Beispiel #1
0
def HandleArtists(title, page=1, **params):
    oc = ObjectContainer(title2=unicode(L(title)))

    page = int(page)
    limit = util.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)

    service.add_pagination_to_response(response, page,
                                       util.get_elements_per_page())
    pagination.append_controls(oc,
                               response['data'],
                               callback=HandleArtists,
                               title=title,
                               page=page)

    oc.add(
        InputDirectoryObject(key=Callback(SearchArtists,
                                          title=unicode(L("Artists Search"))),
                             title=unicode(L("Artists Search")),
                             thumb=R(SEARCH_ICON)))

    return oc
Beispiel #2
0
def HandleCollections(title, page=1):
    oc = ObjectContainer()

    page = int(page)
    limit = util.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']:
        name = media['title']
        thumb = media['thumbnail']

        new_params = {
            'type': 'collection',
            'id': media['id'],
            'collection__id': media['id'],
            'name': name,
            'thumb': thumb
        }
        key = Callback(HandleCollection, **new_params)
        oc.add(DirectoryObject(key=key, title=unicode(name), thumb=thumb))

    oc.add(InputDirectoryObject(
        key=Callback(SearchCollections, title=unicode(L("Collections Search"))),
        title=unicode(L("Collections Search")),
        thumb=R(SEARCH_ICON)
    ))

    service.add_pagination_to_response(response, page, util.get_elements_per_page())
    pagination.append_controls(oc, response['data'], callback=HandleCollections, title=title, page=page)

    return oc
Beispiel #3
0
def SearchCollections(title, query, page=1, **params):
    page = int(page)
    limit = util.get_elements_per_page()
    offset = (page - 1) * limit

    oc = ObjectContainer(title2=unicode(L(title)))

    response = service.search_collection(q=query,
                                         limit=util.get_elements_per_page(),
                                         offset=offset)

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

    service.add_pagination_to_response(response, page,
                                       util.get_elements_per_page())
    pagination.append_controls(oc,
                               response['data'],
                               callback=SearchCollections,
                               title=title,
                               query=query,
                               page=page,
                               **params)

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

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

    response = service.get_albums(limit=limit, offset=offset,
                                  year__gte=util.get_start_music_year(),
                                  year__lte=util.get_end_music_year(),
                                  **service.filter_request_params(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(SearchAlbums, title=unicode(L("Albums Search")), page=page),
            title=unicode(L("Albums Search")),
            thumb=R(SEARCH_ICON)
    ))

    service.add_pagination_to_response(response, page, util.get_elements_per_page())
    pagination.append_controls(oc, response['data'], callback=HandleAlbums, title=title, page=page, **params)

    return oc
Beispiel #5
0
def SearchTracks(title, query, page, **params):
    oc = ObjectContainer(title2=unicode(L(title)))

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

    response = service.search_audio_track(q=query, limit=util.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

        new_params = {
            'type': 'track',
            'id': url,
            'name': title,
            'thumb': 'thumb',
            'artist': artist,
            'format': format
        }
        oc.add(HandleTrack(**new_params))

    service.add_pagination_to_response(response, page, util.get_elements_per_page())
    pagination.append_controls(oc, response['data'], callback=SearchTracks, title=title, query=query, page=page, **params)

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

    oc = ObjectContainer(title2=unicode(title))

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

    for index, media in enumerate(response['data']):
        if index >= (page - 1) * util.get_elements_per_page() and index < page * util.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), **params),
                    title=unicode(name),
                    thumb=Resource.ContentsOfURLWithFallback(url=thumb)
            ))

    add_pagination_to_response(response, page)
    pagination.append_controls(oc, response['data'], callback=GetLiveChannels, title=title, favorite_only=favorite_only,
                               page=page, **params)

    return oc
