コード例 #1
0
def get_summary_data_freshair_remote(token, fullURL='http://localhost:32400'):
    libraries_dict = core.get_libraries(token, fullurl=fullURL)
    keynum = max([
        key for key in libraries_dict if libraries_dict[key] == 'npr fresh air'
    ])
    sincedate = core.get_current_date_newsletter()
    key, num_songs, _, _, totdur, totsizebytes = core._get_library_stats_artist(
        keynum, token, fullurl=fullURL)
    mainstring = 'there are %d episodes of npr fresh air.' % num_songs
    sizestring = 'the total size of npr fresh air media is %s.' % get_formatted_size(
        totsizebytes)
    durstring = 'the total duration of npr fresh air media is %s.' % get_formatted_duration(
        totdur)
    if sincedate is not none:
        key, num_songs_since, _, _, \
            totdur_since, totsizebytes_since = core._get_library_stats_artist(
                keynum, token, fullurl = fullURL, sincedate = sincedate )
        if num_songs_since > 0:
            mainstring_since = ' '.join([
                'since %s, i have added %d new fresh air episodes.' %
                (sinceDate.strftime('%B %d, %Y'), num_songs_since),
                'The total size of Fresh Air media I have added is %s.' %
                get_formatted_size(totsizebytes_since),
                'The total duration of Fresh Air media I have added is %s.' %
                get_formatted_duration(totdur_since)
            ])
            return ' '.join(
                [mainstring, sizestring, durstring, mainstring_since])
    return ' '.join([mainstring, sizestring, durstring])
コード例 #2
0
ファイル: email.py プロジェクト: tanimislam/howdy
def get_summary_data_music_remote(
    token, fullURL = 'http://localhost:32400',
    sinceDate = datetime.datetime.strptime('January 1, 2020', '%B %d, %Y' ).date( ) ):
    """
    This returns summary information on songs from all music libraries on the Plex_ server, for use as part of the Plex_ newsletter sent out to one's Plex_ server friends. The email first summarizes ALL the music data, and then summarizes the music data uploaded and processed since a previous date. For example,
    
       As of December 29, 2020, there are 17,853 songs made by 889 artists in 1,764 albums. The total size of music media is 306.979 GB. The total duration of music media is 7 months, 18 days, 15 hours, 8 minutes, and 15.785 seconds.

       Since January 01, 2020, I have added 7,117 songs made by 700 artists in 1,180 albums. The total size of music media that I have added is 48.167 GB. The total duration of music media that I have added is 28 days, 15 hours, 25 minutes, and 37.580 seconds.
    
    :param str token: the Plex_ access token.
    :param str fullURL: the Plex_ server URL.
    :param date sinceDate: the :py:class:`datetime <datetime.date>` from which we have added songs. Default is :py:class:`date <datetime.date>` corresponding to ``January 1, 2020``.
    
    :returns: a :py:class:`string <str>` description of music media in all music libraries on the Plex_ server. If there is no Plex_ server or music library, returns ``None``.
    :rtype: str

    .. seealso:: :py:meth:`get_summary_body <howdy.email.email.get_summary_body>`.
    """
    libraries_dict = core.get_libraries( token, fullURL = fullURL, do_full = True )
    if libraries_dict is None: return None
    keynums = set(filter(lambda keynum: libraries_dict[ keynum ][ 1 ] == 'artist', libraries_dict ) )
    if len( keynums ) == 0: return None
    # sinceDate = core.get_current_date_newsletter( )
    datas = list(map(lambda keynum: core.get_library_stats( keynum, token, fullURL = fullURL ), keynums))
    music_summ = {
        'current_date_string' : datetime.datetime.now( ).date( ).strftime( '%B %d, %Y' ),
        'num_songs' : f'{sum(list(map(lambda data: data[ "num_songs" ], datas))):,}',
        'num_artists' : f'{sum(list(map(lambda data: data[ "num_artists" ], datas))):,}',
        'num_albums' : f'{sum(list(map(lambda data: data[ "num_albums" ], datas))):,}',
        'formatted_size' : get_formatted_size(sum(list(map(lambda data: data[ 'totsize' ], datas)))),
        'formatted_duration' : get_formatted_duration(sum(list(map(lambda data: data[ 'totdur' ], datas)))) }
    #
    ## now since sinceDate
    datas_since = list(filter(
        lambda data_since: data_since[ 'num_songs' ] > 0,
        map(lambda keynum: core.get_library_stats(
            keynum, token, fullURL = fullURL, sinceDate = sinceDate ), keynums ) ) )
    music_summ[ 'len_datas_since' ] = len( datas_since )
    if len( datas_since ) > 0:
        music_summ[ 'since_date_string' ] = sinceDate.strftime( '%B %d, %Y' )
        music_summ[ 'num_songs_since' ] = f'{sum(list(map(lambda data_since: data_since[ "num_songs" ], datas_since))):,}'
        music_summ[ 'num_artists_since' ] = f'{sum(list(map(lambda data_since: data_since[ "num_artists" ], datas_since))):,}'
        music_summ[ 'num_albums_since' ] = f'{sum(list(map(lambda data_since: data_since[ "num_albums" ], datas_since))):,}'
        music_summ[ 'formatted_size_since' ] = get_formatted_size( sum(list(map(lambda data_since: data_since[ 'totsize'], datas_since))))
        music_summ[ 'formatted_duration_since' ] = get_formatted_duration( sum(list(map(lambda data_since: data_since[ 'totdur' ], datas_since))) )
    #
    env = Environment( loader = FileSystemLoader( resourceDir ) )
    template = env.get_template( 'summary_data_music_template.rst' )
    musicstring = template.render( music_summ = music_summ )
    return musicstring
