Example #1
0
def HandleCategory(category_path, title):
    oc = ObjectContainer(title2=unicode(title))

    # Add all items category
    items = service.get_category_items(category_path)

    if len(items) > 0:
        all_title = unicode(L('All')) + ' ' + unicode(title.lower())

        oc.add(DirectoryObject(
            key=Callback(HandleCategoryItems, category_path=category_path, title=all_title),
            title=plex_util.sanitize(all_title)
        ))

    cats = service.get_subcategories(category_path)

    for item in cats['data']:
        name = item['title']
        path = item['path']

        oc.add(DirectoryObject(
            key=Callback(HandleCategoryItems, category_path=path, title=name),
            title=plex_util.sanitize(name)
        ))

    return oc
Example #2
0
def HandleAllGenres():
    oc = ObjectContainer(title2=unicode(L('Top')))

    grouped_genres = service.get_grouped_genres()

    movies_genres = grouped_genres['films']
    series_genres = grouped_genres['serial']
    anime_genres = grouped_genres['anime']

    oc.add(
        DirectoryObject(key=Callback(HandleGenres,
                                     name='Movies',
                                     genres=movies_genres),
                        title=plex_util.sanitize(unicode(L('Movies')))))

    oc.add(
        DirectoryObject(key=Callback(HandleGenres,
                                     name='Series',
                                     genres=series_genres),
                        title=plex_util.sanitize(unicode(L('Series')))))

    oc.add(
        DirectoryObject(key=Callback(HandleGenres,
                                     name='Anime',
                                     genres=anime_genres),
                        title=plex_util.sanitize(unicode(L('Anime')))))

    return oc
Example #3
0
def HandleCategory(category_path, title):
    oc = ObjectContainer(title2=unicode(title))

    # Add all items category
    items = service.get_category_items(category_path)

    if len(items) > 0:
        all_title = unicode(L('All')) + ' ' + unicode(title.lower())

        oc.add(
            DirectoryObject(key=Callback(HandleCategoryItems,
                                         category_path=category_path,
                                         title=all_title),
                            title=plex_util.sanitize(all_title)))

    cats = service.get_subcategories(category_path)

    for item in cats['data']:
        name = item['title']
        path = item['path']

        oc.add(
            DirectoryObject(key=Callback(HandleCategoryItems,
                                         category_path=path,
                                         title=name),
                            title=plex_util.sanitize(name)))

    return oc
Example #4
0
def HandleSelection(page=1, operation=None, **params):
    oc = ObjectContainer(title2=unicode(params['name']))

    media_info = MediaInfo(**params)

    service.queue.handle_bookmark_operation(operation, media_info)

    response = service.get_selection(params['id'], page=page)

    for item in response['movies']:
        new_params = {
            'type': 'movie',
            'id': item['path'],
            'name': item['name'],
            'thumb': item['thumb'],
        }

        oc.add(DirectoryObject(
            key=Callback(HandleMovie, **new_params),
            title=plex_util.sanitize(item['name']),
            thumb=plex_util.get_thumb(item['thumb'])
        ))

    service.queue.append_bookmark_controls(oc, HandleSelection, media_info)
    pagination.append_controls(oc, response, page=page, callback=HandleSelection, **media_info)

    return oc
Example #5
0
def HandleSelections(page=1):
    oc = ObjectContainer(title2=unicode(L('Selections')))

    response = service.get_selections(page=page)

    for item in response['movies']:
        name = item['name']

        if name != "Актёры и актрисы" and name != "Актеры и актрисы":
            new_params = {
                'type': 'selection',
                'id': item['path'],
                'name': name,
                'thumb': item['thumb'],
            }

            oc.add(DirectoryObject(
                key=Callback(HandleSelection, **new_params),
                title=plex_util.sanitize(name),
                thumb=plex_util.get_thumb(item['thumb'])
            ))

    pagination.append_controls(oc, response, callback=HandleSelections, page=page)

    return oc
