Rename module from lyrics-dl
to lrc-dl
This commit is contained in:
parent
4bfcbf17bd
commit
658e1bef77
16 changed files with 52 additions and 52 deletions
38
lrc_dl/core.py
Normal file
38
lrc_dl/core.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
from dataclasses import dataclass
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional, Self
|
||||
from pathlib import Path
|
||||
import mutagen
|
||||
|
||||
|
||||
@dataclass
|
||||
class Song:
|
||||
title: str
|
||||
artist: str
|
||||
album: Optional[str] = None
|
||||
duration: Optional[int] = None
|
||||
|
||||
@classmethod
|
||||
def from_file(cls, path: Path) -> Self:
|
||||
metadata = mutagen.File(path)
|
||||
|
||||
if "title" not in metadata or "artist" not in metadata:
|
||||
raise RuntimeError("Song is missing title or artist name")
|
||||
|
||||
title = ", ".join(metadata.get("title"))
|
||||
artist = ", ".join(metadata.get("artist"))
|
||||
|
||||
album = metadata.get("album")
|
||||
if album:
|
||||
album = ", ".join(album)
|
||||
|
||||
duration = metadata.info.length
|
||||
|
||||
return cls(title=title, artist=artist, album=album, duration=duration)
|
||||
|
||||
|
||||
class AbstractProvider(ABC):
|
||||
name: str = ""
|
||||
@abstractmethod
|
||||
def fetch_lyrics(self, song: Song) -> Optional[str]:
|
||||
pass
|
Loading…
Add table
Add a link
Reference in a new issue