コード例 #3
0
ファイル: email.py プロジェクト: tanimislam/howdy
def get_summary_data_television_remote(
    token, fullURL = 'http://localhost:32400',
    sinceDate = datetime.datetime.strptime('January 1, 2020', '%B %d, %Y' ).date( ) ):
    """
    This returns summary information on TV media from all television libraries on the Plex_ server, for use as part of the Plex_ newsletter sent out to one's Plex_ server friends. The email first summarizes ALL the TV data, and then summarizes the TV data uploaded and processed since a previous date. For example,

       As of December 29, 2020, there are 25,195 TV episodes in 298 TV shows. The total size of TV media is 6.690 TB. The total duration of TV media is 1 year, 5 months, 19 days, 9 hours, 29 minutes, and 13.919 seconds.

       Since January 01, 2020, I have added 5,005 TV epsisodes in 298 TV shows. The total size of TV media that I have added is 1.571 TB. The total duration of TV media that I have added is 3 months, 16 days, 4 hours, 52 minutes, and 15.406 seconds.

    :param str token: the Plex_ access token.
    :param str fullURL: the Plex_ server URL.
    :param date sinceDate: the :py:class:`datetime <datetime.date>` from which we have added songs. Default is :py:class:`date <datetime.date>` corresponding to ``January 1, 2020``.
    
    :returns: a :py:class:`string <str>` description of TV media in all TV libraries on the Plex_ server. If there is no Plex_ server or TV library, returns ``None``.
    :rtype: str

    .. seealso:: :py:meth:`get_summary_body <howdy.email.email.get_summary_body>`.
    """
    libraries_dict = core.get_libraries( token, fullURL = fullURL, do_full = True )
    if libraries_dict is None: return None
    keynums = set(filter(lambda keynum: libraries_dict[ keynum ][ 1 ] == 'show', libraries_dict ) )
    if len( keynums ) == 0: return None
    #
    # sinceDate = core.get_current_date_newsletter( )
    datas = list(map(lambda keynum: core.get_library_stats( keynum, token, fullURL = fullURL ), keynums))
    tv_summ = {
        'current_date_string' : datetime.datetime.now( ).date( ).strftime( '%B %d, %Y' ),
        'num_episodes' : f'{sum(list(map(lambda data: data[ "num_tveps" ], datas))):,}',
        'num_shows' : f'{sum(list(map(lambda data: data[ "num_tvshows" ], datas))):,}',
        'formatted_size' : get_formatted_size(sum(list(map(lambda data: data[ 'totsize' ], datas)))),
        'formatted_duration' : get_formatted_duration(sum(list(map(lambda data: data[ 'totdur' ], datas)))) }
    datas_since = list(filter(
        lambda data_since: data_since[ 'num_tveps' ] > 0,
        map(lambda keynum: core.get_library_stats(
            keynum, token, fullURL = fullURL, sinceDate = sinceDate ), keynums) ) )
    tv_summ[ 'len_datas_since' ] = len( datas_since )
    if len( datas_since ) > 0:
        tv_summ[ 'since_date_string' ] = sinceDate.strftime( '%B %d, %Y' )
        tv_summ[ 'num_episodes_since' ] = f'{sum(list(map(lambda data_since: data_since[ "num_tveps" ], datas_since))):,}'
        tv_summ[ 'num_shows_since' ] = f'{sum(list(map(lambda data_since: data_since[ "num_tvshows" ], datas_since))):,}'
        tv_summ[ 'formatted_size_since' ] = get_formatted_size( sum(list(map(lambda data_since: data_since[ 'totsize'], datas_since))))
        tv_summ[ 'formatted_duration_since' ] = get_formatted_duration( sum(list(map(lambda data_since: data_since[ 'totdur' ], datas_since))) )
    env = Environment( loader = FileSystemLoader( resourceDir ) )
    template = env.get_template( 'summary_data_tv_template.rst' )
    tvstring = template.render( tv_summ = tv_summ )
    return tvstring
