Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import aiohttp
- import asyncio
- from genius_key2 import HEADERS
- import requests
- def make_query(album_id):
- return {"id": album_id}
- def print_songs(album, album_name):
- print(album_name, ":")
- print()
- song_list = album["album_appearances"]
- for song in song_list:
- print(song["song"]["full_title"])
- print()
- print("-------")
- print()
- async def get_songs(album_ids_and_names):
- async with aiohttp.ClientSession() as session:
- URL = "https://genius-song-lyrics1.p.rapidapi.com/album/appearances/"
- tasks = [
- session.get(URL, headers=HEADERS, params=make_query(album_id))
- for album_id, album_name in album_ids_and_names
- ]
- album_appearances = []
- responses = await asyncio.gather(*tasks)
- for response in responses:
- album_appearances.append(await response.json())
- for it, album in enumerate(album_appearances):
- print_songs(album, album_ids_and_names[it][1])
- def get_albums(URL, querystring):
- response = requests.get(URL, headers=HEADERS, params=querystring)
- albums = response.json()["albums"]
- album_ids_and_names = [
- (album["api_path"].split("/")[2], album["full_title"]) for album in albums
- ]
- asyncio.run(get_songs(album_ids_and_names))
- if __name__ == "__main__":
- URL = "https://genius-song-lyrics1.p.rapidapi.com/artist/albums/"
- querystring = {"id": "1177", "per_page": "20", "page": "1"}
- get_albums(URL, querystring)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement