Add Library
This commit is contained in:
parent
ee91e2016b
commit
a503e67c93
33
karaokatalog/Library.py
Normal file
33
karaokatalog/Library.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from typing import Self
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
from karaokatalog.Song import Song
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class Library:
|
||||||
|
songs: Sequence[Song]
|
||||||
|
unparseable_song_txts: Sequence[Path]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dir(cls, library_dir: Path) -> Self:
|
||||||
|
"""
|
||||||
|
Load a library from a directory by recursively finding all txt files in there
|
||||||
|
and interpreting them as UltraStar Song TXT files.
|
||||||
|
"""
|
||||||
|
maybe_songs_by_path = {
|
||||||
|
song_txt: Song.from_song_txt(song_txt)
|
||||||
|
for song_txt in tqdm(library_dir.rglob("*.txt"), unit=" songs")
|
||||||
|
}
|
||||||
|
|
||||||
|
songs = tuple(song for song in maybe_songs_by_path.values() if song)
|
||||||
|
unparseable_song_txts = tuple(
|
||||||
|
song_txt for song_txt, song in maybe_songs_by_path.items() if not song
|
||||||
|
)
|
||||||
|
|
||||||
|
return cls(songs, unparseable_song_txts)
|
Loading…
x
Reference in New Issue
Block a user