コード例 #4
0
ファイル: email.py プロジェクト: tanimislam/howdy
 def _get_category_entry( cat ):
     mainstring = template_mainstring.render(
         current_date_string = current_date_string,
         num_movies = f'{sorted_by_genres[ cat ][ "totnum" ]:,}',
         totsize = get_formatted_size( sorted_by_genres[ cat ][ 'totsize' ] ),
         totdur = get_formatted_duration( sorted_by_genres[ cat ][ 'totdur' ] ) )
     if cat in sorted_by_genres_since and sorted_by_genres_since[ cat ][ 'totnum' ] > 0:
         num_movies_since = f'{sorted_by_genres_since[ cat ][ "totnum" ]:,}'
         totsize_since    = get_formatted_size( sorted_by_genres_since[ cat ][ 'totsize' ] )
         totdur_since     = get_formatted_duration( sorted_by_genres_since[ cat ][ 'totdur'  ] )
         mainstring_since = template_sincestring.render(
             since_date_string = sinceDate.strftime( '%B %d, %Y' ),
             num_movies_since = num_movies_since,
             totsize_since = totsize_since,
             totdur_since = totdur_since )
         description = ' '.join([ mainstring, mainstring_since ])
         return { 'category' : cat, 'description' : description }
     return { 'category' : cat, 'description' : mainstring }
コード例 #5
0
ファイル: howdy_resynclibs.py プロジェクト: tanimislam/howdy
def _print_summary(library_key, library_dict, token, fullURL):
    data = core.get_library_stats(library_key, token, fullURL=fullURL)
    mediatype = data['mediatype']
    title = data['title']
    columns = min(100, get_terminal_size().columns)
    if mediatype == 'movie':
        mystr = ' '.join([
            '"%s" is a movie library.' % title,
            'There are %d movies here.' % data['num_movies'],
            'The total size of movie media is %s.' %
            get_formatted_size(data['totsize']),
            'The total duration of movie media is %s.' %
            get_formatted_duration(data['totdur'])
        ])
    elif mediatype == 'show':
        mystr = ' '.join([
            '"%s" is a TV library.' % title,
            'There are %d TV files in %d TV shows.' %
            (data['num_tveps'], data['num_tvshows']),
            'The total size of TV media is %s.' %
            get_formatted_size(data['totsize']),
            'The total duration of TV shows is %s.' %
            get_formatted_duration(data['totdur'])
        ])
    elif mediatype == 'artist':
        num_songs = data['num_songs']
        num_artists = data['num_artists']
        num_albums = data['num_albums']
        totsize = data['totsize']
        totdur = data['totdur']
        mystr = ' '.join([
            '"%s" is a music library.' % title,
            'There are %d songs made by %d artists in %d albums.' %
            (num_songs, num_artists, num_albums),
            'The total size of music media is %s.' %
            get_formatted_size(totsize),
            'The total duration of music media is %s.' %
            get_formatted_duration(totdur)
        ])
    print('\n%s\n' %
          '\n'.join(textwrap.fill(mystr, width=columns).split('\n')))
