Rename module from lyrics-dl to lrc-dl

This commit is contained in:
mrsobakin 2024-11-11 05:25:48 +03:00
parent 4bfcbf17bd
commit 658e1bef77
No known key found for this signature in database
GPG key ID: 325CBF665E4FFD6E
16 changed files with 52 additions and 52 deletions

38
lrc_dl/core.py Normal file
View 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