Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lyrics: Refactor Genius, Google backends, and consolidate common functionality #5474

Open
wants to merge 23 commits into
base: fix-lrclib-lyrics
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
17d9c7e
Apply dist_thresh to Genius and Google backends
snejus Oct 12, 2024
c183528
Make lyrics plugin documentation slightly more clear
snejus Aug 27, 2024
a03477a
Centralize requests setup with requests.Session
snejus Sep 4, 2024
c1747b0
Centralise request error handling
snejus Oct 13, 2024
fa013dd
Include class name in the log messages
snejus Sep 6, 2024
70f99fc
Leave a single chef in the kitchen
snejus Sep 11, 2024
d57fea9
Do not try to strip cruft from the parsed lyrics text.
snejus Oct 19, 2024
1e3ad06
Use a single slug implementation
snejus Sep 6, 2024
6b7acb9
lyrics: Add symbols for better visual feedback in the logs
snejus Sep 19, 2024
b915b2e
lyrics: Do not write item unless lyrics have changed
snejus Sep 27, 2024
2fa122a
Replace custom unescape implementation by html.unescape
snejus Oct 7, 2024
f1c042c
Remove extract_text_between
snejus Oct 7, 2024
d230c49
Genius: refactor and simplify
snejus Oct 9, 2024
69a4a3d
Unite Genius, Tekstowo and Google backends under the same interface
snejus Oct 13, 2024
e843078
Google: Refactor and improve
snejus Oct 13, 2024
2fdbd27
Create Html class for cleaning up the html text
snejus Oct 13, 2024
f224c4c
Google: prioritise Songlyrics and AZlyrics sources
snejus Oct 13, 2024
999766f
Google: make sure we do not return the captcha text
snejus Oct 13, 2024
ce64e3a
Remove dependency existence checks
snejus Oct 26, 2024
617a9e2
Tidy up handling of backends
snejus Oct 26, 2024
a694c2b
Append source to the lyrics
snejus Oct 19, 2024
f8d1bea
Xfail Songlyrics source
snejus Oct 19, 2024
09c0b9f
Google: add support for dainuzodziai.lt
snejus Oct 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions beetsplug/_typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
from __future__ import annotations

from typing import Any

from typing_extensions import NotRequired, TypeAlias, TypedDict

JSONDict: TypeAlias = "dict[str, Any]"


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

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


class GeniusAPI:
"""Genius API data types.

This documents *only* the fields that are used in the plugin.
:attr:`SearchResult` is an exception, since I thought some of the other
fields might be useful in the future.
"""

class DateComponents(TypedDict):
year: int
month: int
day: int

class Artist(TypedDict):
api_path: str
header_image_url: str
id: int
image_url: str
is_meme_verified: bool
is_verified: bool
name: str
url: str

class Stats(TypedDict):
unreviewed_annotations: int
hot: bool

class SearchResult(TypedDict):
annotation_count: int
api_path: str
artist_names: str
full_title: str
header_image_thumbnail_url: str
header_image_url: str
id: int
lyrics_owner_id: int
lyrics_state: str
path: str
primary_artist_names: str
pyongs_count: int | None
relationships_index_url: str
release_date_components: GeniusAPI.DateComponents
release_date_for_display: str
release_date_with_abbreviated_month_for_display: str
song_art_image_thumbnail_url: str
song_art_image_url: str
stats: GeniusAPI.Stats
title: str
title_with_featured: str
url: str
featured_artists: list[GeniusAPI.Artist]
primary_artist: GeniusAPI.Artist
primary_artists: list[GeniusAPI.Artist]

class SearchHit(TypedDict):
result: GeniusAPI.SearchResult

class SearchResponse(TypedDict):
hits: list[GeniusAPI.SearchHit]

class Search(TypedDict):
response: GeniusAPI.SearchResponse


class GoogleCustomSearchAPI:
class Response(TypedDict):
"""Search response from the Google Custom Search API.

If the search returns no results, the :attr:`items` field is not found.
"""

items: NotRequired[list[GoogleCustomSearchAPI.Item]]

class Item(TypedDict):
"""A Google Custom Search API result item.

:attr:`title` field is shown to the user in the search interface, thus
it gets truncated with an ellipsis for longer queries. For most
results, the full title is available as ``og:title`` metatag found
under the :attr:`pagemap` field. Note neither this metatag nor the
``pagemap`` field is guaranteed to be present in the data.
"""

title: str
link: str
pagemap: NotRequired[GoogleCustomSearchAPI.Pagemap]

class Pagemap(TypedDict):
"""Pagemap data with a single meta tags dict in a list."""

metatags: list[JSONDict]
Loading
Loading