Beispiel #1
0
def MainMenu():
    if datetime.datetime.now() > Dict['refresh'] + TWO_HOURS:
        LibraryRefresh()

    oc = ObjectContainer(title2=L('Title'))

    if API.authenticated == False and Prefs['email'] and Prefs['password']:
        API.authenticate(Prefs['email'], Prefs['password'])
        Thread.Create(LoadAsync)

    if API.authenticated:
        oc.add(
            DirectoryObject(key=Callback(LibraryMenu), title=L('My Library')))
        oc.add(
            DirectoryObject(key=Callback(PlaylistsMenu), title=L('Playlists')))
        oc.add(DirectoryObject(key=Callback(StationsMenu),
                               title=L('Stations')))

        if API.all_access:
            oc.add(DirectoryObject(key=Callback(GenresMenu),
                                   title=L('Genres')))
            oc.add(
                InputDirectoryObject(key=Callback(SearchMenu),
                                     title=L('Search'),
                                     prompt=L('Search Prompt'),
                                     thumb=R(SEARCH_ICON)))

    oc.add(DirectoryObject(key=Callback(RefreshMenu), title=L('Refresh')))
    oc.add(PrefsObject(title=L('Prefs Title'), thumb=R(PREFS_ICON)))
    return oc
def PlayAudio(id, storeId):
    if storeId != 0:
        try:
            song_url = API.get_stream_url(storeId)
        except CallFailure:
            song_url = API.get_stream_url(id)
    else:
        song_url = API.get_stream_url(id)

    return Redirect(song_url)
Beispiel #3
0
def PlayAudio(id, storeId):
    if storeId != 0:
        try:
            song_url = API.get_stream_url(storeId)
        except CallFailure:
            song_url = API.get_stream_url(id)
    else:
        song_url = API.get_stream_url(id)

    return Redirect(song_url)
def AddToCollection(id, playlist=None, type=0):
    if type == 0:
        item = API.add_aa_track(id)
    else:
        item = API.add_songs_to_playlist(playlist, id)

    if item == None:
        message = L('Adding Fail')
    else:
        message = L('Adding Success')

    LibraryRefresh()
    return ObjectContainer(header=L('Adding Song'), message=message)
Beispiel #5
0
def GetPlaylistContents(name, id):
    oc = ObjectContainer(title2=name)

    tracks = API.get_all_user_playlist_contents(id)
    for track in tracks:
        if 'track' in track:
            data = track['track']
        else:
            data = API.get_song(track['trackId'])

        oc.add(GetTrack(data, track['id']))

    return oc
def GetPlaylistContents(name, id):
    oc = ObjectContainer(title2=name)

    tracks = API.get_all_user_playlist_contents(id)
    for track in tracks:
        if 'track' in track:
            data = track['track']
        else:
            data = API.get_song(track['trackId'])

        oc.add(GetTrack(data, track['id']))

    return oc
Beispiel #7
0
def AddToCollection(id, playlist=None, type=0):
    if type == 0:
        item = API.add_aa_track(id)
    else:
        item = API.add_songs_to_playlist(playlist, id)

    if item == None:
        message = L('Adding Fail')
    else:
        message = L('Adding Success')

    LibraryRefresh()
    return ObjectContainer(header=L('Adding Song'), message=message)
def SearchMenu(query):
    oc = ObjectContainer(title2=L('Search'))

    results = API.search_all_access(query, 100)
    for key, values in results.iteritems():
        if key == 'song_hits':
            for song in values:
                do = DirectoryObject(
                    key=Callback(AddItemMenu, song=song['track']),
                    title=song['track']['title'],
                    summary=L('Song')
                )

                if 'albumArtRef' in song['track']:
                    do.thumb = song['track']['albumArtRef'][0]['url']

                oc.add(do)

        if key == 'artist_hits':
            for artist in values:
                artist = artist['artist']
                artistObj = DirectoryObject(
                    key=Callback(GetArtistInfo, name=artist['name'], id=artist['artistId']),
                    title=artist['name'],
                    summary=L('Artist')
                )
                if 'artistArtRef' in artist:
                    artistObj.thumb = artist['artistArtRef']

                oc.add(artistObj)

        if key == 'album_hits':
            for album in values:
                album = album['album']
                albumObj = DirectoryObject(
                    key=Callback(GetAlbumInfo, name=album['name'], id=album['albumId']),
                    title=album['name'],
                    summary=L('Album')
                )

                if 'albumArtRef' in album:
                    albumObj.thumb = album['albumArtRef']

                oc.add(albumObj)

        if key == 'playlist_hits':
            for playlist in values:
               playlist = playlist['playlist']
               playlistObj = DirectoryObject(
                   key=Callback(GetSharedPlaylist, name=playlist['name'], token=playlist['shareToken']),
                   title=playlist['name'],
                   summary=L('Playlist')
               )

               if 'albumArtRef' in playlist:
                   playlistObj.thumb = playlist['albumArtRef'][0]['url']

               oc.add(playlistObj)

    return oc
