Ejemplo n.º 1
0
def fetch(url):
    data, _ = spotify_tools.fetch(url)

    list_name = data['name']
    songs = list(map(lambda t: _map_track_url(t), data['tracks']['items']))

    return list_name, songs
    def test__fetch_album(self):
        with patch('core.spotify_tools._fetch_playlist',
                   new=(lambda u: '_fetch_playlist')), \
            patch('core.spotify_tools._fetch_album',
                  new=(lambda u: '_fetch_album')), \
            patch('core.spotify_tools._fetch_track',
                  new=(lambda u: '_fetch_track')):

            data = [[
                "https://open.spotify.com/album/1", ("_fetch_album", 'ALBUM')
            ], ["https://open.spotify.com/album/2", ("_fetch_album", 'ALBUM')]]

            for d in data:
                assert spotify_tools.fetch(d[0]) == d[1]
Ejemplo n.º 3
0
def fetch_info(url):
    cache_key = _cache_formatter.format("info", url)

    if _cache and cache_key in _cache:
        return _cache[cache_key]

    data, typ = spotify_tools.fetch(url)

    list_name = data['name']
    songs = list(
        map(lambda t: _map_track(t, list_name), data['tracks']['items']))

    image = ""
    if 'images' in data and len(data['images']) > 0:
        image = data['images'][0]['url']
    elif 'images' in data['album'] \
         and len(data['album']['images']) > 0:
        image = data['album']['images'][0]['url']

    description = ""
    if 'description' in data and len(data['description']) > 0:
        description = data['description']

    album = ""
    if 'album' in data and len(data['album']) > 0:
        album = data['album']

    artists = ""
    if 'artists' in data:
        artists = ", ".join(map(lambda a: a['name'], data['artists']))

    results = {
        'name': list_name,
        'album': album,
        'description': description,
        'type': typ,
        'tracks': songs,
        'artists': artists,
        'image': image,
        'url': url
    }

    if results:
        _cache[cache_key] = results

    return results