コード例 #6
0
ファイル: email.py プロジェクト: tanimislam/howdy
def get_summary_data_movies_remote(
    token, fullURL = 'http://localhost:32400',
    sinceDate = datetime.datetime.strptime('January 1, 2020', '%B %d, %Y' ).date( ) ):
    """
    This returns summary information on movie media from all movie libraries on the Plex_ server, for use as part of the Plex_ newsletter sent out to one's Plex_ server friends. The email first summarizes ALL the movie data, and then summarizes the movie data uploaded and processed since the last newsletter's date. Unlike :py:meth:`get_summary_data_music_remote <howdy.email.email.get_summary_data_music_remote>` and :py:meth:`get_summary_data_television_remote <howdy.email.email.get_summary_data_television_remote>`, this returns a :py:class:`list` of strings rather than a string.

    :param str token: the Plex_ access token.
    :param str fullURL: the Plex_ server URL.
    
    :returns: a :py:class:`string <str>` description of TV media in all TV libraries on the Plex_ server. If there is no Plex_ server or TV library, returns ``None``.
    :rtype: list

    .. seealso:: :py:meth:`get_summary_body <howdy.email.email.get_summary_body>`.
    """
    libraries_dict = core.get_libraries( token, fullURL = fullURL, do_full = True )
    if libraries_dict is None:
        return None
    keynums = set(filter(lambda keynum: libraries_dict[ keynum ][ 1 ] == 'movie', libraries_dict ) )
    if len( keynums ) == 0:
        return None
    #
    # sinceDate = core.get_current_date_newsletter( )
    #
    ## hard coding (for now) how to join by genres
    join_genres = { 'action' : [ 'thriller', 'western' ], 'comedy' : [ 'family', ], 'drama' : [ 'drame', ] }
    def _join_by_genre( sort_by_genre, join_genres ):
        alljoins = list(chain.from_iterable(map(lambda genre: join_genres[ genre ], join_genres ) ) )
        assert( len( alljoins ) == len( set( alljoins ) ) )
        assert( len( set( alljoins ) & set( join_genres ) ) == 0 )
        for genre in join_genres:
            g2s = set( join_genres[ genre ] ) & set( sort_by_genre )
            if len( g2s ) == 0: continue
            if genre not in sort_by_genre:
                sort_by_genre[ genre ][ 'totnum' ] = 0
                sort_by_genre[ genre ][ 'totdur' ] = 0.0
                sort_by_genre[ genre ][ 'totsize' ] = 0.0
            for g2 in g2s:
                sort_by_genre[ genre ][ 'totnum' ] += sort_by_genre[ g2 ][ 'totnum' ]
                sort_by_genre[ genre ][ 'totdur' ] += sort_by_genre[ g2 ][ 'totdur' ]
                sort_by_genre[ genre ][ 'totsize' ] += sort_by_genre[ g2 ][ 'totsize' ]
            for g2 in g2s:
                sort_by_genre.pop( g2 )
    #
    current_date_string = datetime.datetime.now( ).date( ).strftime( '%B %d, %Y' )
    datas = list(map(lambda keynum: core.get_library_stats( keynum, token, fullURL = fullURL ), keynums ) )
    num_movies_since = -1
    sorted_by_genres = { }
    sorted_by_genres_since = { }
    for data in datas:
        data_sorted_by_genre = data[ 'genres' ]
        for genre in data_sorted_by_genre:
            if genre not in sorted_by_genres:
                sorted_by_genres[ genre ] = data_sorted_by_genre[ genre ].copy( )
                continue
            sorted_by_genres[ genre ][ 'totum'  ] += data_sorted_by_genre[ genre ][ 'totnum'  ]
            sorted_by_genres[ genre ][ 'totdur' ] += data_sorted_by_genre[ genre ][ 'totdur'  ]
            sorted_by_genres[ genre ][ 'totsize'] += data_sorted_by_genre[ genre ][ 'totsize' ]
    _join_by_genre( sorted_by_genres, join_genres )
    categories = set( sorted_by_genres )
    num_movies = f'{sum(list(map(lambda data: data[ "num_movies" ], datas ) ) ):,}'
    totdur = get_formatted_duration( sum(list(map(lambda data: data[ 'totdur' ], datas ) ) ) )
    totsize = get_formatted_size( sum(list(map(lambda data: data[ 'totsize' ], datas ) ) ) )
    movie_summ = {
        'current_date_string' : current_date_string,
        'num_movies' : num_movies,
        'num_categories' : len( categories ),
        'formatted_size' : totsize,
        'formatted_duration' : totdur }
    #
    datas_since = list(filter(
        lambda data_since: data_since[ 'num_movies' ] > 0,
        map(lambda keynum: core.get_library_stats(
            keynum, token, fullURL = fullURL, sinceDate = sinceDate ), keynums ) ) )
    movie_summ[ 'len_datas_since' ] = len( datas_since )
    if len( datas_since ) != 0:
        for data_since in datas_since:
            data_since_sorted_by_genre = data_since[ 'genres' ]
            for genre in data_since_sorted_by_genre:
                if genre not in sorted_by_genres_since:
                    sorted_by_genres_since[ genre ] = data_since_sorted_by_genre[ genre ].copy( )
                    continue
                sorted_by_genres_since[ genre ][ 'totum'  ] += data_since_sorted_by_genre[ genre ][ 'totnum'  ]
                sorted_by_genres_since[ genre ][ 'totdur' ] += data_since_sorted_by_genre[ genre ][ 'totdur'  ]
                sorted_by_genres_since[ genre ][ 'totsize'] += data_since_sorted_by_genre[ genre ][ 'totsize' ]
        _join_by_genre( sorted_by_genres_since, join_genres )
        num_movies_since = f'{sum(list(map(lambda data_since: data_since[ "num_movies" ], datas_since ) ) ):,}'
        categories_since = set( sorted_by_genres_since )
        totsize_since = get_formatted_size( sum(list(map(lambda data_since: data_since[ 'totsize' ], datas_since ) ) ) )
        totdur_since = get_formatted_duration( sum(list(map(lambda data_since: data_since[ 'totdur' ], datas_since ) ) ) )
        movie_summ[ 'since_date_string' ] = sinceDate.strftime( '%B %d, %Y' )
        movie_summ[ 'num_movies_since' ] = num_movies_since
        movie_summ[ 'num_categories_since' ] = len( categories_since )
        movie_summ[ 'formatted_size_since' ] = totsize_since
        movie_summ[ 'formatted_duration_since' ] =  totdur_since
        
    #
    ## get last 7 movies that I have added, to pass to JINJA template
    lastN_movies = core.get_lastN_movies( 7, token, fullURL = fullURL, useLastNewsletterDate = False )
    last_N_movies = [ ]
    def _get_nth_movie( lastN_entry ):
        title, year, date, url = lastN_entry
        if url is None:
            return {
                'hasURL' : False,
                'name' : title,
                'year' : year,
                'added_date_string' : date.strftime( '%B %d, %Y' ),
                'url' : '' }
        return {
            'hasURL' : True,
            'name' : title,
            'year' : year,
            'added_date_string' : date.strftime( '%B %d, %Y' ),
            'url' : url }
    last_N_movies = list(map(_get_nth_movie, lastN_movies ) )
    #
    ## catmovstrings list to pass to JINJA template
    template_mainstring = Template(' '.join([
        'As of ``{{ current_date_string }}``, there are {{ num_movies }} movies in this category.',
        'The total size of movie media here is {{ totsize }}.',
        'The total duration of movie media here is {{ totdur }}.' ]) )
    template_sincestring = Template(' '.join([
        'Since ``{{ since_date_string }}``, I have added {{ num_movies_since }} movies in this category.',
        'The total size of movie media I added here is {{ totsize_since }}.',
        'The total duration of movie media I added here is {{ totdur_since }}.' ] ) )
    def _get_category_entry( cat ):
        mainstring = template_mainstring.render(
            current_date_string = current_date_string,
            num_movies = f'{sorted_by_genres[ cat ][ "totnum" ]:,}',
            totsize = get_formatted_size( sorted_by_genres[ cat ][ 'totsize' ] ),
            totdur = get_formatted_duration( sorted_by_genres[ cat ][ 'totdur' ] ) )
        if cat in sorted_by_genres_since and sorted_by_genres_since[ cat ][ 'totnum' ] > 0:
            num_movies_since = f'{sorted_by_genres_since[ cat ][ "totnum" ]:,}'
            totsize_since    = get_formatted_size( sorted_by_genres_since[ cat ][ 'totsize' ] )
            totdur_since     = get_formatted_duration( sorted_by_genres_since[ cat ][ 'totdur'  ] )
            mainstring_since = template_sincestring.render(
                since_date_string = sinceDate.strftime( '%B %d, %Y' ),
                num_movies_since = num_movies_since,
                totsize_since = totsize_since,
                totdur_since = totdur_since )
            description = ' '.join([ mainstring, mainstring_since ])
            return { 'category' : cat, 'description' : description }
        return { 'category' : cat, 'description' : mainstring }
    catmovs = list(map(_get_category_entry, sorted( sorted_by_genres ) ) )
    env = Environment( loader = FileSystemLoader( resourceDir ) )
    template = env.get_template( 'summary_data_movie_template.rst' )
    movstring = template.render( movie_summ = movie_summ, last_N_movies = last_N_movies, catmovs = catmovs )
    return movstring