Beispiel #9
0
def PlaylistsMenu(id=None):
    oc = ObjectContainer(title2=L('Playlists'))

    playlists = API.get_all_playlists()
    for playlist in playlists:
        # This block is for normal selection of playlists
        if id == None:
            if 'type' in playlist and playlist['type'].lower(
            ) == 'user_generated':
                oc.add(
                    DirectoryObject(key=Callback(GetPlaylistContents,
                                                 name=playlist['name'],
                                                 id=playlist['id']),
                                    title=playlist['name']))
            else:
                oc.add(
                    DirectoryObject(key=Callback(GetSharedPlaylist,
                                                 name=playlist['name'],
                                                 token=playlist['shareToken']),
                                    title=playlist['name']))
        # This block is for when a song is being added to a playlist
        else:
            oc.add(
                DirectoryObject(key=Callback(AddToCollection,
                                             id=id,
                                             playlist=playlist['id'],
                                             type=1),
                                title=playlist['name']))

    oc.objects.sort(key=lambda obj: obj.title)
    return oc
Beispiel #10
0
def SearchMenu(query):
    oc = ObjectContainer(title2=L('Search'))

    results = API.search_all_access(query, 100)
    for key, values in results.iteritems():
        if key == 'song_hits':
            for song in values:
                do = DirectoryObject(key=Callback(AddItemMenu,
                                                  song=song['track']),
                                     title=song['track']['title'],
                                     summary=L('Song'))

                if 'albumArtRef' in song['track']:
                    do.thumb = song['track']['albumArtRef'][0]['url']

                oc.add(do)

        if key == 'artist_hits':
            for artist in values:
                artist = artist['artist']
                artistObj = DirectoryObject(key=Callback(
                    GetArtistInfo, name=artist['name'], id=artist['artistId']),
                                            title=artist['name'],
                                            summary=L('Artist'))
                if 'artistArtRef' in artist:
                    artistObj.thumb = artist['artistArtRef']

                oc.add(artistObj)

        if key == 'album_hits':
            for album in values:
                album = album['album']
                albumObj = DirectoryObject(key=Callback(GetAlbumInfo,
                                                        name=album['name'],
                                                        id=album['albumId']),
                                           title=album['name'],
                                           summary=L('Album'))

                if 'albumArtRef' in album:
                    albumObj.thumb = album['albumArtRef']

                oc.add(albumObj)

        if key == 'playlist_hits':
            for playlist in values:
                playlist = playlist['playlist']
                playlistObj = DirectoryObject(key=Callback(
                    GetSharedPlaylist,
                    name=playlist['name'],
                    token=playlist['shareToken']),
                                              title=playlist['name'],
                                              summary=L('Playlist'))

                if 'albumArtRef' in playlist:
                    playlistObj.thumb = playlist['albumArtRef'][0]['url']

                oc.add(playlistObj)

    return oc
Beispiel #11
0
def GetAlbumInfo(name, id):
    oc = ObjectContainer(title2=name)

    album = API.get_album_info(id)
    for track in album['tracks']:
        oc.add(GetTrack(track, track['nid']))

    return oc
Beispiel #12
0
def GetTrackList(name, type):
    oc = ObjectContainer(title2=name)
    tracks = API.get_tracks_for_type(type, name)
    sort = 'title' if type == 'Songs By Letter' else 'trackType'
    for track in sorted(tracks, key = lambda x: x['track'].get(sort)):
        oc.add(GetTrack(track['track'], track['id']))

    return oc
Beispiel #13
0
def GetSharedPlaylist(name, token):
    oc = ObjectContainer(title2=name)

    tracks = API.get_shared_playlist_contents(token)
    for track in tracks:
        oc.add(GetTrack(track['track'], track['trackId']))

    return oc
