Types
Package-defined types.
Currently, the types defined here are only returned by
Genius.search_album(), Genius.search_artist()
and Genius.search_song().
All of the attributes listed in the types are guaranteed to be present
in the returned object. To access other values that are
in the response body, use to_dict().
Base
Base classes.
Classes
Stats of an item. |
|
docstring for Track |
- class lyricsgenius.types.Stats(json_dict)
Stats of an item.
Note
The values passed to this class are inconsistent, and therefore need to be set dynamically. Use the built-in
dir()function to see the available attributes. You could also access the stats by the dictionary annotation. For example:values = song.to_dict() print(values['stats'])
- class lyricsgenius.types.Track(client, json_dict, lyrics)
docstring for Track
- to_dict()
Converts the object to a dictionary.
- to_json(filename=None, sanitize=True, ensure_ascii=True)
Converts the object to a json string.
- Parameters:
filename (
str, optional) – Output filename, a string. If not specified, the result is returned as a string.sanitize (
bool, optional) – Sanitizes the filename if True.ensure_ascii (
bool, optional) – If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped.
- Returns:
If
filenameis None, returns the lyrics as a plain string, otherwise None.- Return type:
str|None
Warning
If you set
sanitizeto False, the file name may contain invalid characters, and therefore cause the saving to fail.
- to_text(filename=None, sanitize=True)
Converts song(s) lyrics to a single string.
- Parameters:
filename (
str, optional) – Output filename, a string. If not specified, the result is returned as a string.sanitize (
bool, optional) – Sanitizes the filename if True.
- Returns:
If
filenameis None, returns the lyrics as a plain string. Otherwise None.- Return type:
str|None
Warning
If you set
sanitizeto False, the file name may contain invalid characters, and therefore cause the saving to fail.
- save_lyrics(filename=None, extension='json', overwrite=False, ensure_ascii=True, sanitize=True, verbose=True)
Save Song(s) lyrics and metadata to a JSON or TXT file.
If the extension is ‘json’ (the default), the lyrics will be saved alongside the song’s information. Take a look at the example below.
- Parameters:
filename (
str, optional) – Output filename, a string. If not specified, the result is returned as a string.extension (
str, optional) – Format of the file (json or txt).overwrite (
bool, optional) – Overwrites preexisting file if True. Otherwise prompts user for input.ensure_ascii (
bool, optional) – If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped.sanitize (
bool, optional) – Sanitizes the filename if True.verbose (
bool, optional) – prints operation result.
Warning
If you set
sanitizeto False, the file name may contain invalid characters, and thefore cause the saving to fail.
Album
An album from Genius that has the album’s songs and their lyrics.
Attributes
Attribute |
Type |
|---|---|
_type |
|
api_path |
|
artist |
|
cover_art_thumbnail_url |
|
cover_art_url |
|
full_title |
|
id |
|
name |
|
name_with_artist |
|
release_date_components |
|
tracks |
|
url |
|
Methods
Converts the object to a dictionary. |
|
Converts the object to a json string. |
|
Converts song(s) lyrics to a single string. |
|
Save Song(s) lyrics and metadata to a JSON or TXT file. |
- class lyricsgenius.types.Album(client, json_dict, tracks)
An album from the Genius.com database.
- to_dict()
Converts the object to a dictionary.
- to_json(filename=None, sanitize=True, ensure_ascii=True)
Converts the object to a json string.
- Parameters:
filename (
str, optional) – Output filename, a string. If not specified, the result is returned as a string.sanitize (
bool, optional) – Sanitizes the filename if True.ensure_ascii (
bool, optional) – If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped.
- Returns:
If
filenameis None, returns the lyrics as a plain string, otherwise None.- Return type:
str|None
Warning
If you set
sanitizeto False, the file name may contain invalid characters, and therefore cause the saving to fail.
- to_text(filename=None, sanitize=True)
Converts song(s) lyrics to a single string.
- Parameters:
filename (
str, optional) – Output filename, a string. If not specified, the result is returned as a string.sanitize (
bool, optional) – Sanitizes the filename if True.
- Returns:
If
filenameis None, returns the lyrics as a plain string. Otherwise None.- Return type:
str|None
Warning
If you set
sanitizeto False, the file name may contain invalid characters, and therefore cause the saving to fail.
- save_lyrics(filename=None, extension='json', overwrite=False, ensure_ascii=True, sanitize=True, verbose=True)
Save Song(s) lyrics and metadata to a JSON or TXT file.
If the extension is ‘json’ (the default), the lyrics will be saved alongside the song’s information. Take a look at the example below.
- Parameters:
filename (
str, optional) – Output filename, a string. If not specified, the result is returned as a string.extension (
str, optional) – Format of the file (json or txt).overwrite (
bool, optional) – Overwrites preexisting file if True. Otherwise prompts user for input.ensure_ascii (
bool, optional) – If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped.sanitize (
bool, optional) – Sanitizes the filename if True.verbose (
bool, optional) – prints operation result.
Warning
If you set
sanitizeto False, the file name may contain invalid characters, and thefore cause the saving to fail.
Artist
The Artist object which holds the details of the artist and the Song objects of that artist.
Attributes
Attribute |
Type |
|---|---|
api_path |
|
header_image_url |
|
id |
|
image_url |
|
is_meme_verified |
|
is_verified |
|
name |
|
songs |
|
url |
|
Methods
|
|
|
|
Converts the object to a dictionary. |
|
Converts the object to a json string. |
|
Converts song(s) lyrics to a single string. |
|
Save Song(s) lyrics and metadata to a JSON or TXT file. |
- class lyricsgenius.types.Artist(client, json_dict)
An artist with songs from the Genius.com database.
- to_dict()
Converts the object to a dictionary.
- to_json(filename=None, sanitize=True, ensure_ascii=True)
Converts the object to a json string.
- Parameters:
filename (
str, optional) – Output filename, a string. If not specified, the result is returned as a string.sanitize (
bool, optional) – Sanitizes the filename if True.ensure_ascii (
bool, optional) – If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped.
- Returns:
If
filenameis None, returns the lyrics as a plain string, otherwise None.- Return type:
str|None
Warning
If you set
sanitizeto False, the file name may contain invalid characters, and therefore cause the saving to fail.
- to_text(filename=None, sanitize=True)
Converts song(s) lyrics to a single string.
- Parameters:
filename (
str, optional) – Output filename, a string. If not specified, the result is returned as a string.sanitize (
bool, optional) – Sanitizes the filename if True.
- Returns:
If
filenameis None, returns the lyrics as a plain string. Otherwise None.- Return type:
str|None
Warning
If you set
sanitizeto False, the file name may contain invalid characters, and therefore cause the saving to fail.
- save_lyrics(filename=None, extension='json', overwrite=False, ensure_ascii=True, sanitize=True, verbose=True)
Save Song(s) lyrics and metadata to a JSON or TXT file.
If the extension is ‘json’ (the default), the lyrics will be saved alongside the song’s information. Take a look at the example below.
- Parameters:
filename (
str, optional) – Output filename, a string. If not specified, the result is returned as a string.extension (
str, optional) – Format of the file (json or txt).overwrite (
bool, optional) – Overwrites preexisting file if True. Otherwise prompts user for input.ensure_ascii (
bool, optional) – If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped.sanitize (
bool, optional) – Sanitizes the filename if True.verbose (
bool, optional) – prints operation result.
Warning
If you set
sanitizeto False, the file name may contain invalid characters, and thefore cause the saving to fail.
Song
This is the Song object which holds the details of the song.
Attributes
Attribute |
Type |
|---|---|
annotation_count |
|
api_path |
|
artist |
|
full_title |
|
header_image_thumbnail_url |
|
header_image_url |
|
id |
|
lyrics |
|
lyrics_owner_id |
|
lyrics_state |
|
path |
|
primary_artist |
|
pyongs_count |
|
song_art_image_thumbnail_url |
|
song_art_image_url |
|
stats |
|
title |
|
title_with_featured |
|
url |
|
Methods
Converts the object to a dictionary. |
|
Converts the object to a json string. |
|
Converts song(s) lyrics to a single string. |
|
Save Song(s) lyrics and metadata to a JSON or TXT file. |
- class lyricsgenius.types.Song(client, json_dict, lyrics='')
A song from the Genius.com database.
- to_dict()
Converts the object to a dictionary.
- to_json(filename=None, sanitize=True, ensure_ascii=True)
Converts the object to a json string.
- Parameters:
filename (
str, optional) – Output filename, a string. If not specified, the result is returned as a string.sanitize (
bool, optional) – Sanitizes the filename if True.ensure_ascii (
bool, optional) – If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped.
- Returns:
If
filenameis None, returns the lyrics as a plain string, otherwise None.- Return type:
str|None
Warning
If you set
sanitizeto False, the file name may contain invalid characters, and therefore cause the saving to fail.
- to_text(filename=None, sanitize=True)
Converts song(s) lyrics to a single string.
- Parameters:
filename (
str, optional) – Output filename, a string. If not specified, the result is returned as a string.sanitize (
bool, optional) – Sanitizes the filename if True.
- Returns:
If
filenameis None, returns the lyrics as a plain string. Otherwise None.- Return type:
str|None
Warning
If you set
sanitizeto False, the file name may contain invalid characters, and therefore cause the saving to fail.
- save_lyrics(filename=None, extension='json', overwrite=False, ensure_ascii=True, sanitize=True, verbose=True)
Save Song(s) lyrics and metadata to a JSON or TXT file.
If the extension is ‘json’ (the default), the lyrics will be saved alongside the song’s information. Take a look at the example below.
- Parameters:
filename (
str, optional) – Output filename, a string. If not specified, the result is returned as a string.extension (
str, optional) – Format of the file (json or txt).overwrite (
bool, optional) – Overwrites preexisting file if True. Otherwise prompts user for input.ensure_ascii (
bool, optional) – If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped.sanitize (
bool, optional) – Sanitizes the filename if True.verbose (
bool, optional) – prints operation result.
Warning
If you set
sanitizeto False, the file name may contain invalid characters, and thefore cause the saving to fail.