Пример #1
0
def _browse_toplist(config, session, variant, region):
    if region == 'countries':
        codes = config['toplist_countries']
        if not codes:
            codes = countries.COUNTRIES.keys()
        return [
            models.Ref.directory(
                uri='spotify:top:%s:%s' % (variant, code.lower()),
                name=countries.COUNTRIES.get(code.upper(), code.upper()))
            for code in codes]

    if region in ('user', 'country', 'everywhere'):
        sp_toplist = session.get_toplist(
            type=_TOPLIST_TYPES[variant],
            region=_TOPLIST_REGIONS[region](session))
    elif len(region) == 2:
        sp_toplist = session.get_toplist(
            type=_TOPLIST_TYPES[variant], region=region.upper())
    else:
        return []

    if session.connection.state is spotify.ConnectionState.LOGGED_IN:
        sp_toplist.load()

    if not sp_toplist.is_loaded:
        return []

    if variant == 'tracks':
        return list(translator.to_track_refs(sp_toplist.tracks))
    elif variant == 'albums':
        return list(translator.to_album_refs(sp_toplist.albums))
    elif variant == 'artists':
        return list(translator.to_artist_refs(sp_toplist.artists))
    else:
        return []
Пример #2
0
def _browse_artist(session, uri):
    sp_artist_browser = session.get_artist(uri).browse(
        type=spotify.ArtistBrowserType.NO_TRACKS)
    sp_artist_browser.load()
    top_tracks = list(translator.to_track_refs(
        sp_artist_browser.tophit_tracks))
    albums = list(translator.to_album_refs(sp_artist_browser.albums))
    return top_tracks + albums
Пример #3
0
def _browse_toplist(config, session, variant, region):
    if region == "countries":
        codes = config["toplist_countries"]
        if not codes:
            codes = countries.COUNTRIES.keys()
        return [
            models.Ref.directory(
                uri=f"spotify:top:{variant}:{code.lower()}",
                name=countries.COUNTRIES.get(code.upper(), code.upper()),
            ) for code in codes
        ]

    if region in ("country", "everywhere"):
        sp_toplist = session.get_toplist(
            type=_TOPLIST_TYPES[variant],
            region=_TOPLIST_REGIONS[region](session),
        )
    elif len(region) == 2:
        sp_toplist = session.get_toplist(type=_TOPLIST_TYPES[variant],
                                         region=region.upper())
    else:
        return []

    if session.connection.state is spotify.ConnectionState.LOGGED_IN:
        sp_toplist.load(config["timeout"])

    if not sp_toplist.is_loaded:
        return []

    if variant == "tracks":
        return list(translator.to_track_refs(sp_toplist.tracks))
    elif variant == "albums":
        return list(
            translator.to_album_refs(sp_toplist.albums,
                                     timeout=config["timeout"]))
    elif variant == "artists":
        return list(
            translator.to_artist_refs(sp_toplist.artists,
                                      timeout=config["timeout"]))
    else:
        return []