예제 #1
0
def GetLiveChannels(title, favorite_only=False, category=0, page=1, **params):
    page = int(page)

    oc = ObjectContainer(title2=unicode(title))

    response = video_service.get_live_channels(favorite_only=favorite_only, category=category)

    for index, media in enumerate(response["data"]):
        if index >= (page - 1) * common.get_elements_per_page() and index < page * common.get_elements_per_page():
            id = media["id"]
            name = media["name"]
            thumb = media["icon"]
            files = media["files"]

            oc.add(
                DirectoryObject(
                    key=Callback(GetLiveChannel, name=name, channel_id=id, thumb=thumb, files=json.dumps(files)),
                    title=unicode(name),
                    thumb=Resource.ContentsOfURLWithFallback(url=thumb),
                )
            )

    add_pagination_to_response(response, page)
    pagination.append_controls(
        oc, response, callback=GetLiveChannels, title=title, favorite_only=favorite_only, page=page
    )

    return oc
예제 #2
0
def GetLiveChannels(title, favorite_only=False, category=0, page=1, **params):
    page = int(page)

    oc = ObjectContainer(title2=unicode(title))

    response = video_service.get_live_channels(favorite_only=favorite_only,
                                               category=category)

    for index, media in enumerate(response['data']):
        if index >= (page - 1) * common.get_elements_per_page(
        ) and index < page * common.get_elements_per_page():
            id = media['id']
            name = media['name']
            thumb = media['icon']
            files = media['files']

            oc.add(
                DirectoryObject(
                    key=Callback(GetLiveChannel,
                                 name=name,
                                 channel_id=id,
                                 thumb=thumb,
                                 files=json.dumps(files)),
                    title=unicode(name),
                    thumb=Resource.ContentsOfURLWithFallback(url=thumb)))

    add_pagination_to_response(response, page)
    pagination.append_controls(oc,
                               response,
                               callback=GetLiveChannels,
                               title=title,
                               favorite_only=favorite_only,
                               page=page)

    return oc
예제 #3
0
def SearchMusicAudioTracks(title, query, page, **params):
    oc = ObjectContainer(title2=unicode(L(title)))

    page = int(page)
    limit = common.get_elements_per_page()
    offset = (page-1)*limit

    response = service.search_audio_track(q=query, limit=common.get_elements_per_page(), offset=offset)

    for media in response['objects']:
        title = media['title']
        thumb = 'thumb'
        file = media['file']
        if media['album']['artist']:
            artist = media['album']['artist']['title']
        else:
            artist = ''

        format = 'mp3'
        url = service.BASE_URL + file

        oc.add(GetAudioTrack(title=unicode(title), thumb=thumb, artist=artist, format=format, url=url))

    common.add_pagination_to_response(response, page)
    pagination.append_controls(oc, response, callback=SearchMusicAudioTracks, title=title, query=query, page=page, **params)

    return oc
예제 #4
0
def HandleAudioTracks(name, thumb, page=1, **params):
    oc = ObjectContainer(title2=unicode(name))

    page = int(page)
    limit = common.get_elements_per_page()
    offset = (page-1)*limit

    response = service.get_tracks(limit=common.get_elements_per_page(), offset=offset, **params)

    for media in response['objects']:
        title = media['title']
        file = media['file']

        if media['album']['artist']:
            artist = media['album']['artist']['title']
        else:
            artist = ''

        format = 'mp3'
        url = service.BASE_URL + file

        oc.add(GetAudioTrack(title=unicode(title), thumb=thumb, artist=artist, format=format, url=url))

    music_queue.append_controls(oc, name=name, thumb=thumb, **params)

    common.add_pagination_to_response(response, page)
    pagination.append_controls(oc, response, callback=HandleAudioTracks, name=name, thumb=thumb, page=page, **params)

    return oc
예제 #5
0
def HandleCollections(title, page=1, **params):
    oc = ObjectContainer()

    page = int(page)
    limit = common.get_elements_per_page()
    offset = (page - 1) * limit

    response = service.get_collections(limit=limit, offset=offset)

    oc.title2 = unicode(L('Collections')) + ' (' + str(
        response['meta']['total_count']) + ')'

    for media in response['objects']:
        id = media['id']
        name = media['title']
        thumb = media['thumbnail']

        key = Callback(HandleCollection,
                       collection__id=id,
                       title=name,
                       thumb=thumb)
        oc.add(DirectoryObject(key=key, title=unicode(name), thumb=thumb))

    add_search_collections(oc)

    common.add_pagination_to_response(response, page)
    pagination.append_controls(oc,
                               response,
                               callback=HandleCollections,
                               title=title,
                               page=page)

    return oc
예제 #6
0
def HandleCollections(title, page=1, **params):
    oc = ObjectContainer()

    page = int(page)
    limit = common.get_elements_per_page()
    offset = (page-1)*limit

    response = service.get_collections(limit=limit, offset=offset)

    oc.title2 = unicode(L('Collections')) + ' (' + str(response['meta']['total_count']) + ')'

    for media in response['objects']:
        id = media['id']
        name = media['title']
        thumb = media['thumbnail']

        key = Callback(HandleCollection, collection__id=id, title=name, thumb=thumb)
        oc.add(DirectoryObject(key=key, title=unicode(name), thumb=thumb))

    add_search_collections(oc)

    common.add_pagination_to_response(response, page)
    pagination.append_controls(oc, response, callback=HandleCollections, title=title, page=page)

    return oc
