def my_library():
    playlists = xbmcgui.ListItem(utils.translate(30020))
    playlists.setArt({
        'thumb': thumbs.IMG_PLAYLIST,
        'poster': thumbs.IMG_PLAYLIST
    })

    stations = xbmcgui.ListItem(utils.translate(30021))
    stations.setArt({
        'thumb': thumbs.IMG_STATION,
        'poster': thumbs.IMG_STATION
    })

    artists = xbmcgui.ListItem(utils.translate(30022))
    artists.setArt({'thumb': thumbs.IMG_ARTIST, 'poster': thumbs.IMG_ARTIST})

    albums = xbmcgui.ListItem(utils.translate(30023))
    albums.setArt({'thumb': thumbs.IMG_ALBUM, 'poster': thumbs.IMG_ALBUM})

    songs = xbmcgui.ListItem(utils.translate(30024))
    songs.setArt({'thumb': thumbs.IMG_TRACK, 'poster': thumbs.IMG_TRACK})
    genres = xbmcgui.ListItem(utils.translate(30025))
    genres.setArt({'thumb': thumbs.IMG_GENRE, 'poster': thumbs.IMG_GENRE})

    items = [
        (utils.build_url(URL, ['playlists']), playlists, True),
        (utils.build_url(URL, ['stations']), stations, True),
        (utils.build_url(URL, ['artists']), artists, True),
        (utils.build_url(URL, ['albums']), albums, True),
        (utils.build_url(URL, ['songs']), songs, True),
        (utils.build_url(URL, ['genres']), genres, True),
    ]

    listing.list_items(items)
Esempio n. 2
0
def browse_stations_categories(category_id):
    categories = GMUSIC.get_station_categories(True)

    if categories:
        items = []
        for category in categories:
            if category['id'] != category_id:
                continue

            subcategories = category['subcategories']
            for sub in subcategories:
                item = xbmcgui.ListItem(sub['display_name'])
                item.setArt({
                    'thumb': thumbs.IMG_STATION,
                    'poster': thumbs.IMG_STATION
                })

                items.append((
                    utils.build_url(
                        url=URL,
                        paths=['browse', 'browse-stations',
                               'subcategories', sub['id']],
                        r_path=True,
                        r_query=True
                    ),
                    item,
                    True
                ))

    listing.list_items(items)
Esempio n. 3
0
def artist(artist_id):
    top_songs = xbmcgui.ListItem(utils.translate(30066))
    top_songs.setArt({'thumb': thumbs.IMG_STAR, 'poster': thumbs.IMG_STAR})

    related_artists = xbmcgui.ListItem(utils.translate(30067))
    related_artists.setArt({
        'thumb': thumbs.IMG_ARTIST,
        'poster': thumbs.IMG_ARTIST
    })

    items = [
        (utils.build_url(url=URL,
                         paths=['browse', 'artist', artist_id, 'top-songs'],
                         r_path=True), top_songs, True),
        (utils.build_url(
            url=URL,
            paths=['browse', 'artist', artist_id, 'related-artists'],
            r_path=True), related_artists, True)
    ]

    info = GMUSIC.get_artist_info(artist_id=artist_id,
                                  include_albums=True,
                                  max_top_tracks=0,
                                  max_rel_artist=0)

    if 'albums' in info:
        albums = info['albums']
        albums.sort(key=itemgetter('name'))
        albums.sort(key=itemgetter('year'), reverse=True)

        items += listing.build_album_listitems(albums)
        listing.list_albums(items)

    else:
        listing.list_items([])
Esempio n. 4
0
def new_releases():
    releases = GMUSIC.get_new_releases()
    if releases:
        items = listing.build_album_listitems(releases)
        listing.list_albums(items)

    else:
        listing.list_items([])
Esempio n. 5
0
def album(album_id):
    album_info = GMUSIC.get_album_info(album_id=album_id)

    if album_info and 'tracks' in album_info:
        items = listing.build_song_listitems(album_info['tracks'])
        listing.list_songs(items)

    else:
        listing.list_items([])
Esempio n. 6
0
def top_charts_albums():
    top_charts = GMUSIC.get_top_chart()

    if top_charts and 'albums' in top_charts:
        items = listing.build_album_listitems(top_charts['albums'])
        listing.list_albums(items)

    else:
        listing.list_items([])
