Git Product home page Git Product logo

wrap-genius's Introduction

wrap-genius

Version Quality Gate Status CodeCoverage

Unofficial python wrapper for genius.com's API

Setup

wrap-genius is supported on Python 3.8+ and it can be installed using pip.

pip install wrap-genius

To be able to use it, you'll need to create an API client for genius.com and get a CLIENT ACCESS TOKEN.

Quickstart

The genius wrapper library provides a convenient interface to interact with the Genius API, allowing you to search for songs, artists, and retrieve information about them. This documentation will guide you through the available functionalities of the library with examples.

Initialization

To start using the genius wrapper library, you need to initialize an instance of the Genius class. This requires an access token, which you can obtain from the Genius API.

from genius import Genius

g = Genius(access_token="YOUR_ACCESS_TOKEN")

Search All

You can use the search_all method to search for songs or artists. It returns a generator that yields search results. Here are some examples:

# Search for an artist
songs = g.search_all("Dua Lipa", page_limit=1) # page_limit is 10 by default, use conservatively if not needed
print(next(songs).title)  # Get the first song
print([song.title for song in songs])  # Get the rest of the songs

# Search for a song
songs = g.search_all("My Iron Lung", page_limit=1)
print(next(songs).title)

# Search for a song by an artist
songs = g.search_all("White Light Gorillaz", page_limit=1)
print(next(songs).title)

Output:

New Rules
['Scared to Be Lonely', 'Don’t Start Now', 'IDGAF', 'Levitating', 'One Kiss', 'Blow Your Mind (Mwah)', 'Break My Heart', 'Be the One', 'Kiss and Make Up', 'Physical', 'Levitating (Remix)', 'UN DÍA (ONE DAY)', 'Electricity', 'We’re Good', 'Homesick', 'Dua Lipa', 'Love Again', 'Dua Lipa & BLACKPINK - Kiss and Make Up (Romanized)', 'Hotter Than Hell']

My Iron Lung

White Light

Search Artist

You can use the search_artist method to search for an artist by their name. It returns an Artist object representing the artist. Here is an example:

artist = g.search_artist("Radiohead")
print(artist)  # Artist object
print(artist.alternate_names)
print(artist.followers_count)
print(artist.description[:100] + "..." if len(artist.description) > 100 else artist.description)
print(artist.header_image_url)
print(artist.id)
print(artist.name)
print(artist.is_verified)
print(list(itertools.islice(artist.songs, 5)))
print(list(itertools.islice(artist.songs_by_popularity, 5)))
print(artist.url)

Search Song

You can use the search_all method to search for a specific song. It returns a generator that yields song objects. Here is an example:

songs = g.search_all("Karma Police Radiohead", page_limit=1)
song = next(songs)
print(song)  # Song object
print(song.album)
print(song.artist)
print(song.pageviews)
print(song.song_art_image_url)
print(song.title)
print(song.title_with_featured)
print(song.hot)
print(song.description)
print(song.recording_location)
print(song.release_date)
print(song.release_date_for_display)
print(song.features)
print(song.media)
print(song.writers)
print(song.producers)
print(song.samples)
print(song.sampled_in)
print(song.interpolates)
print(song.interpolated_by)
print(song.is_cover)
print(song.is_live)
print(song.is_remix)
print(song.cover_of)
print(song.covered_by)
print(song.remix_of)
print(song.remixed_by)
print(song.live_version_of)
print(song.performed_live_as)
print("\n".join(song.lyrics))

Get Artist Information

You can use the get_artist method to retrieve detailed information about an artist by their ID. Here is an example:

artist = g.get_artist(604)
print(artist)  # Artist object

Get Song Information

You can use the get_song method to retrieve detailed information about a song by its ID. Here is an example:

song = g.get_song(378195)
print(song)  # Song object

Get Album Information

You can use the get_all_album_songs method to retrieve information about an album by the artist's ID. Here is an example:

song=g.get_song(378195)
album = song.album
print(album.name)
print(album.artist)
print(album.cover_art_url)
print(album.id)
print(album.url)
print(list(album.songs))

wrap-genius's People

Contributors

dependabot[bot] avatar fedecalendino avatar highnessatharva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

highnessatharva

wrap-genius's Issues

Requests fail

I just noticed that any request seems to fail. I tried the example in the readme, and I always get the same exception: requests.exceptions.JSONDecodeError: [Errno Expecting value]. Full traceback here : traceback.txt.

Lyrics are not full

Hi, me again!

Today I started reading the lyrics of some songs I tagged with wrap-genius, and noticed that the lyrics are never full. I tried finding lyrics for a few different songs, and although I didn't see any pattern, there is always the end of the lyrics missing (like a few dozen percents). I wonder if you have the same issue.

Exemple with this song:

Lyrics on Genius:

[Verse 1]
I keep going back to when I laid eyes on you
'Cause ever since then you've been on my mind
You gave me that look and suddenly I felt new
Now I'm watching my phone late in to the night

[Pre-Chorus]
But it's been days, I hate to wait
I guess that we're both too shy to call up
I wish you would speak your mind
And tell me that you also want me closer
'Cause baby, when I think about you, I come alive