Beispiel #7
0
def HandleTracks(operation=None, page=1, **params):
    media_info = MediaInfo(**params)

    if 'album' in params:
        media_info['id'] = params['album']

    service.queue.handle_bookmark_operation(operation, media_info)

    oc = ObjectContainer(title2=unicode(params['name']))

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

    response = service.get_tracks(limit=util.get_elements_per_page(),
                                  offset=offset,
                                  **service.filter_request_params(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
        bitrate = "128"

        new_params = {
            'type': 'track',
            'id': url,
            'name': title,
            'thumb': params['thumb'],
            'artist': artist,
            'format': format,
            'bitrate': bitrate
        }

        oc.add(HandleTrack(**new_params))

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

    service.add_pagination_to_response(response, page,
                                       util.get_elements_per_page())
    pagination.append_controls(oc,
                               response['data'],
                               callback=HandleTracks,
                               page=page,
                               **params)

    return oc
Beispiel #8
0
def HandleTracks(operation=None, page=1, **params):
    media_info = MediaInfo(**params)

    if 'album' in params:
        media_info['id'] = params['album']

    service.queue.handle_bookmark_operation(operation, media_info)

    oc = ObjectContainer(title2=unicode(params['name']))

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

    response = service.get_tracks(limit=util.get_elements_per_page(), offset=offset,
                                  **service.filter_request_params(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
        bitrate = "128"

        new_params = {
            'type': 'track',
            'id': url,
            'name': title,
            'thumb': params['thumb'],
            'artist': artist,
            'format': format,
            'bitrate': bitrate
        }

        oc.add(HandleTrack(**new_params))

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

    service.add_pagination_to_response(response, page, util.get_elements_per_page())
    pagination.append_controls(oc, response['data'], callback=HandleTracks, page=page, **params)

    return oc
Beispiel #9
0
def HandleDoubleAlbum(operation=None, **params):
    oc = ObjectContainer(title2=unicode(params['name']))

    media_info = MediaInfo(**params)

    service.queue.handle_bookmark_operation(operation, media_info)

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

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

        new_params = {
            'type': 'album',
            'album': id,
            'id': id,
            'name': name,
            'thumb': thumb
        }
        key = Callback(HandleTracks, **new_params)
        oc.add(DirectoryObject(key=key, title=unicode(name), thumb=thumb))

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

    return oc
Beispiel #10
0
def SearchCollections(title, query, page=1, **params):
    page = int(page)
    limit = util.get_elements_per_page()
    offset = (page-1)*limit

    oc = ObjectContainer(title2=unicode(L(title)))

    response = service.search_collection(q=query, limit=util.get_elements_per_page(), offset=offset)

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

    service.add_pagination_to_response(response, page, util.get_elements_per_page())
    pagination.append_controls(oc, response['data'], callback=SearchCollections, title=title, query=query, page=page, **params)

    return oc
Beispiel #11
0
def HandleDoubleAlbum(operation=None, **params):
    oc = ObjectContainer(title2=unicode(params['name']))

    media_info = MediaInfo(**params)

    service.queue.handle_bookmark_operation(operation, media_info)

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

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

        new_params = {
            'type': 'album',
            'album': id,
            'id': id,
            'name': name,
            'thumb': thumb
        }
        key = Callback(HandleTracks, **new_params)
        oc.add(DirectoryObject(key=key, title=unicode(name), thumb=thumb))

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

    return oc
Beispiel #12
0
def add_pagination_to_response(response, page):
    pages = len(response['data']) / util.get_elements_per_page()

    response['data'] = {'pagination': {
        'page': page,
        'pages': pages,
        'has_next': page < pages,
        'has_previous': page > 1
    }}
Beispiel #13
0
def SearchTracks(title, query, page, **params):
    oc = ObjectContainer(title2=unicode(L(title)))

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

    response = service.search_audio_track(q=query,
                                          limit=util.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

        new_params = {
            'type': 'track',
            'id': url,
            'name': title,
            'thumb': 'thumb',
            'artist': artist,
            'format': format
        }
        oc.add(HandleTrack(**new_params))

    service.add_pagination_to_response(response, page,
                                       util.get_elements_per_page())
    pagination.append_controls(oc,
                               response['data'],
                               callback=SearchTracks,
                               title=title,
                               query=query,
                               page=page,
                               **params)

    return oc
Beispiel #14
0
def HandleCollections(title, page=1):
    oc = ObjectContainer()

    page = int(page)
    limit = util.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']:
        name = media['title']
        thumb = media['thumbnail']

        new_params = {
            'type': 'collection',
            'id': media['id'],
            'collection__id': media['id'],
            'name': name,
            'thumb': thumb
        }
        key = Callback(HandleCollection, **new_params)
        oc.add(DirectoryObject(key=key, title=unicode(name), thumb=thumb))

    oc.add(
        InputDirectoryObject(key=Callback(SearchCollections,
                                          title=unicode(
                                              L("Collections Search"))),
                             title=unicode(L("Collections Search")),
                             thumb=R(SEARCH_ICON)))

    service.add_pagination_to_response(response, page,
                                       util.get_elements_per_page())
    pagination.append_controls(oc,
                               response['data'],
                               callback=HandleCollections,
                               title=title,
                               page=page)

    return oc
Beispiel #15
0
def add_pagination_to_response(response, page):
    pages = len(response['data']) / util.get_elements_per_page()

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

    response = service.get_history(per_page=util.get_elements_per_page(), page=page)

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

    pagination.append_controls(oc, response['data'], page=page, callback=GetHistory, params=params)

    return oc
Beispiel #17
0
def HandleTopic(id, page=1, **params):
    oc = ObjectContainer(title2=unicode(L(id)))

    response = service.get_topic_items(id, page=page, per_page=util.get_elements_per_page())

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

    pagination.append_controls(oc, response['data'], callback=HandleTopic, id=id, page=page, params=params)

    return oc
Beispiel #18
0
def HandleChannel(id, name, page=1, **params):
    oc = ObjectContainer(title2=unicode(name))

    response = service.get_archive(channel_id=id, per_page=util.get_elements_per_page(), page=page)

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

    pagination.append_controls(oc, response['data'], page=page, callback=HandleChannel, id=id, name=name, params=params)

    return oc
Beispiel #19
0
def HandleLetter(title, page=1, **params):
    oc = ObjectContainer(title2=unicode(title))

    page = int(page)
    limit = util.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)

    service.add_pagination_to_response(response, page, util.get_elements_per_page())
    pagination.append_controls(oc, response['data'], callback=HandleLetter, title=title, page=page, **params)

    oc.add(InputDirectoryObject(
        key=Callback(SearchArtists, title=unicode(L("Artists Search"))),
        title=unicode(L("Artists Search")),
        thumb=R(SEARCH_ICON)
    ))

    return oc
Beispiel #20
0
def SearchMovies(query=None, page=1, **params):
    response = service.search(query=query, per_page=util.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['data'], page=page, callback=SearchMovies, query=query, params=params)

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

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

    oc = ObjectContainer(title2=unicode(title))

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

    for index, media in enumerate(response['data']):
        if index >= (page - 1) * util.get_elements_per_page(
        ) and index < page * util.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),
                                 **params),
                    title=unicode(name),
                    thumb=Resource.ContentsOfURLWithFallback(url=thumb)))

    add_pagination_to_response(response, page)
    pagination.append_controls(oc,
                               response['data'],
                               callback=GetLiveChannels,
                               title=title,
                               favorite_only=favorite_only,
                               page=page,
                               **params)

    return oc
