songleaf.sources¶
Where songs are found: sources, and a search that composes them.
A source is any object with a name, a
search(query, *, title, artist, lyrics, limit) -> list[Hit] method and a
get(song_id) -> Song method. search() and get_song() take
several through sources=; the default is the Kaggle chords-and-lyrics
corpus, read through sung.
A hit’s Hit.key ("<source>:<id>") names the song everywhere: it is
what get_song() resolves and what the store is keyed by.
Functions
The sources used when none are given, built once per process. |
|
|
The song named by |
|
Search every source and merge the hits, best first. |
Classes
|
One search result: a song a source can |
|
The Kaggle chords-and-lyrics corpus (~135K songs, chords over lyrics). |
|
A folder of files you exported yourself, indexed and searched by name. |
- class songleaf.sources.Hit(source, id, title, artist='', score=0.0, meta=<factory>)[source]¶
Bases:
objectOne search result: a song a source can
get().- property key: str¶
"<source>:<id>", the song’s name forget_song()and the store.
- class songleaf.sources.KaggleChordsSource(*, loader=None, min_score=70)[source]¶
Bases:
objectThe Kaggle chords-and-lyrics corpus (~135K songs, chords over lyrics).
Read through
sungfrom a local copy of the zip, with no Kaggle credentials needed when that copy exists. The corpus was scraped from a chords site: personal use only (licence taggray).Title and artist are matched fuzzily (typos, punctuation and word order do not matter); lyrics must contain every word of the
lyricsquery as a whole word. Lyrics matches are not ranked beyond popularity.- Parameters:
loader –
() -> pandas.DataFramewithcolumns. Defaults to sung’s loader of the local corpus zip.min_score (
float) – Fuzzy-match cutoff, 0-100.
- class songleaf.sources.LocalFolderSource(root=None, *, name='local_folder')[source]¶
Bases:
objectA folder of files you exported yourself, indexed and searched by name.
For files a chords/tab site lets a paying user export – Ultimate Guitar’s Guitar Pro/PDF downloads, MuseScore’s MusicXML/MSCZ/MIDI/PDF exports – with no automated route into either site (songleaf#5, songleaf#6): the user exports the file through the site as usual and drops it here. No network calls, no login; this only reads what is already on disk.
Text files (
.txt,.cho,.chopro,.crd,.pro) are parsed as chords-over-lyrics charts, the same format as the Kaggle corpus. Files with no lyrics to parse (Guitar Pro, MusicXML, MSCZ, MIDI, PDF) become aSongwith empty text and onescore_link()annotation pointing at the file, so a renderer can still show it as an attached score snippet.A file is named
"Artist - Title.ext"(the artist part is optional; a plain"Title.ext"works too).- Parameters:
>>> import tempfile, pathlib >>> root = tempfile.mkdtemp() >>> _ = (pathlib.Path(root) / "Nobody - Paper Boats.txt").write_text( ... "C\nla la la" ... ) >>> local = LocalFolderSource(root) >>> hit = local.search("paper boats")[0] >>> (hit.title, hit.artist) ('Paper Boats', 'Nobody') >>> local.get(hit.id).of_kind("chord")[0].body["symbol"] 'C'
- songleaf.sources.default_sources()[source]¶
The sources used when none are given, built once per process.
- Return type: