How to use the lyricsgenius.song.Song function in lyricsgenius

To help you get started, we’ve selected a few lyricsgenius examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github johnwmillr / LyricsGenius / tests / test_genius.py View on Github external
def test_song(self):
        msg = "The returned object is not an instance of the Song class."
        self.assertIsInstance(self.song, Song, msg)
github johnwmillr / LyricsGenius / lyricsgenius / api.py View on Github external
# TODO: Shouldn't I use self.search_song() here?

                    # Songs must have a title
                    if 'title' not in json_song:
                        json_song['title'] = 'MISSING TITLE'

                    # Remove non-song results (e.g. Linear Notes, Tracklists, etc.)
                    song_is_valid = self._result_is_lyrics(json_song['title']) if self.skip_non_songs else True

                    if song_is_valid:
                        # Scrape song lyrics from the song's HTML
                        lyrics = self._scrape_song_lyrics_from_url(json_song['url'])

                        # Create song object for current song
                        if get_full_song_info:
                            song = Song(self.get_song(json_song['id']), lyrics)
                        else:
                            # Create song with less info (faster)
                            song = Song({'song': json_song}, lyrics)

                        # Add song to the Artist object
                        if artist.add_song(song, verbose=False) == 0:
                            n += 1
                            if self.verbose:
                                print('Song {0}: "{1}"'.format(n, song.title))

                    else:  # Song does not contain lyrics
                        if self.verbose:
                            print('"{title}" does not contain lyrics. Rejecting.'.format(title=json_song['title']))

                    # Check if user specified a max number of songs
                    if not isinstance(max_songs, type(None)):
github johnwmillr / LyricsGenius / lyricsgenius / api.py View on Github external
valid = has_title and (has_lyrics or (not self.skip_non_songs))

                # Reject non-song results (e.g. Linear Notes, Tracklists, etc.)
                if not valid:
                    if self.verbose:
                        s = song_info['title'] if has_title else "MISSING TITLE"
                        print('"{s}" is not valid. Skipping.'.format(s=s))
                    continue

                # Create the Song object from lyrics and metadata
                lyrics = self._scrape_song_lyrics_from_url(song_info['url'])
                if get_full_info:
                    info = self.get_song(song_info['id'])
                else:
                    info = {'song': song_info}
                song = Song(info, lyrics)

                # Attempt to add the Song to the Artist
                result = artist.add_song(song, verbose=False)
                if result == 0 and self.verbose:
                    print('Song {n}: "{t}"'.format(n=artist.num_songs,
                                                   t=song.title))

                # Exit search if the max number of songs has been met
                reached_max_songs = max_songs and artist.num_songs >= max_songs
                if reached_max_songs:
                    if self.verbose:
                        print('\nReached user-specified song limit ({m}).'.format(m=max_songs))
                    break

            # Move on to next page of search results
            page = songs_on_page['next_page']
github johnwmillr / LyricsGenius / lyricsgenius / api.py View on Github external
return None

        # Download full song info (an API call) unless told not to by user
        song_info = result.copy()
        if get_full_info:
            song_info.update(self.get_song(result['id'])['song'])
        lyrics = self._scrape_song_lyrics_from_url(song_info['url'])

        # Skip results when URL is a 404 or lyrics are missing
        if not lyrics:
            if self.verbose:
                print('Specified song does not have a valid URL with lyrics. Rejecting.')
            return None

        # Return a Song object with lyrics if we've made it this far
        song = Song(song_info, lyrics)
        if self.verbose:
            print('Done.')
        return song
github johnwmillr / LyricsGenius / lyricsgenius / api.py View on Github external
if (self.take_first_result or
                found_song == self._clean_str(song_title) and
                found_artist == self._clean_str(artist_name) or
                artist_name == ""):

                # Remove non-song results (e.g. Linear Notes, Tracklists, etc.)
                song_is_valid = self._result_is_lyrics(found_song) if self.skip_non_songs else True
                if song_is_valid:
                    # Found correct song, accessing API ID
                    json_song = self.get_song(search_hit['id'])

                    # Scrape the song's HTML for lyrics
                    lyrics = self._scrape_song_lyrics_from_url(json_song['song']['url'])

                    # Create the Song object
                    song = Song(json_song, lyrics)

                    if self.verbose:
                        print('Done.')
                    return song
                else:
                    if self.verbose:
                        print('Specified song does not contain lyrics. Rejecting.')
                    return None

        if self.verbose:
            print('Specified song was not first result')
        return None
github johnwmillr / LyricsGenius / lyricsgenius / api.py View on Github external
if 'title' not in json_song:
                        json_song['title'] = 'MISSING TITLE'

                    # Remove non-song results (e.g. Linear Notes, Tracklists, etc.)
                    song_is_valid = self._result_is_lyrics(json_song['title']) if self.skip_non_songs else True

                    if song_is_valid:
                        # Scrape song lyrics from the song's HTML
                        lyrics = self._scrape_song_lyrics_from_url(json_song['url'])

                        # Create song object for current song
                        if get_full_song_info:
                            song = Song(self.get_song(json_song['id']), lyrics)
                        else:
                            # Create song with less info (faster)
                            song = Song({'song': json_song}, lyrics)

                        # Add song to the Artist object
                        if artist.add_song(song, verbose=False) == 0:
                            n += 1
                            if self.verbose:
                                print('Song {0}: "{1}"'.format(n, song.title))

                    else:  # Song does not contain lyrics
                        if self.verbose:
                            print('"{title}" does not contain lyrics. Rejecting.'.format(title=json_song['title']))

                    # Check if user specified a max number of songs
                    if not isinstance(max_songs, type(None)):
                        if artist.num_songs >= max_songs:
                            keep_searching = False
                            if self.verbose:

lyricsgenius

Download lyrics and metadata from Genius.com

MIT
Latest version published 4 years ago

Package Health Score

52 / 100
Full package analysis

Similar packages