Beispiel #22
0
def HandleChildren(id,
                   name,
                   thumb,
                   operation=None,
                   in_queue=False,
                   page=1,
                   dir='desc'):
    oc = ObjectContainer(title2=unicode(name))

    if operation == 'add':
        service.add_bookmark(id)
    elif operation == 'remove':
        service.remove_bookmark(id)

    response = service.get_children(int(id),
                                    per_page=util.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,
                              HandleChildren,
                              id=id,
                              name=name,
                              thumb=thumb,
                              operation=operation)
    append_sorting_controls(oc,
                            HandleChildren,
                            id=id,
                            name=name,
                            thumb=thumb,
                            in_queue=in_queue,
                            page=page,
                            dir=dir)

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

    return oc
Beispiel #23
0
def GetNewArrivals(page=1, **params):
    oc = ObjectContainer(title2=unicode(L('New Arrivals')))

    response = service.get_new_arrivals(per_page=util.get_elements_per_page(),
                                        page=page)

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

    pagination.append_controls(oc,
                               response['data'],
                               page=page,
                               callback=GetNewArrivals)

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

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

    response = service.get_albums(limit=limit,
                                  offset=offset,
                                  year__gte=util.get_start_music_year(),
                                  year__lte=util.get_end_music_year(),
                                  **service.filter_request_params(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(SearchAlbums,
                                          title=unicode(L("Albums Search")),
                                          page=page),
                             title=unicode(L("Albums Search")),
                             thumb=R(SEARCH_ICON)))

    service.add_pagination_to_response(response, page,
                                       util.get_elements_per_page())
    pagination.append_controls(oc,
                               response['data'],
                               callback=HandleAlbums,
                               title=title,
                               page=page,
                               **params)

    return oc
Beispiel #25
0
def HandleTopic(id, page=1, **params):
    oc = ObjectContainer(title2=unicode(L(id)))

    response = service.get_topic_items(id,
                                       page=page,
                                       per_page=util.get_elements_per_page())

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

    pagination.append_controls(oc,
                               response['data'],
                               callback=HandleTopic,
                               id=id,
                               page=page,
                               params=params)

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

    response = service.get_archive(genre=int(id),
                                   per_page=util.get_elements_per_page(),
                                   page=page)

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

    pagination.append_controls(oc,
                               response['data'],
                               page=page,
                               callback=HandleGenre,
                               id=id,
                               name=name,
                               params=params)

    return oc
Beispiel #27
0
def HandleChildren(id, name, thumb, operation=None, in_queue=False, page=1, dir='desc'):
    oc = ObjectContainer(title2=unicode(name))

    if operation == 'add':
        service.add_bookmark(id)
    elif operation == 'remove':
        service.remove_bookmark(id)

    response = service.get_children(int(id), per_page=util.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, HandleChildren, id=id, name=name, thumb=thumb, operation=operation)
    append_sorting_controls(oc, HandleChildren, id=id, name=name, thumb=thumb, in_queue=in_queue, page=page, dir=dir)

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

    return oc
Beispiel #28
0
def SearchMovies(query=None, page=1, **params):
    response = service.search(query=query,
                              per_page=util.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['data'],
                               page=page,
                               callback=SearchMovies,
                               query=query,
                               params=params)

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

    return oc