[Chorus 1]
You should come over
Let me get to know you
I'm picturing you when the light hits your face in the morning
Yeah, I need to know you
You should come over

[Verse 2]
There's not a moment I don't want to talk to ya
There's so many things that I wanna know
Like your favourite place, your favourite song
And all of the secrets that nobody knows
Let it all be uncovered

[Pre-Chorus]
So tell me why we're wasting time
We both know we want to get in closer
’Cause baby, when I think about you, I come alive

[Chorus 1]
You should come over
Let me get to know you
I'm picturing you when the light hits your face in the morning
Yeah, I need to know you
You should come over

[Chorus 2]
You should come over
Stay as long as you wanna
With the sun on your skin as I'm taking you in for a moment
Yeah I need to know you
You should come over

[Bridge]
I know we got busy schedules
I know we got busy minds
So why don't we just ease each other?
Get lost in me, I'll get lost in you
'Cause baby, when I think about you, I come alive

[Chorus 2]
You should come over
Stay as long as you wanna
With the sun on your skin as I'm taking you in for a moment
Yeah, I need to know you
You should come over
You should come over
Stay as long as you wanna
With the sun on your skin as I'm taking you in for a moment
Yeah, I need to know you
You should come over

Lyrics I get:

[Verse 1]
I keep going back to when I laid eyes on you
'Cause ever since then you've been on my mind
You gave me that look and suddenly I felt new
Now I'm watching my phone late in to the night

[Pre-Chorus]
But it's been days, I hate to wait
I guess that we're both too shy to call up
I wish you would speak your mind
And tell me that you also want me closer
'Cause baby, when I think about you, I come alive

[Chorus 1]
You should come over
Let me get to know you
I'm picturing you when the light hits your face in the morning
Yeah, I need to know you
You should come over

[Verse 2]
There's not a moment I don't want to talk to ya
There's so many things that I wanna know
Like your favourite place, your favourite song
And all of the secrets that nobody knows
Let it all be uncovered

[Pre-Chorus]
So tell me why we're wasting time
We both know we want to get in closer
’Cause baby, when I think about you, I come alive

[Chorus 1]
You should come over
Let me get to know you
I'm picturing you when the light hits your face in the morning
Yeah, I need to know you
You should come over

Lyrics are not entirely fetched

Hi again!

Small issue I've just encountered while fetching lyrics. For this song, the lyrics are not entirely fetched. They stop at the double new line after French Montana's part.

Test code:

from genius import Genius
g = Genius(access_token="TOKEN")
song = g.get_song(song_id=2127949)
print(song.lyrics)

Result:

['Much as you blame yourself', "You can't be blamed for the way that you feel", 'Had no example of a love', 'That was even remotely real', 'How can you understand', 'Something that you never had?', 'Ooh, baby, if you let me', 'I can help you out with all of that', 'Girl, let me love you', 'And I will love you', 'Until you learn to love yourself', 'Girl, let me love you', 'I know your trouble', "Don't be afraid", 'Girl, let me help', 'Girl, let me love you', 'And I will love you', 'Until you learn to love yourself', 'Girl, let me love you', 'A heart in numbness', 'Is brought to life', "I'll take you there", 'Hey, hey', '(Girl, let me love you)', 'Girl, let me love you, baby, oh', '(Girl, let me love you)', 'Girl, let me love you, baby', '(Girl, let me love you)', 'Let me love you', 'Let me love you', 'Oh', 'Ooh', '[French Montana:]', 'Let me love you, I promise', 'We push that drop right through currents', "And when I'm stressed with them problems", "I'm blowing stacks up and honest", "I'm talking, sipping, syrup, double cup", "We was down, now we're up", "When you're down, I'll pick you up", 'Massi, Lago, Lambo, truck', 'Highs with the lows, getting high in a row', 'On the couches spinning rows', 'Let me love you, fuck them hoes!', "I got it all here, don't cheat yourself", "You don't owe me, man you owe yourself", "Put your guards down, I'd love to help", "But you can't love me till you love yourself", "Ah, she's fisty with it", 'Trying to keep me in check like Nike with it', 'Cause her last boyfriend was shasty with her', "Rich and famous, life we're living", 'Them long flights, them long nights', 'Them short days, that Porsche white', 'Cop two for you, cop two for me', 'Promise will be for life', '', '']

Lyrics parser cuts lines around annotations

Hi, now that I'm using your project to get lyrics, I noticed some strange behaviour.

Lines are cut around Genius' annotations, when of course they souldn't.

For instance, with this song, which contains an annotation on Gemini and on straight to 42nd:

Lyrics on Genius:

Village is dead
Gemini panic
Quick out of bed

Lyrics parsed:

'Village is dead', 'Gemini', ' panic', 'Quick out of bed'

Lyrics on Genius:

Land at 11, straight to 42nd, it's colder

Lyrics parsed:

'Land at 11, ', 'straight to 42nd', ", it's colder"

I noticed that it happens around each Genius' annotation, and so far only there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.