This is a module I wrote for Python, intended to be used primarily within an interactive interpreter, which grabs and displays song lyrics from two easily parsed website databases. For lyrics in different languages, a function is provided that displays the original and translated lines side-by-side. The module itself supplies three functions, lyrics(), HTMLDecode(), and, if the translate.py file is present, translate_lyrics().
Documentation
lyrics(artist, song, source=0, output=0, intent=0)
The artist and song are strings determinging which lyrics to fetch.
The artist, song, langfrom and langto are strings determinging which lyrics to fetch and the language pair to translate between and display.
Using the mappings stored in decodedict, changes HTML encoded characters to their UTF-8 equivalents.
The artist and song are strings determinging which lyrics to fetch.
- Setting source to 1 causes the lyrics search to use LeosLyrics instead of lyrics.wikia.com, can grab the wrong song if an exact match cannot be found.
- Setting output to 1 causes status statements to print as the script runs, often good for probing why it isn't working, or seeing exactly which URL is giving it problems.
- Setting intent to 1 causes the function to return the lyrics as a list of strings, one for each line of the song.
The artist, song, langfrom and langto are strings determinging which lyrics to fetch and the language pair to translate between and display.
- Setting 'Verb' to 1 causes the artist and song strings to be taken verbatim, rather than being set to standard formatting.
- Setting source to 1 causes the lyrics search to use LeosLyrics instead of lyrics.wikia.com, can grab the wrong song if an exact match cannot be found.
- Setting output to 1 causes status statements to print as the script runs, often good for probing why it isn't working, or seeing exactly which URL is giving it problems.
Using the mappings stored in decodedict, changes HTML encoded characters to their UTF-8 equivalents.
Examples
In [1]: from lyrics import *
In [2]: lyrics('das ich', 'kokon')
kokon
Befrage dich selbst,
erforsche dein Ich.
Du kannst Licht sein
und Finsterniss.
In [3]: translate_lyrics('das ich', 'kokon', 'german', 'english')
Kokon : Cocoon
Befrage dich selbst, : Interrogate yourself,
erforsche dein Ich. : explore your self.
Du kannst Licht sein : You can be light
und Finsterniss. : and darkness.