예제 #7
0
def HandleAlbums(title, page=1, **params):
    oc = ObjectContainer(title2=unicode(L(title)))

    page = int(page)
    limit = common.get_elements_per_page()
    offset = (page-1)*limit

    response = service.get_albums(limit=limit, offset=offset,
                                        year__gte=common.get_start_music_year(),
                                        year__lte=common.get_end_music_year(),
                                        **params)

    oc.title2 = unicode(L(title)) + ' (' + str(response['meta']['total_count']) + ')'

    for media in BuildAlbumsList(response['objects']):
        oc.add(media)

    oc.add(InputDirectoryObject(
            key=Callback(SearchMusicAlbums, title=unicode(L("Albums Search")), page=page),
            title=unicode(L("Albums Search")),
            thumb=R(SEARCH_ICON)
    ))

    common.add_pagination_to_response(response, page)
    pagination.append_controls(oc, response, callback=HandleAlbums, title=title, page=page, **params)

    return oc
예제 #8
0
def HandleChildren(id, name, thumb, in_queue=False, page=1, dir='desc'):
    oc = ObjectContainer(title2=unicode(name))

    response = video_service.get_children(
        int(id), per_page=common.get_elements_per_page(), page=page, dir=dir)

    for media in HandleMediaList(response['data']['children'],
                                 in_queue=in_queue):
        oc.add(media)

    bookmarks.append_controls(oc, id=id, name=name, thumb=thumb)
    sorting.append_controls(oc,
                            HandleChildren,
                            id=id,
                            name=name,
                            thumb=thumb,
                            in_queue=in_queue,
                            page=page,
                            dir=dir)

    pagination.append_controls(oc,
                               response,
                               callback=HandleChildren,
                               id=id,
                               name=name,
                               thumb=thumb,
                               in_queue=in_queue,
                               page=page,
                               dir=dir)

    return oc
예제 #9
0
def SearchMusicArtists(title, query, page, **params):
    oc = ObjectContainer(title2=unicode(L(title)))

    page = int(page)
    limit = common.get_elements_per_page()
    offset = (page-1)*limit

    response = service.search_artist_annotated(q=query, limit=common.get_elements_per_page(), offset=offset)

    for artist in BuildArtistsList(response['objects']):
        oc.add(artist)

    common.add_pagination_to_response(response, page)
    pagination.append_controls(oc, response, callback=SearchMusicArtists, title=title, query=query, page=page, **params)

    return oc
예제 #10
0
def HandleAlbums(title, page=1, **params):
    oc = ObjectContainer(title2=unicode(L(title)))

    page = int(page)
    limit = common.get_elements_per_page()
    offset = (page - 1) * limit

    response = service.get_albums(limit=limit,
                                  offset=offset,
                                  year__gte=common.get_start_music_year(),
                                  year__lte=common.get_end_music_year(),
                                  **params)

    oc.title2 = unicode(L(title)) + ' (' + str(
        response['meta']['total_count']) + ')'

    for media in BuildAlbumsList(response['objects']):
        oc.add(media)

    oc.add(
        InputDirectoryObject(key=Callback(SearchMusicAlbums,
                                          title=unicode(L("Albums Search")),
                                          page=page),
                             title=unicode(L("Albums Search")),
                             thumb=R(SEARCH_ICON)))

    common.add_pagination_to_response(response, page)
    pagination.append_controls(oc,
                               response,
                               callback=HandleAlbums,
                               title=title,
                               page=page,
                               **params)

    return oc
예제 #11
0
def GetHistory(page=1, **params):
    oc = ObjectContainer(title2=unicode(L('History')))

    response = video_service.get_history(per_page=common.get_elements_per_page(), page=page)

    for media in HandleMediaList(response['data']['media']):
        oc.add(media)

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

    return oc
예제 #12
0
def HandleGenre(id, name, page=1, **params):
    oc = ObjectContainer(title2=unicode(name))

    response = video_service.get_archive(genre=int(id), per_page=common.get_elements_per_page(), page=page)

    for media in HandleMediaList(response['data']['media']):
        oc.add(media)

    pagination.append_controls(oc, response, page=page, callback=HandleGenre, id=id, name=name)

    return oc
예제 #13
0
def add_pagination_to_response(response, page):
    pages = len(response['data']) / common.get_elements_per_page()

    response['data'] = {
        'pagination': {
            'page': page,
            'pages': pages,
            'has_next': page < pages,
            'has_previous': page > 1
        }
    }
예제 #14
0
def GetHistory(page=1, **params):
    oc = ObjectContainer(title2=unicode(L('History')))

    response = video_service.get_history(
        per_page=common.get_elements_per_page(), page=page)

    for media in HandleMediaList(response['data']['media']):
        oc.add(media)

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

    return oc