Esempio n. 7
0
def listen_now():
    ifl = xbmcgui.ListItem(utils.translate(30045))
    ifl.setArt({'thumb': thumbs.IMG_IFL, 'poster': thumbs.IMG_IFL})

    albums = xbmcgui.ListItem(utils.translate(30023))
    albums.setArt({'thumb': thumbs.IMG_ALBUM, 'poster': thumbs.IMG_ALBUM})

    stations = xbmcgui.ListItem(utils.translate(30021))
    stations.setArt({
        'thumb': thumbs.IMG_STATION,
        'poster': thumbs.IMG_STATION
    })

    playlists = xbmcgui.ListItem(utils.translate(30020))
    playlists.setArt({
        'thumb': thumbs.IMG_PLAYLIST,
        'poster': thumbs.IMG_PLAYLIST
    })

    items = [
        (utils.build_url(url=URL,
                         paths=['play', 'station'],
                         queries={'station_id': 'IFL'},
                         r_path=True,
                         r_query=True), ifl, False),
        (utils.build_url(URL, ['albums']), albums, True),
        (utils.build_url(URL, ['stations']), stations, True),
        (utils.build_url(URL, ['playlists']), playlists, True),
    ]

    # Only fetch new information if one full hour has passed
    # to keep things speedy on slow devices
    try:
        last_check = ADDON.getSetting('listen_now_last_update')

    except:
        last_check = -1

    from_cache = True
    if last_check != time.strftime('%Y%m%d%H'):
        from_cache = False
        ADDON.setSetting('listen_now_last_update', time.strftime('%Y%m%d%H'))

    primary_header, situations = gmusic.get_listen_now_situations(from_cache)

    if primary_header and situations:
        situations = xbmcgui.ListItem(primary_header)
        situations.setArt({
            'thumb': thumbs.IMG_ALBUM,
            'poster': thumbs.IMG_ALBUM
        })

        # Add Situations after IFL
        items.insert(1,
                     (utils.build_url(URL, ['situations']), situations, True))

    listing.list_items(items)
Esempio n. 8
0
def top_charts_songs():
    top_charts = GMUSIC.get_top_chart()

    if top_charts and 'tracks' in top_charts:
        items = listing.build_song_listitems(top_charts['tracks'])
        listing.list_songs(items)

    else:
        listing.list_items([])
Esempio n. 9
0
def top_charts():
    songs = xbmcgui.ListItem(utils.translate(30024))
    songs.setArt({'thumb': thumbs.IMG_TRACK, 'poster': thumbs.IMG_TRACK})

    albums = xbmcgui.ListItem(utils.translate(30023))
    albums.setArt({'thumb': thumbs.IMG_ALBUM, 'poster': thumbs.IMG_ALBUM})

    items = [(utils.build_url(URL, ['songs']), songs, True),
             (utils.build_url(URL, ['albums']), albums, True)]

    listing.list_items(items)
Esempio n. 10
0
def artist_related_artists(artist_id):
    artist = GMUSIC.get_artist_info(artist_id=artist_id,
                                    include_albums=False,
                                    max_top_tracks=0,
                                    max_rel_artist=100)

    if artist and 'related_artists' in artist:
        items = listing.build_artist_listitems(artist['related_artists'])
        listing.list_artists(items)

    else:
        listing.list_items([])
Esempio n. 11
0
def artist_top_tracks(artist_id):
    artist = GMUSIC.get_artist_info(artist_id=artist_id,
                                    include_albums=False,
                                    max_top_tracks=100,
                                    max_rel_artist=0)

    if artist and 'topTracks' in artist:
        items = listing.build_song_listitems(artist['topTracks'])
        listing.list_songs(items)

    else:
        listing.list_items([])
def my_library_genres():
    genres = GMUSIC.get_my_library_genres()

    items = []
    for genre in genres:
        item = xbmcgui.ListItem(genre)
        item.setArt({'thumb': thumbs.IMG_GENRE, 'poster': thumbs.IMG_GENRE})

        items.append(
            (utils.build_url(url=URL,
                             paths=['browse', 'my-library', 'genre', genre],
                             r_path=True), item, True))

    listing.list_items(items)
