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 24 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
24 commits
Select commit Hold shift + click to select a range
62238b1
Apply dist_thresh to Genius and Google backends
snejus Oct 12, 2024
680238a
Make lyrics plugin documentation slightly more clear
snejus Aug 27, 2024
fb46f39
Centralize requests setup with requests.Session
snejus Sep 4, 2024
7e7cd21
Centralise request error handling
snejus Oct 13, 2024
2abafa6
Include class name in the log messages
snejus Sep 6, 2024
abb442c
Leave a single chef in the kitchen
snejus Sep 11, 2024
70e3659
Do not try to strip cruft from the parsed lyrics text.
snejus Oct 19, 2024
81f7047
Use a single slug implementation
snejus Sep 6, 2024
40a57c2
lyrics: Add symbols for better visual feedback in the logs
snejus Sep 19, 2024
dfeb9a2
lyrics: Do not write item unless lyrics have changed
snejus Sep 27, 2024
6cdf70f
Replace custom unescape implementation by html.unescape
snejus Oct 7, 2024
9276301
Remove extract_text_between
snejus Oct 7, 2024
52feedf
Genius: refactor and simplify
snejus Oct 9, 2024
5d80ca6
Unite Genius, Tekstowo and Google backends under the same interface
snejus Oct 13, 2024
18f286f
Google: Refactor and improve
snejus Oct 13, 2024
a7873ba
Create Html class for cleaning up the html text
snejus Oct 13, 2024
ab838aa
Google: prioritise Songlyrics and AZlyrics sources
snejus Oct 13, 2024
cb197bb
Google: make sure we do not return the captcha text
snejus Oct 13, 2024
0ff20e7
Remove dependency existence checks
snejus Oct 26, 2024
1476a67
Tidy up handling of backends
snejus Oct 26, 2024
cbe9519
Append source to the lyrics
snejus Oct 19, 2024
8d829fc
Xfail Songlyrics source
snejus Oct 19, 2024
bcf7465
Google: add support for dainuzodziai.lt
snejus Oct 26, 2024
730cb8f
Do not search for Various Artists, split titles by ' / '
snejus Jan 19, 2025
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