Skip to content

Commit

Permalink
lyrics: define LRCLibItem in lyrics/types.py
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Oct 1, 2024
1 parent f0ee0a1 commit 9399f66
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
11 changes: 4 additions & 7 deletions beetsplug/lyrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
from urllib.parse import urlparse

import requests
from typing_extensions import TypeAlias
from unidecode import unidecode

import beets
from beets import plugins, ui
from beets.autotag.hooks import string_dist

from .types import LRCLibItem

if TYPE_CHECKING:
from beets.library import Item

Expand Down Expand Up @@ -286,10 +287,6 @@ def fetch(
raise NotImplementedError


Candidate: TypeAlias = "dict[str, Any]"
Candidates: TypeAlias = "list[Candidate]"


@dataclass
@total_ordering
class LRCLyrics:
Expand All @@ -309,7 +306,7 @@ def __le__(self, other: LRCLyrics) -> bool:
return self.dist < other.dist

@classmethod
def make(cls, candidate: Candidate, target_duration: float) -> LRCLyrics:
def make(cls, candidate: LRCLibItem, target_duration: float) -> LRCLyrics:
return cls(
target_duration,
candidate["duration"],
Expand Down Expand Up @@ -363,7 +360,7 @@ class LRCLib(Backend):

def fetch_candidates(
self, artist: str, title: str, album: str
) -> Iterator[Candidates]:
) -> Iterator[list[LRCLibItem]]:
"""Yield lyrics candidates for the given song data.
Firstly, attempt to GET lyrics directly, and then search the API if
Expand Down
17 changes: 17 additions & 0 deletions beetsplug/lyrics/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from __future__ import annotations

from typing_extensions import TypedDict


class LRCLibItem(TypedDict):
"""Lyrics data item returned by the LRCLib API."""

id: int
name: str
trackName: str
artistName: str
albumName: str
duration: float
instrumental: bool
plainLyrics: str
syncedLyrics: str | None

0 comments on commit 9399f66

Please sign in to comment.