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
70db4ee
Apply dist_thresh to Genius and Google backends
snejus Oct 12, 2024
5af8f0d
Make lyrics plugin documentation slightly more clear
snejus Aug 27, 2024
ad53e8d
Centralize requests setup with requests.Session
snejus Sep 4, 2024
16eada1
Centralise request error handling
snejus Oct 13, 2024
9a26025
Include class name in the log messages
snejus Sep 6, 2024
53b5b19
Leave a single chef in the kitchen
snejus Sep 11, 2024
aa3a1c5
Do not try to strip cruft from the parsed lyrics text.
snejus Oct 19, 2024
d3aeed2
Use a single slug implementation
snejus Sep 6, 2024
f7df3fb
lyrics: Add symbols for better visual feedback in the logs
snejus Sep 19, 2024
1b9aa3b
lyrics: Do not write item unless lyrics have changed
snejus Sep 27, 2024
4a33cc3
Replace custom unescape implementation by html.unescape
snejus Oct 7, 2024
cf2aede
Remove extract_text_between
snejus Oct 7, 2024
9ce662b
Genius: refactor and simplify
snejus Oct 9, 2024
61e4142
Unite Genius, Tekstowo and Google backends under the same interface
snejus Oct 13, 2024
99f3c67
Google: Refactor and improve
snejus Oct 13, 2024
7d35c4c
Create Html class for cleaning up the html text
snejus Oct 13, 2024
2ce3857
Google: prioritise Songlyrics and AZlyrics sources
snejus Oct 13, 2024
a36eaee
Google: make sure we do not return the captcha text
snejus Oct 13, 2024
c7d6750
Remove dependency existence checks
snejus Oct 26, 2024
db84aae
Tidy up handling of backends
snejus Oct 26, 2024
71895b2
Append source to the lyrics
snejus Oct 19, 2024
bfe4589
Xfail Songlyrics source
snejus Oct 19, 2024
ebf136f
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