Beispiel #14
0
def GetTrackList(name, type):
    oc = ObjectContainer(title2=name)
    tracks = API.get_tracks_for_type(type, name)
    sort = 'title' if type == 'Songs By Letter' else 'trackType'
    for track in sorted(tracks, key=lambda x: x['track'].get(sort)):
        oc.add(GetTrack(track['track'], track['id']))

    return oc
Beispiel #15
0
def GetSharedPlaylist(name, token):
    oc = ObjectContainer(title2=name)

    tracks = API.get_shared_playlist_contents(token)
    for track in tracks:
        oc.add(GetTrack(track['track'], track['trackId']))

    return oc
Beispiel #16
0
def GetAlbumInfo(name, id):
    oc = ObjectContainer(title2=name)

    album = API.get_album_info(id)
    for track in album['tracks']:
        oc.add(GetTrack(track, track['nid']))

    return oc
Beispiel #17
0
def StationsMenu():
    oc = ObjectContainer(title2=L('Stations'))
    oc.add(DirectoryObject(key=Callback(GetStationTracks, name=L('Lucky Radio'), id='IFL'), title=L('Lucky Radio')))

    stations = API.get_all_stations()
    for station in sorted(stations, key = lambda x: int(x.get('recentTimestamp')), reverse=True):
        do = DirectoryObject(key=Callback(GetStationTracks, name=station['name'], id=station['id']), title=station['name'])
        if 'imageUrl' in station:
            do.thumb = station['imageUrl']
        oc.add(do)

    return oc
Beispiel #18
0
def MainMenu():
    if datetime.datetime.now() > Dict['refresh'] + TWO_HOURS:
        LibraryRefresh()

    oc = ObjectContainer(title2=L('Title'))

    if API.authenticated == False and Prefs['email'] and Prefs['password']:
        API.authenticate(Prefs['email'], Prefs['password'])
        Thread.Create(LoadAsync)

    if API.authenticated:
        oc.add(DirectoryObject(key=Callback(LibraryMenu), title=L('My Library')))
        oc.add(DirectoryObject(key=Callback(PlaylistsMenu), title=L('Playlists')))
        oc.add(DirectoryObject(key=Callback(StationsMenu), title=L('Stations')))

        if API.all_access:
            oc.add(DirectoryObject(key=Callback(GenresMenu), title=L('Genres')))
            oc.add(InputDirectoryObject(key=Callback(SearchMenu), title=L('Search'), prompt=L('Search Prompt'), thumb=R(SEARCH_ICON)))

    oc.add(DirectoryObject(key=Callback(RefreshMenu), title=L('Refresh')))
    oc.add(PrefsObject(title=L('Prefs Title'), thumb=R(PREFS_ICON)))
    return oc
Beispiel #19
0
def GetStationTracks(name, id):
    oc = ObjectContainer(title2=name)

    tracks = API.get_station_tracks(id)
    for track in tracks:
        if API.all_access:
            if 'nid' in track:
                id = track['nid']
            else:
                id = track['id']
        else:
            id = track['id']
        oc.add(GetTrack(track, id))

    return oc
Beispiel #20
0
def GetStationTracks(name, id):
    oc = ObjectContainer(title2=name)

    tracks = API.get_station_tracks(id)
    for track in tracks:
        if API.all_access:
            if 'nid' in track:
                id = track['nid']
            else:
                id = track['id']
        else:
            id = track['id']
        oc.add(GetTrack(track, id))

    return oc
Beispiel #21
0
def GenresMenu():
    oc = ObjectContainer(title2=L('Genres'))

    genres = API.get_genres()
    for genre in genres:
        if 'children' in genre:
            children = genre['children']
        else:
            children = None
        do = DirectoryObject(key=Callback(GenresSubMenu, name=genre['name'], id=genre['id'], children=children), title=genre['name'])
        if 'images' in genre:
            do.thumb = genre['images'][0]['url']
        oc.add(do)

    return oc
Beispiel #22
0
def GetAlbumsInLibrary(name):
    oc = ObjectContainer(title2=name)

    albums = API.get_albums_in_library(name)
    for album in sorted(albums['albums'], key = lambda x: x.get('year')):
        albumObj = DirectoryObject(
            key=Callback(GetAlbumInfo, name=album['name'], id=album['albumId']),
            title=album['name']
        )

        if 'albumArtRef' in album:
            albumObj.thumb = album['albumArtRef']

        oc.add(albumObj)

    return oc