Example #6
0
def HandleMovies(title, id, page=1):
    oc = ObjectContainer(title2=unicode(L(title)))

    response = service.get_movies(path=id, page=page)

    for item in response['items']:
        name = item['name']
        thumb = item['thumb']

        new_params = {
            'id': item['path'],
            'name': item['name'],
            'thumb': item['thumb'],
            'isSerie': item['isSerie']
        }
        oc.add(
            DirectoryObject(key=Callback(HandleMovieOrSerie, **new_params),
                            title=plex_util.sanitize(name),
                            thumb=plex_util.get_thumb(thumb)))

    pagination.append_controls(oc,
                               response,
                               callback=HandleMovies,
                               id=id,
                               title=title,
                               page=page)

    return oc
Example #7
0
def HandleQueue(filter=None):
    oc = ObjectContainer(title2=unicode(L('Queue')))

    for media_info in service.queue.data:
        type = media_info['type']

        if filter is None or type == filter:
            if 'thumb' in media_info:
                thumb = media_info['thumb']
            else:
                thumb = None

            oc.add(
                DirectoryObject(key=Callback(HandleContainer, **media_info),
                                title=plex_util.sanitize(media_info['name']),
                                thumb=thumb))

    if filter:
        records = [
            item for item in service.queue.data if item['type'] == filter
        ]
    else:
        records = service.queue.data

    if len(records) > 0:
        oc.add(
            DirectoryObject(key=Callback(ClearQueue, filter=filter),
                            title=unicode(L("Clear Queue"))))

    return oc
Example #8
0
def HandleQueue(filter=None):
    oc = ObjectContainer(title2=unicode(L('Queue')))

    for media_info in service.queue.data:
        type = media_info['type']

        if filter is None or type == filter:
            if 'thumb' in media_info:
                thumb = media_info['thumb']
            else:
                thumb = None

            oc.add(DirectoryObject(
                key=Callback(HandleContainer, **media_info),
                title=plex_util.sanitize(media_info['name']),
                thumb=thumb
            ))

    if filter:
        records = [item for item in service.queue.data if item['type'] == filter]
    else:
        records = service.queue.data

    if len(records) > 0:
        oc.add(DirectoryObject(
            key=Callback(ClearQueue, filter=filter),
            title=unicode(L("Clear Queue"))
        ))

    return oc
Example #9
0
def HandleCategories():
    oc = ObjectContainer(title2=unicode(L('Categories')))

    items = service.get_categories()

    for item in items:
        name = item['title']
        path = item['path']

        if path == '/Serialy.html':
            oc.add(DirectoryObject(
                key=Callback(HandleSeries, category_path=path, title=name),
                title=plex_util.sanitize(name)
            ))
        else:
            oc.add(DirectoryObject(
                key=Callback(HandleCategory, category_path=path, title=name),
                title=plex_util.sanitize(name)
            ))

    return oc
Example #10
0
def HandleGenres(name, genres):
    oc = ObjectContainer(title2=unicode(L(name)))

    for genre in genres:
        oc.add(
            DirectoryObject(key=Callback(HandleMovies,
                                         id=genre['path'],
                                         title=genre['name']),
                            title=plex_util.sanitize(unicode(L(
                                genre['name'])))))

    return oc
Example #11
0
def HandleTops():
    oc = ObjectContainer(title2=unicode(L('Top')))

    genres = service.get_grouped_genres()['top']

    for genre in genres:
        path = genre['path']
        name = genre['name']

        if path == '/podborka.html':
            oc.add(
                DirectoryObject(key=Callback(HandleTags, name=name),
                                title=plex_util.sanitize(unicode(L(name)))))
        else:
            oc.add(
                DirectoryObject(key=Callback(HandleCriteria,
                                             id=path,
                                             name=name),
                                title=plex_util.sanitize(unicode(L(name)))))

    return oc
Example #12
0
def HandleCategories():
    oc = ObjectContainer(title2=unicode(L('Categories')))

    items = service.get_categories()

    for item in items:
        name = item['title']
        path = item['path']

        if path == '/Serialy.html':
            oc.add(
                DirectoryObject(key=Callback(HandleSeries,
                                             category_path=path,
                                             title=name),
                                title=plex_util.sanitize(name)))
        else:
            oc.add(
                DirectoryObject(key=Callback(HandleCategory,
                                             category_path=path,
                                             title=name),
                                title=plex_util.sanitize(name)))

    return oc