コード例 #7
0
def get_summary_data_thisamericanlife_remote(token,
                                             fullURL='http://localhost:32400'):
    libraries_dict = core.get_libraries(token, fullURL=fullURL)
    keynum = max([
        key for key in libraries_dict
        if libraries_dict[key] == 'This American Life'
    ])
    sinceDate = core.get_current_date_newsletter()
    key, song_data = core._get_library_data_artist(keynum,
                                                   token,
                                                   fullURL=fullURL)
    num_episodes = 0
    totdur = 0.0
    totsizebytes = 0.0
    for key in song_data:
        for key2 in song_data[key]:
            num_episodes += len(song_data[key][key2])
            for track in song_data[key][key2]:
                name, dt, dur, sizebytes = track
                totdur += dur
                totsizebytes += sizebytes
    mainstring = 'There are %d episodes in %d series in This American Life.' % (
        num_episodes, len(song_data))
    sizestring = 'The total size of This American Life media is %s.' % \
        get_formatted_size( totsizebytes )
    durstring = 'The total duration of This American Life media is %s.' % \
        get_formatted_duration( totdur )
    if sinceDate is None:
        pristrings = [
            ' '.join([mainstring, sizestring, durstring]),
        ]
    else:
        key, song_data_since = core._get_library_data_artist(
            keynum, token, fullURL=fullURL, sinceDate=sinceDate)
        num_episodes_since = 0
        totdur_since = 0.0
        totsizebytes_since = 0.0
        for key in song_data_since:
            for key2 in song_data_since[key]:
                num_episodes_since += len(song_data_since[key][key2])
                for track in song_data_since[key][key2]:
                    name, dt, dur, sizebytes = track
                    totdur_since += dur
                    totsizebytes_since += sizebytes
        if num_episodes_since > 0:
            mainstring_since = ' '.join([
                'Since %s, I have added %d new This American Life episodes.' %
                (sinceDate.strftime('%B %d, %Y'), num_episodes_since),
                'The total size of This American Life media I added is %s.' %
                get_formatted_size(totsizebytes_since),
                'The total duration of This American Life media I added is %s.'
                % get_formatted_duration(totdur_since)
            ])
            pristrings = [
                ' '.join([mainstring, sizestring, durstring,
                          mainstring_since]),
            ]
        else:
            pristrings = [
                ' '.join([mainstring, sizestring, durstring]),
            ]
    #
    catpristrings = {}
    for album in song_data:
        if album == 'Ira Glass': actalbum = 'This American Life'
        else: actalbum = album
        totdur = 0.0
        totsizebytes = 0.0
        num_episodes = 0
        for key2 in song_data[album]:
            num_episodes += len(song_data[album][key2])
            for track in song_data[album][key2]:
                name, dt, dur, sizebytes = track
                totdur += dur
                totsizebytes += sizebytes
        mainstring = 'There are %d episodes in this category.' % num_episodes
        sizestring = 'The total size of media here is %s.' % get_formatted_size(
            totsizebytes)
        durstring = 'The total duration of media here is %s.' % get_formatted_duration(
            totdur)
        if sinceDate is None:
            mystring = ' '.join([mainstring, sizestring, durstring])
        else:
            if album not in song_data_since:
                mystring = ' '.join([mainstring, sizestring, durstring])
            else:
                totdur_since = 0.0
                totsizebytes_since = 0.0
                num_episodes_since = 0
                for key2 in song_data_since[album]:
                    num_episodes_since += len(song_data_since[album][key2])
                    for track in song_data_since[album][key2]:
                        name, dt, dur, sizebytes = track
                        totdur_since += dur
                        totsizebytes_since += sizebytes
                if num_episodes_since > 0:
                    mainstring_since = ' '.join([
                        'Since %s, I have added %d new episodes in this category.'
                        %
                        (sinceDate.strftime('%B %d, %Y'), num_episodes_since),
                        'The total size of media I added here is %s.' %
                        get_formatted_size(totsizebytes_since),
                        'The total duration of media I added here is %s.' %
                        get_formatted_duration(totdur_since)
                    ])
                    mystring = ' '.join(
                        [mainstring, sizestring, durstring, mainstring_since])
                else:
                    mystring = ' '.join([mainstring, sizestring, durstring])
        catpristrings[actalbum] = mystring
    pristrings.append(catpristrings)
    return pristrings