Esempio n. 13
0
def search_history():
    history = _get_search_history()

    # Add "New Search" to the list
    item = xbmcgui.ListItem(utils.translate(30053))
    item.setArt({'thumb': thumbs.IMG_SEARCH, 'poster': thumbs.IMG_SEARCH})

    items = [(utils.build_url(url=URL,
                              paths=['search', 'new'],
                              r_path=True,
                              r_query=True), item, True)]

    for hist in history:
        item = xbmcgui.ListItem(hist)
        item.setArt({'thumb': thumbs.IMG_SEARCH, 'poster': thumbs.IMG_SEARCH})

        items.append((utils.build_url(url=URL,
                                      paths=['search', hist],
                                      r_path=True,
                                      r_query=True), item, True))

    listing.list_items(items)
Esempio n. 14
0
def browse_stations():
    categories = GMUSIC.get_station_categories(False)

    items = []
    for category in categories:
        item = xbmcgui.ListItem(category['display_name'])
        item.setArt({
            'thumb': thumbs.IMG_STATION,
            'poster': thumbs.IMG_STATION
        })

        items.append((
            utils.build_url(
                url=URL,
                paths=['browse', 'browse-stations',
                       'categories', category['id']],
                r_path=True,
                r_query=True
            ),
            item,
            True
        ))

    listing.list_items(items)
Esempio n. 15
0
def listen_now_situation(situation_id):
    def _find_situation(situation_id, situations, parent=None):
        """ Helper to find the right situation as
        situations can have situations as child (instead of stations)
        """
        match = None
        for situation in situations:
            parent = situation

            if 'id' in situation and situation['id'] == situation_id:
                match = situation

            elif 'situations' in situation:
                parent, match = _find_situation(situation_id,
                                                situation['situations'],
                                                parent)

            if match:
                return parent, match

        return None, None

    primary_header, situations = gmusic.get_listen_now_situations(
        from_cache=True)

    if not situations:
        listing.list_items([])
        return

    parent, situation = _find_situation(situation_id, situations)

    if not situation:
        listing.list_items([])
        return

    items = []
    if 'situations' in situation:
        sub_situations = situation['situations']
        for i, sit in enumerate(sub_situations):
            sub_situations[i]['imageUrl'] = parent['imageUrl']

        items = listing.build_situation_listitems(sub_situations)

    elif 'stations' in situation:
        stations = []
        for station in situation['stations']:
            art = ''
            for img_urls in station['compositeArtRefs']:
                if int(img_urls['aspectRatio']) == 1:
                    art = img_urls['url']
                    break

            stations.append({
                'name':
                station['name'],
                'imageUrls': [{
                    'url': art
                }],
                'curatedStationId':
                station['seed']['curatedStationId'],
                'description':
                station['description']
            })

        items = listing.build_station_listitems(stations)

    listing.list_stations(items)
