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

Merged
merged 25 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2ff5750
Apply dist_thresh to Genius and Google backends
snejus Oct 12, 2024
c40db10
Make lyrics plugin documentation slightly more clear
snejus Aug 27, 2024
06eac79
Centralize requests setup with requests.Session
snejus Sep 4, 2024
283c513
Centralise request error handling
snejus Oct 13, 2024
cb29605
Include class name in the log messages
snejus Sep 6, 2024
7c2fb31
Leave a single chef in the kitchen
snejus Sep 11, 2024
dd9f178
Do not try to strip cruft from the parsed lyrics text.
snejus Oct 19, 2024
f94d276
Use a single slug implementation
snejus Sep 6, 2024
8bdc2c6
lyrics: Add symbols for better visual feedback in the logs
snejus Sep 19, 2024
8a1ce27
lyrics: Do not write item unless lyrics have changed
snejus Sep 27, 2024
55b7824
Replace custom unescape implementation by html.unescape
snejus Oct 7, 2024
54fc67b
Remove extract_text_between
snejus Oct 7, 2024
745c5eb
Genius: refactor and simplify
snejus Oct 9, 2024
12c5eaa
Unite Genius, Tekstowo and Google backends under the same interface
snejus Oct 13, 2024
c5c4138
Google: Refactor and improve
snejus Oct 13, 2024
7055464
Create Html class for cleaning up the html text
snejus Oct 13, 2024
07d372c
Google: prioritise Songlyrics and AZlyrics sources
snejus Oct 13, 2024
b2402b1
Google: make sure we do not return the captcha text
snejus Oct 13, 2024
04054ca
Remove dependency existence checks
snejus Oct 26, 2024
bdc564a
Tidy up handling of backends
snejus Oct 26, 2024
734bcc2
Append source to the lyrics
snejus Oct 19, 2024
858c135
Xfail Songlyrics source
snejus Oct 19, 2024
39c479f
Google: add support for dainuzodziai.lt
snejus Oct 26, 2024
7389f24
Do not search for Various Artists, split titles by ' / '
snejus Jan 19, 2025
dab9a0d
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
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, TypedDict

JSONDict = 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