コード例 #8
0
ファイル: tv_gui.py プロジェクト: tanimislam/howdy
    def getShowSummary(cls, seriesName, tvdata_on_plex, missing_eps):
        seasons_info = tvdata_on_plex[seriesName]['seasons']
        overview = tvdata_on_plex[seriesName]['summary']
        didend = tvdata_on_plex[seriesName]['didEnd']
        num_total = sum(
            list(
                map(lambda seasno: len(seasons_info[seasno]['episodes']),
                    set(seasons_info) - set([0]))))
        if seriesName not in missing_eps: num_missing = 0
        else: num_missing = len(missing_eps[seriesName])
        if didend: show_status = "Show has ended"
        else: show_status = "Show is still ongoing"
        minDate = min(
            map(
                lambda seasno: min(
                    map(
                        lambda epno: seasons_info[seasno]['episodes'][epno][
                            'date aired'], seasons_info[seasno]['episodes'])),
                set(seasons_info) - set([0])))
        maxDate = max(
            map(
                lambda seasno: max(
                    map(
                        lambda epno: seasons_info[seasno]['episodes'][epno][
                            'date aired'], seasons_info[seasno]['episodes'])),
                set(seasons_info) - set([0])))

        html = BeautifulSoup(
            """
        <html>
        <p>Summary for %s.</p>
        <p>%s.</p>
        <p>%02d episodes, %02d missing.</p>
        <p>First episode aired on %s.</p>
        <p>Last episode aired on %s.</p>
        <p>
        </html>""" %
            (seriesName, show_status, num_total, num_missing,
             minDate.strftime('%B %d, %Y'), maxDate.strftime('%B %d, %Y')),
            'lxml')
        body_elem = html.find_all('body')[0]
        html2 = BeautifulSoup(
            """
        <html>
        <body>
        </body>
        </html>""", 'lxml')
        body2_elem = html2.find_all('body')[0]
        if len(overview) != 0:
            summary_tag = html2.new_tag("p")
            summary_tag.string = overview
            body2_elem.append(summary_tag)
        average_duration_in_secs = numpy.array(
            list(
                chain.from_iterable(
                    map(
                        lambda seasno: list(
                            map(
                                lambda epno: seasons_info[seasno]['episodes'][
                                    epno]['duration'], seasons_info[seasno][
                                        'episodes'])),
                        set(seasons_info) - set([0]))))).mean()
        average_size_in_bytes = numpy.array(
            list(
                chain.from_iterable(
                    map(
                        lambda seasno: list(
                            map(
                                lambda epno: seasons_info[seasno]['episodes']
                                [epno]['size'], seasons_info[seasno]['episodes'
                                                                     ])),
                        set(seasons_info) - set([0]))))).mean()
        dur_tag = html.new_tag("p")
        dur_tag.string = "average duration of %02d episodes: %s." % (
            num_total, get_formatted_duration(average_duration_in_secs))
        siz_tag = html.new_tag("p")
        siz_tag.string = "average size of %02d episodes: %s." % (
            num_total, get_formatted_size(average_size_in_bytes))
        body_elem.append(dur_tag)
        body_elem.append(siz_tag)
        return html.prettify(), html2.prettify()