Example #13
0
def HandleTags(name):
    oc = ObjectContainer(title2=unicode(L(name)))

    response = service.get_tags()

    for item in response:
        name = item['name']
        thumb = item['thumb']

        new_params = {'id': item['path'], 'title': item['name']}
        oc.add(
            DirectoryObject(key=Callback(HandleMovies, **new_params),
                            title=plex_util.sanitize(name),
                            thumb=plex_util.get_thumb(thumb)))

    return oc
Example #14
0
def HandleFilter(mode, name, list):
    oc = ObjectContainer(title2=unicode(name))

    if mode == 'film':
        handler = HandleMovies
    else:
        handler = HandleSeries

    for item in json.loads(list):
        name = item['name']
        path = item['path']

        oc.add(DirectoryObject(
            key=Callback(handler, path=path, title=name),
            title=plex_util.sanitize(name),
        ))

    return oc
Example #15
0
def addSelectedSeason(oc, document, selected_season, selected_episode, **params):
    selected_season = int(selected_season)

    serial_info = service.get_serial_info(document)

    if selected_episode:
        selected_episode = int(selected_episode)

        if len(serial_info['episodes']) >= selected_episode:
            episode_name = serial_info['episodes'][selected_episode]

            new_params = {
                'type': 'episode',
                'id': params['id'],
                'serieName': params['name'],
                'name': episode_name,
                'thumb': params['thumb'],
                'episodeNumber': selected_episode

            }
            oc.add(DirectoryObject(
                key=Callback(HandleMovie, **new_params),
                title=plex_util.sanitize(episode_name)
            ))

    season_name = serial_info['seasons'][selected_season]
    rating_key = service.get_episode_url(params['id'], selected_season, 0)

    new_params = {
        'type': 'season',
        'id': params['id'],
        'title': season_name,
        'name': params['name'],
        'thumb': params['thumb'],
        'season': selected_season
    }

    oc.add(SeasonObject(
        key=Callback(HandleSeason, **new_params),
        title=unicode(season_name),
        rating_key=rating_key,
        index=selected_season,
        thumb=params['thumb'],
    ))
Example #16
0
def addSelectedSeason(oc, document, selected_season, selected_episode,
                      **params):
    selected_season = int(selected_season)

    serial_info = service.get_serial_info(document)

    if selected_episode:
        selected_episode = int(selected_episode)

        if len(serial_info['episodes']) >= selected_episode:
            episode_name = serial_info['episodes'][selected_episode]

            new_params = {
                'type': 'episode',
                'id': params['id'],
                'serieName': params['name'],
                'name': episode_name,
                'thumb': params['thumb'],
                'episodeNumber': selected_episode
            }
            oc.add(
                DirectoryObject(key=Callback(HandleMovie, **new_params),
                                title=plex_util.sanitize(episode_name)))

    season_name = serial_info['seasons'][selected_season]
    rating_key = service.get_episode_url(params['id'], selected_season, 0)

    new_params = {
        'type': 'season',
        'id': params['id'],
        'title': season_name,
        'name': params['name'],
        'thumb': params['thumb'],
        'season': selected_season
    }

    oc.add(
        SeasonObject(
            key=Callback(HandleSeason, **new_params),
            title=unicode(season_name),
            rating_key=rating_key,
            index=selected_season,
            thumb=params['thumb'],
        ))
Example #17
0
def HandleCategoryItems(category_path, title, page=1):
    response = service.get_category_items(category_path, page)

    if len(response['items']) == 1:
        item = response['items'][0]

        name = item['title']
        path = item['path']
        thumb = service.get_thumb(item['thumb'])

        new_params = {
            'id': path,
            'title': name,
            'name': name,
            'thumb': thumb
        }
        return HandleMovieOrSerie(**new_params)
    else:
        oc = ObjectContainer(title2=unicode(title))

        if response['items']:
            for item in response['items']:
                name = item['title']
                path = item['path']
                thumb = service.get_thumb(item['thumb'])

                new_params = {
                    'id': path,
                    'title': name,
                    'name': name,
                    'thumb': thumb
                }

                oc.add(DirectoryObject(
                    key=Callback(HandleMovieOrSerie, **new_params),
                    title=plex_util.sanitize(name),
                    thumb=thumb
                ))

            pagination.append_controls(oc, response, page=page, callback=HandleCategoryItems, title=title,
                                       category_path=category_path)

        return oc
