Debian Codegraph @

beetsplug/_typing.py

raw
1 from __future__ import annotations
2
3 from typing import Any
4
5 from typing_extensions import NotRequired, TypedDict
6
7 JSONDict = dict[str, Any]
8
9
10 class LRCLibAPI:
11 class Item(TypedDict):
12 """Lyrics data item returned by the LRCLib API."""
13
14 id: int
15 name: str
16 trackName: str
17 artistName: str
18 albumName: str
19 duration: float | None
20 instrumental: bool
21 # Both lyrics fields may be null, even when 'instrumental' is False.
22 plainLyrics: str | None
23 syncedLyrics: str | None
24
25
26 class GeniusAPI:
27 """Genius API data types.
28
29 This documents *only* the fields that are used in the plugin.
30 :attr:`SearchResult` is an exception, since I thought some of the other
31 fields might be useful in the future.
32 """
33
34 class DateComponents(TypedDict):
35 year: int
36 month: int
37 day: int
38
39 class Artist(TypedDict):
40 api_path: str
41 header_image_url: str
42 id: int
43 image_url: str
44 is_meme_verified: bool
45 is_verified: bool
46 name: str
47 url: str
48
49 class Stats(TypedDict):
50 unreviewed_annotations: int
51 hot: bool
52
53 class SearchResult(TypedDict):
54 annotation_count: int
55 api_path: str
56 artist_names: str
57 full_title: str
58 header_image_thumbnail_url: str
59 header_image_url: str
60 id: int
61 lyrics_owner_id: int
62 lyrics_state: str
63 path: str
64 primary_artist_names: str
65 pyongs_count: int | None
66 relationships_index_url: str
67 release_date_components: GeniusAPI.DateComponents
68 release_date_for_display: str
69 release_date_with_abbreviated_month_for_display: str
70 song_art_image_thumbnail_url: str
71 song_art_image_url: str
72 stats: GeniusAPI.Stats
73 title: str
74 title_with_featured: str
75 url: str
76 featured_artists: list[GeniusAPI.Artist]
77 primary_artist: GeniusAPI.Artist
78 primary_artists: list[GeniusAPI.Artist]
79
80 class SearchHit(TypedDict):
81 result: GeniusAPI.SearchResult
82
83 class SearchResponse(TypedDict):
84 hits: list[GeniusAPI.SearchHit]
85
86 class Search(TypedDict):
87 response: GeniusAPI.SearchResponse
88
89 class StatusResponse(TypedDict):
90 status: int
91 message: str
92
93 class Meta(TypedDict):
94 meta: GeniusAPI.StatusResponse
95
96 Response = Search | Meta
97
98
99 class GoogleCustomSearchAPI:
100 class Response(TypedDict):
101 """Search response from the Google Custom Search API.
102
103 If the search returns no results, the :attr:`items` field is not found.
104 """
105
106 items: NotRequired[list[GoogleCustomSearchAPI.Item]]
107
108 class Item(TypedDict):
109 """A Google Custom Search API result item.
110
111 :attr:`title` field is shown to the user in the search interface, thus
112 it gets truncated with an ellipsis for longer queries. For most
113 results, the full title is available as ``og:title`` metatag found
114 under the :attr:`pagemap` field. Note neither this metatag nor the
115 ``pagemap`` field is guaranteed to be present in the data.
116 """
117
118 title: str
119 link: str
120 pagemap: NotRequired[GoogleCustomSearchAPI.Pagemap]
121
122 class Pagemap(TypedDict):
123 """Pagemap data with a single meta tags dict in a list."""
124
125 metatags: list[JSONDict]
126
127
128 class TranslatorAPI:
129 class Language(TypedDict):
130 """Language data returned by the translator API."""
131
132 language: str
133 score: float
134
135 class Translation(TypedDict):
136 """Translation data returned by the translator API."""
137
138 text: str
139 to: str
140
141 class Response(TypedDict):
142 """Response from the translator API."""
143
144 detectedLanguage: TranslatorAPI.Language
145 translations: list[TranslatorAPI.Translation]