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 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f013b96
Apply dist_thresh to Genius and Google backends
snejus Oct 12, 2024
9d72fca
Make lyrics plugin documentation slightly more clear
snejus Aug 27, 2024
75ae4b5
Centralize requests setup with requests.Session
snejus Sep 4, 2024
2f37030
Centralise request error handling
snejus Oct 13, 2024
4cb3f3c
Include class name in the log messages
snejus Sep 6, 2024
6730e04
Leave a single chef in the kitchen
snejus Sep 11, 2024
0a850ae
Do not try to strip cruft from the parsed lyrics text.
snejus Oct 19, 2024
395425a
Use a single slug implementation
snejus Sep 6, 2024
fc8a645
lyrics: Add symbols for better visual feedback in the logs
snejus Sep 19, 2024
44b040a
lyrics: Do not write item unless lyrics have changed
snejus Sep 27, 2024
1190e99
Replace custom unescape implementation by html.unescape
snejus Oct 7, 2024
fdd7fa6
Remove extract_text_between
snejus Oct 7, 2024
078953d
Genius: refactor and simplify
snejus Oct 9, 2024
0a84231
Unite Genius, Tekstowo and Google backends under the same interface
snejus Oct 13, 2024
7816ee5
Google: Refactor and improve
snejus Oct 13, 2024
5589390
Create Html class for cleaning up the html text
snejus Oct 13, 2024
98f8933
Google: prioritise Songlyrics and AZlyrics sources
snejus Oct 13, 2024
79e6a9a
Google: make sure we do not return the captcha text
snejus Oct 13, 2024
c4f6749
Remove dependency existence checks
snejus Oct 26, 2024
03eb75f
Tidy up handling of backends
snejus Oct 26, 2024
fb1870b
Append source to the lyrics
snejus Oct 19, 2024
abe98d2
Xfail Songlyrics source
snejus Oct 19, 2024
d74d7b5
Google: add support for dainuzodziai.lt
snejus Oct 26, 2024
d56cd5f
Do not search for Various Artists, split titles by ' / '
snejus Jan 19, 2025
e02260c
lyrics: normalize " & " and " and "
snejus Jan 20, 2025
07d359c
Bring back Tekstowo search
snejus Dec 15, 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
3 changes: 2 additions & 1 deletion beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
return id(self)


class AlbumInfo(AttrDict):

Check failure on line 59 in beets/autotag/hooks.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Missing type parameters for generic type "AttrDict"
"""Describes a canonical release that may be used to match a release
in the library. Consists of these data members:

Expand Down Expand Up @@ -166,7 +166,7 @@
return dupe


class TrackInfo(AttrDict):

Check failure on line 169 in beets/autotag/hooks.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Missing type parameters for generic type "AttrDict"
"""Describes a canonical track present on a release. Appears as part
of an AlbumInfo's ``tracks`` list. Consists of these data members:

Expand Down Expand Up @@ -271,7 +271,8 @@
]
# Replacements to use before testing distance.
SD_REPLACE = [
(r"&", "and"),
(r" & ", ", "),
(r" and ", ", "),
]


Expand Down Expand Up @@ -647,7 +648,7 @@
yield t


def invoke_mb(call_func: Callable, *args):

Check failure on line 651 in beets/autotag/hooks.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Missing type parameters for generic type "Callable"
try:
return call_func(*args)
except mb.MusicBrainzAPIError as exc:
Expand All @@ -661,8 +662,8 @@
artist: str,
album: str,
va_likely: bool,
extra_tags: dict,

Check failure on line 665 in beets/autotag/hooks.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Missing type parameters for generic type "dict"
) -> Iterable[tuple]:

Check failure on line 666 in beets/autotag/hooks.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Missing type parameters for generic type "tuple"
"""Search for album matches. ``items`` is a list of Item objects
that make up the album. ``artist`` and ``album`` are the respective
names (strings), which may be derived from the item list or may be
Expand Down Expand Up @@ -690,7 +691,7 @@


@plugins.notify_info_yielded("trackinfo_received")
def item_candidates(item: Item, artist: str, title: str) -> Iterable[tuple]:

Check failure on line 694 in beets/autotag/hooks.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Missing type parameters for generic type "tuple"
"""Search for item matches. ``item`` is the Item to be matched.
``artist`` and ``title`` are strings and either reflect the item or
are specified by the user.
Expand Down
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