Beispiel #23
0
def GetArtistInfo(name, id, inLibrary=False):
    oc = ObjectContainer(title2=name)

    artist = API.get_artist_info(id)
    for album in sorted(artist['albums'], key = lambda x: x.get('year')):
        albumObj = DirectoryObject(
            key=Callback(GetAlbumInfo, name=album['name'], id=album['albumId']),
            title=album['name']
        )

        if 'albumArtRef' in album:
            albumObj.thumb = album['albumArtRef']

        oc.add(albumObj)

    return oc
Beispiel #24
0
def GetArtistInfo(name, id, inLibrary=False):
    oc = ObjectContainer(title2=name)

    artist = API.get_artist_info(id)
    for album in sorted(artist['albums'], key=lambda x: x.get('year')):
        albumObj = DirectoryObject(key=Callback(GetAlbumInfo,
                                                name=album['name'],
                                                id=album['albumId']),
                                   title=album['name'])

        if 'albumArtRef' in album:
            albumObj.thumb = album['albumArtRef']

        oc.add(albumObj)

    return oc
Beispiel #25
0
def GetAlbumsInLibrary(name):
    oc = ObjectContainer(title2=name)

    albums = API.get_albums_in_library(name)
    for album in sorted(albums['albums'], key=lambda x: x.get('year')):
        albumObj = DirectoryObject(key=Callback(GetAlbumInfo,
                                                name=album['name'],
                                                id=album['albumId']),
                                   title=album['name'])

        if 'albumArtRef' in album:
            albumObj.thumb = album['albumArtRef']

        oc.add(albumObj)

    return oc
Beispiel #26
0
def PlaylistsMenu(id=None):
    oc = ObjectContainer(title2=L('Playlists'))

    playlists = API.get_all_playlists()
    for playlist in playlists:
        # This block is for normal selection of playlists
        if id == None:
            if 'type' in playlist and playlist['type'].lower() == 'user_generated':
                oc.add(DirectoryObject(key=Callback(GetPlaylistContents, name=playlist['name'], id=playlist['id']), title=playlist['name']))
            else:
                oc.add(DirectoryObject(key=Callback(GetSharedPlaylist, name=playlist['name'], token=playlist['shareToken']), title=playlist['name']))
        # This block is for when a song is being added to a playlist
        else:
            oc.add(DirectoryObject(key=Callback(AddToCollection, id=id, playlist=playlist['id'], type=1), title=playlist['name']))

    oc.objects.sort(key=lambda obj: obj.title)
    return oc
Beispiel #27
0
def GenresMenu():
    oc = ObjectContainer(title2=L('Genres'))

    genres = API.get_genres()
    for genre in genres:
        if 'children' in genre:
            children = genre['children']
        else:
            children = None
        do = DirectoryObject(key=Callback(GenresSubMenu,
                                          name=genre['name'],
                                          id=genre['id'],
                                          children=children),
                             title=genre['name'])
        if 'images' in genre:
            do.thumb = genre['images'][0]['url']
        oc.add(do)

    return oc
Beispiel #28
0
def StationsMenu():
    oc = ObjectContainer(title2=L('Stations'))
    oc.add(
        DirectoryObject(key=Callback(GetStationTracks,
                                     name=L('Lucky Radio'),
                                     id='IFL'),
                        title=L('Lucky Radio')))

    stations = API.get_all_stations()
    for station in sorted(stations,
                          key=lambda x: int(x.get('recentTimestamp')),
                          reverse=True):
        do = DirectoryObject(key=Callback(GetStationTracks,
                                          name=station['name'],
                                          id=station['id']),
                             title=station['name'])
        if 'imageUrl' in station:
            do.thumb = station['imageUrl']
        oc.add(do)

    return oc
Beispiel #29
0
def LoadAsync():
    API.load_data()
Beispiel #30
0
def LoadAsync():
    API.load_data()
Beispiel #31
0
def LibraryRefresh():
    HTTP.ClearCache()
    Dict['refresh'] = datetime.datetime.now()
    API.reset_library()
    Thread.Create(LoadAsync)
Beispiel #32
0
def CreateStation(id):
    name = Prettify(id)
    station = API.create_station(name, id)
    return GetStationTracks(name=name, id=station)
Beispiel #33
0
def CreateStation(id):
    name = Prettify(id)
    station = API.create_station(name, id)
    return GetStationTracks(name=name, id=station)
Beispiel #34
0
def LibraryRefresh():
    HTTP.ClearCache()
    Dict['refresh'] = datetime.datetime.now()
    API.reset_library()
    Thread.Create(LoadAsync)