johnwmillr / LyricsGenius

Download song lyrics and metadata from Genius.com 🎶🎤
http://www.johnwmillr.com/scraping-genius-lyrics/
MIT License
892 stars 158 forks source link

Descending order #152

Closed NIkitabala closed 3 years ago

NIkitabala commented 4 years ago

Is there any way to sort in a descending order?

I have

artist = genius.search_artist("Пошлая Молли", max_songs=9, sort="popularity")

But I want to make it in a descending order, so it will be like less popular ones first.

allerter commented 4 years ago

Genius.com doesn't offer to sort by least popularity. Using the library's search_artist() is slow because it attempts to fetch the lyrics and song information. The library doesn't also offer to go through an artist's songs without getting their information yet. But you could do it yourself.

genius = Genius(token)

artist = genius.search_artist('Andy Shauf', max_songs=1)
page = 1
songs = []
while page:
    request = genius.get_artist_songs(artist._id, sort='popularity', per_page=50, page=page)
    songs.extend(request['songs'])
    page = request['next_page']
least_popular_song = genius.search_song(songs[-1]['title'], artist.name)
print(least_popular_song.lyrics)
for song in reversed(songs):
    print(song['title']