Esempio n. 16
0
def main_menu():
    listen_now = xbmcgui.ListItem(utils.translate(30014))
    listen_now.setArt({
        'thumb': thumbs.IMG_HEADPHONES,
        'poster': thumbs.IMG_HEADPHONES
    })

    top_charts = xbmcgui.ListItem(utils.translate(30015))
    top_charts.setArt({
        'thumb': thumbs.IMG_STAR,
        'poster': thumbs.IMG_STAR
    })

    new_releases = xbmcgui.ListItem(utils.translate(30016))
    new_releases.setArt({
        'thumb': thumbs.IMG_RELEASES,
        'poster': thumbs.IMG_RELEASES
    })

    my_library = xbmcgui.ListItem(utils.translate(30017))
    my_library.setArt({
        'thumb': thumbs.IMG_LIBRARY,
        'poster': thumbs.IMG_LIBRARY
    })

    browse_stations = xbmcgui.ListItem(utils.translate(30018))
    browse_stations.setArt({
        'thumb': thumbs.IMG_STATION,
        'poster': thumbs.IMG_STATION
    })

    search = xbmcgui.ListItem(utils.translate(30019))
    search.setArt({
        'thumb': thumbs.IMG_SEARCH,
        'poster': thumbs.IMG_SEARCH
    })

    items = [
        (
            utils.build_url(URL, ['listen-now']),
            listen_now,
            True
        ),
        (
            utils.build_url(URL, ['top-charts']),
            top_charts,
            True
        ),
        (
            utils.build_url(URL, ['new-releases']),
            new_releases,
            True
        ),
        (
            utils.build_url(URL, ['my-library']),
            my_library,
            True
        ),
        (
            utils.build_url(URL, ['browse-stations']),
            browse_stations,
            True
        ),
        (
            utils.build_url(URL, ['search', 'history'], r_path=True),
            search,
            True
        ),
    ]

    # Add "Update Library" context menu to "My Library" entry
    items[3][1].addContextMenuItems([(
        utils.translate(30030),
        'XBMC.RunPlugin(%s)' % utils.build_url(
            url=URL,
            paths=['my-library', 'update'],
            r_path=True
        )
    )])

    # Add "Clear search history" context menu to "Search" entry
    items[5][1].addContextMenuItems([(
        utils.translate(30012),
        'XBMC.RunPlugin(%s)' % utils.build_url(
            url=URL,
            paths=['clear', 'search-history'],
            r_path=True
        )
    )])

    listing.list_items(items)
Esempio n. 17
0
def search(query):
    history_file = os.path.join(_CACHE_DIR, 'search_history.json')
    history = _get_search_history()

    # It was a new search so we add it to the history
    if query.decode('utf-8').lower() not in (hist.lower() for hist in history):
        history.insert(0, query)
        with codecs.open(history_file, 'w+', encoding='utf-8') as f:
            f.write(json.dumps(history[:20], indent=2))

    result = GMUSIC.search(query)

    if not result:
        listing.list_items([])
        return

    items = []
    if 'artist_hits' in result and len(result['artist_hits']) > 0:
        item = xbmcgui.ListItem(
            '%s (%s)' % (utils.translate(30022), len(result['artist_hits'])))
        item.setArt({'thumb': thumbs.IMG_ARTIST, 'poster': thumbs.IMG_ARTIST})

        items.append((utils.build_url(url=URL,
                                      paths=['search', 'artists', query],
                                      r_path=True,
                                      r_query=True), item, True))

    if 'album_hits' in result and len(result['album_hits']) > 0:
        item = xbmcgui.ListItem(
            '%s (%s)' % (utils.translate(30023), len(result['album_hits'])))
        item.setArt({'thumb': thumbs.IMG_ALBUM, 'poster': thumbs.IMG_ALBUM})

        items.append((utils.build_url(url=URL,
                                      paths=['search', 'albums', query],
                                      r_path=True,
                                      r_query=True), item, True))

    if 'playlist_hits' in result and len(result['playlist_hits']) > 0:
        item = xbmcgui.ListItem(
            '%s (%s)' % (utils.translate(30020), len(result['playlist_hits'])))
        item.setArt({
            'thumb': thumbs.IMG_PLAYLIST,
            'poster': thumbs.IMG_PLAYLIST
        })

        items.append((utils.build_url(url=URL,
                                      paths=['search', 'playlists', query],
                                      r_path=True,
                                      r_query=True), item, True))

    if 'station_hits' in result and len(result['station_hits']) > 0:
        item = xbmcgui.ListItem(
            '%s (%s)' % (utils.translate(30021), len(result['station_hits'])))
        item.setArt({
            'thumb': thumbs.IMG_STATION,
            'poster': thumbs.IMG_STATION
        })

        items.append((utils.build_url(url=URL,
                                      paths=['search', 'stations', query],
                                      r_path=True,
                                      r_query=True), item, True))

    if 'song_hits' in result and len(result['song_hits']) > 0:
        item = xbmcgui.ListItem(
            '%s (%s)' % (utils.translate(30024), len(result['song_hits'])))
        item.setArt({'thumb': thumbs.IMG_TRACK, 'poster': thumbs.IMG_TRACK})

        items.append((utils.build_url(url=URL,
                                      paths=['search', 'songs', query],
                                      r_path=True,
                                      r_query=True), item, True))

    listing.list_items(items)