Example #18
0
def HandleCategoryItems(category_path, title, page=1):
    response = service.get_category_items(category_path, page)

    if len(response['items']) == 1:
        item = response['items'][0]

        name = item['title']
        path = item['path']
        thumb = service.get_thumb(item['thumb'])

        new_params = {'id': path, 'title': name, 'name': name, 'thumb': thumb}
        return HandleMovieOrSerie(**new_params)
    else:
        oc = ObjectContainer(title2=unicode(title))

        if response['items']:
            for item in response['items']:
                name = item['title']
                path = item['path']
                thumb = service.get_thumb(item['thumb'])

                new_params = {
                    'id': path,
                    'title': name,
                    'name': name,
                    'thumb': thumb
                }

                oc.add(
                    DirectoryObject(key=Callback(HandleMovieOrSerie,
                                                 **new_params),
                                    title=plex_util.sanitize(name),
                                    thumb=thumb))

            pagination.append_controls(oc,
                                       response,
                                       page=page,
                                       callback=HandleCategoryItems,
                                       title=title,
                                       category_path=category_path)

        return oc
Example #19
0
def HandleSoundtracks(page=1):
    oc = ObjectContainer(title2=unicode(L('Soundtracks')))

    response = service.get_soundtracks(page=page)

    for item in response['movies']:
        new_params = {
            'type': 'soundtrack',
            'id': item['path'],
            'name': item['name'],
            'thumb': item['thumb']
        }

        oc.add(DirectoryObject(
            key=Callback(HandleSoundtrack, **new_params),
            title=plex_util.sanitize(item['name']),
            thumb=plex_util.get_thumb(item['thumb'])
        ))

    pagination.append_controls(oc, response, callback=HandleSoundtracks, page=page)

    return oc
Example #20
0
def HandleSoundtrack(operation=None, container=False, **params):
    oc = ObjectContainer(title2=unicode(params['name']))

    media_info = MediaInfo(**params)

    service.queue.handle_bookmark_operation(operation, media_info)

    albums = service.get_albums(params['id'])

    albums_count = len(albums)

    for index, album in enumerate(albums):
        prefix = str(index + 1) + ". " if albums_count > 1 else ""

        album_name = prefix + album['name']
        thumb = album['thumb']
        artist = album['composer']
        tracks = album['tracks']

        new_params = {
            'type': 'tracks',
            'name': album_name,
            'artist': artist,
            'tracks': json.dumps(tracks)
        }

        oc.add(DirectoryObject(
            key=Callback(HandleTracks, **new_params),
            title=plex_util.sanitize(album_name),
            thumb=plex_util.get_thumb(thumb)
        ))

    if str(container) == 'False':
        history.push_to_history(Data, media_info)
        service.queue.append_bookmark_controls(oc, HandleSoundtrack, media_info)

    return oc
Example #21
0
def HandleSerie(operation=None, **params):
    oc = ObjectContainer(title2=unicode(params['name']))

    media_info = MediaInfo(**params)

    service.queue.handle_bookmark_operation(operation, media_info)

    playlist_url = service.get_serie_playlist_url(params['id'])
    serie_info = service.get_serie_info(playlist_url)

    for index, item in enumerate(serie_info):
        season = index + 1
        season_name = item['comment'].replace('<b>', '').replace('</b>', '')
        episodes = item['playlist']
        rating_key = service.get_episode_url(params['id'], season, 0)

        new_params = {
            'type': 'season',
            'id': params['id'],
            'serieName': params['name'],
            'name': season_name,
            'thumb': params['thumb'],
            'season': season,
            'episodes': json.dumps(episodes)
        }

        oc.add(
            SeasonObject(key=Callback(HandleSeason, **new_params),
                         rating_key=rating_key,
                         title=plex_util.sanitize(season_name),
                         index=int(season),
                         thumb=plex_util.get_thumb(params['thumb'])))

    service.queue.append_bookmark_controls(oc, HandleSerie, media_info)

    return oc
Example #22
0
def HandleFilters(title, mode):
    oc = ObjectContainer(title2=unicode(L(title)))

    response = service.get_filters(mode=mode)

    for item in response:
        for name, list in item.iteritems():
            oc.add(DirectoryObject(
                key=Callback(HandleFilter, mode=mode, name=name, list=json.dumps(list)), title=plex_util.sanitize(name),
            ))

    return oc