jakewaldron / PlexEmail

This script aggregates all new TV, movie and music releases for the past configured time then optionally writes to your web directory and sends out an email.
206 stars 32 forks source link

Feature Request: Library statistics in footer #61

Open oskameDEV opened 7 years ago

oskameDEV commented 7 years ago

Title explains a lot.

I thought it might be neat if the footer showed your Plex's library stats.

1000 Movies | 345 Episodes | 1144 Songs x Days x Hours of entertainment.

justinglock40 commented 7 years ago

Also, Maybe add the resolution of the file. So users can see the quality of the media in the newsletter?

Anyway to make the background of the email a darker color such as black or gray?

oskameDEV commented 7 years ago

I forgot to follow up on this. But for those with Plexpy there is an API you can use. You'll have to edit the html in /scripts/plexEmail.py

Here's roughly what I'm using.

After the import section (top of the file) or near it.

## STATS JSON ##
def GetTime(seconds):
    minutes, seconds = divmod(seconds, 60)
    hours, minutes = divmod(minutes, 60)
    days, hours = divmod(hours, 24)
    return str(days)+'DAYS ' + str(hours)+'HOURS ' + str(minutes)+'MINUTES'

url = urllib.urlopen('http://192.168.0.222:8181/api/v2?apikey=XXX&cmd=get_libraries').read()
url = json.loads(url)

statsJSON = url.get('response')
statsJSON = statsJSON['data']

statsTotal = 'MOVIES ' + statsJSON[0]['count'] + ' | SHOWS ' + statsJSON[1]['count'] + ' | EPISODES ' + statsJSON[1]['child_count']

timeTVsecs = int(statsJSON[1]['child_count'])
timeTVsecs = timeTVsecs*2400
timeTV = GetTime(timeTVsecs)

timeMoviesSecs = int(statsJSON[0]['count'])
timeMoviesSecs = timeMoviesSecs*6900
timeMovies = GetTime(timeMoviesSecs)

and after <!-- /.container —> footer

        <div id="footer"><center>
        <h1 style="font-size:2em;color: #f39c12 !important;width: 100%; text-align: center;">Stats</h1>
        <h2 style="font-size:1em;color: #f39c12 !important;width: 100%; text-align: left; width:75%">&#9889;  """ + statsTotal + """</h2>
        <h2 style="font-size:1em;color: #f39c12 !important;width: 100%; text-align: left; width:75%">&#127909; """ + timeMovies + """</h2>
        <h2 style="font-size:1em;color: #f39c12 !important;width: 100%; text-align: left; width:75%">&#128250;  """ + timeTV + """</h2>
        <img src="http://res.cloudinary.com/fluxcapa/image/upload/c_scale,w_250/v1480731212/ASSETS/giphy.gif" width="125" height="125" style="border-radius:250px; /><div style="clear:both;></div>
        <h1 style="font-size:2em;color: #f39c12 !important;width: 100%; text-align: center;"><b>Have fun watching!</b></h1>
        </center></div>

Edit the IP 192.168.0.222 and XXX to the API key in Plexpy admin page settings.