예제 #15
0
def SearchMovies(query=None, page=1, **params):
    response = video_service.search(query=query, per_page=common.get_elements_per_page(), page=page)

    oc = ObjectContainer(title2=unicode(L('Movies Search')))

    for media in HandleMediaList(response['data']['media']):
        oc.add(media)

    pagination.append_controls(oc, response, page=page, callback=SearchMovies, query=query)

    if len(oc) < 1:
        return common.no_contents('Movies Search')

    return oc
예제 #16
0
def HandleChildren(id, name, thumb, in_queue=False, page=1, dir='desc'):
    oc = ObjectContainer(title2=unicode(name))

    response = video_service.get_children(int(id), per_page=common.get_elements_per_page(), page=page, dir=dir)

    for media in HandleMediaList(response['data']['children'], in_queue=in_queue):
        oc.add(media)

    bookmarks.append_controls(oc, id=id, name=name, thumb=thumb)
    sorting.append_controls(oc, HandleChildren, id=id, name=name, thumb=thumb, in_queue=in_queue, page=page, dir=dir)

    pagination.append_controls(oc, response, callback=HandleChildren, id=id, name=name, thumb=thumb,
                               in_queue=in_queue, page=page, dir=dir)

    return oc
예제 #17
0
def HandleGenre(id, name, page=1, **params):
    oc = ObjectContainer(title2=unicode(name))

    response = video_service.get_archive(
        genre=int(id), per_page=common.get_elements_per_page(), page=page)

    for media in HandleMediaList(response['data']['media']):
        oc.add(media)

    pagination.append_controls(oc,
                               response,
                               page=page,
                               callback=HandleGenre,
                               id=id,
                               name=name)

    return oc
예제 #18
0
def HandleLetter(title, page=1, **params):
    oc = ObjectContainer(title2=unicode(title))

    page = int(page)
    limit = common.get_elements_per_page()
    offset = (page-1)*limit

    response = service.get_artist_annotated(limit=limit, offset=offset, **params)

    for artist in BuildArtistsList(response['objects']):
        oc.add(artist)

    common.add_pagination_to_response(response, page)
    pagination.append_controls(oc, response, callback=HandleLetter, title=title, page=page, **params)

    add_search_artists(oc)

    return oc
예제 #19
0
def HandleDoubleAlbum(name, thumb, **params):
    oc = ObjectContainer(title2=unicode(name))

    response = service.get_albums(limit=common.get_elements_per_page(),
                                        year__gte=common.get_start_music_year(),
                                        year__lte=common.get_end_music_year(),
                                        **params)

    for media in response['objects']:
        id = media['id']
        title = media['title']
        thumb = media['thumbnail']

        key = Callback(audio_tracks.HandleAudioTracks, album=id, name=title, thumb=thumb)
        oc.add(DirectoryObject(key=key, title=unicode(title), thumb=thumb))

    music_queue.append_controls(oc, name=name, thumb=thumb, **params)

    return oc
예제 #20
0
def HandleArtists(title, page=1, **params):
    oc = ObjectContainer(title2=unicode(L(title)))

    page = int(page)
    limit = common.get_elements_per_page()
    offset = (page-1)*limit

    response = service.get_artists(limit=limit, offset=offset, **params)

    oc.title2 = unicode(L(title)) + ' (' + str(response['meta']['total_count']) + ')'

    for artist in BuildArtistsList(response['objects']):
        oc.add(artist)

    common.add_pagination_to_response(response, page)
    pagination.append_controls(oc, response, callback=HandleArtists, title=title, page=page)

    add_search_artists(oc)

    return oc
예제 #21
0
def SearchMovies(query=None, page=1, **params):
    response = video_service.search(query=query,
                                    per_page=common.get_elements_per_page(),
                                    page=page)

    oc = ObjectContainer(title2=unicode(L('Movies Search')))

    for media in HandleMediaList(response['data']['media']):
        oc.add(media)

    pagination.append_controls(oc,
                               response,
                               page=page,
                               callback=SearchMovies,
                               query=query)

    if len(oc) < 1:
        return common.no_contents('Movies Search')

    return oc
예제 #22
0
def HandleDoubleAlbum(name, thumb, **params):
    oc = ObjectContainer(title2=unicode(name))

    response = service.get_albums(limit=common.get_elements_per_page(),
                                  year__gte=common.get_start_music_year(),
                                  year__lte=common.get_end_music_year(),
                                  **params)

    for media in response['objects']:
        id = media['id']
        title = media['title']
        thumb = media['thumbnail']

        key = Callback(audio_tracks.HandleAudioTracks,
                       album=id,
                       name=title,
                       thumb=thumb)
        oc.add(DirectoryObject(key=key, title=unicode(title), thumb=thumb))

    music_queue.append_controls(oc, name=name, thumb=thumb, **params)

    return oc
예제 #23
0
def add_pagination_to_response(response, page):
    pages = len(response["data"]) / common.get_elements_per_page()

    response["data"] = {
        "pagination": {"page": page, "pages": pages, "has_next": page < pages, "has_previous": page > 1}
    }