Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

Commit 82d407a

Browse files
authored
API - Wanted (#5)
1 parent dae3489 commit 82d407a

File tree

5 files changed

+354
-67
lines changed

5 files changed

+354
-67
lines changed

sonarr/models.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,32 @@ def from_dict(data: dict):
252252
)
253253

254254

255+
@dataclass(frozen=True)
256+
class WantedResults:
257+
"""Object holding wanted episode results from Sonarr."""
258+
259+
page: int
260+
per_page: int
261+
total: int
262+
sort_key: str
263+
sort_dir: str
264+
episodes: List[Episode]
265+
266+
@staticmethod
267+
def from_dict(data: dict):
268+
"""Return WantedResults object from Sonarr API response."""
269+
episodes = [Episode.from_dict(episode) for episode in data.get("records", [])]
270+
271+
return WantedResults(
272+
page=data.get("page", 0),
273+
per_page=data.get("pageSize", 0),
274+
total=data.get("totalRecords", 0),
275+
sort_key=data.get("sortKey", ""),
276+
sort_dir=data.get("sortDirection", ""),
277+
episodes=episodes,
278+
)
279+
280+
255281
class Application:
256282
"""Object holding all information of the Sonarr Application."""
257283

sonarr/sonarr.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from .__version__ import __version__
1212
from .exceptions import SonarrAccessRestricted, SonarrConnectionError, SonarrError
13-
from .models import Application, Episode, QueueItem, SeriesItem
13+
from .models import Application, Episode, QueueItem, SeriesItem, WantedResults
1414

1515

1616
class Sonarr:
@@ -167,6 +167,25 @@ async def series(self) -> List[SeriesItem]:
167167

168168
return [SeriesItem.from_dict(result) for result in results]
169169

170+
async def wanted(
171+
self,
172+
sort_key: str = "airDateUtc",
173+
page: int = 1,
174+
page_size: int = 10,
175+
sort_dir: str = "desc",
176+
) -> WantedResults:
177+
"""Get wanted missing episodes."""
178+
params = {
179+
"sortKey": sort_key,
180+
"page": str(page),
181+
"pageSize": str(page_size),
182+
"sortDir": sort_dir,
183+
}
184+
185+
results = await self._request("wanted/missing", params=params)
186+
187+
return WantedResults.from_dict(results)
188+
170189
async def close(self) -> None:
171190
"""Close open client session."""
172191
if self._session and self._close_session:

tests/fixtures/wanted-missing.json

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
{
2+
"page": 1,
3+
"pageSize": 10,
4+
"sortKey": "airDateUtc",
5+
"sortDirection": "descending",
6+
"totalRecords": 2,
7+
"records": [
8+
{
9+
"seriesId": 3,
10+
"episodeFileId": 0,
11+
"seasonNumber": 4,
12+
"episodeNumber": 11,
13+
"title": "Easy Com-mercial, Easy Go-mercial",
14+
"airDate": "2014-01-26",
15+
"airDateUtc": "2014-01-27T01:30:00Z",
16+
"overview": "To compete with fellow \"restaurateur,\" Jimmy Pesto, and his blowout Super Bowl event, Bob is determined to create a Bob's Burgers commercial to air during the \"big game.\" In an effort to outshine Pesto, the Belchers recruit Randy, a documentarian, to assist with the filmmaking and hire on former pro football star Connie Frye to be the celebrity endorser.",
17+
"hasFile": false,
18+
"monitored": true,
19+
"sceneEpisodeNumber": 0,
20+
"sceneSeasonNumber": 0,
21+
"tvDbEpisodeId": 0,
22+
"series": {
23+
"tvdbId": 194031,
24+
"tvRageId": 24607,
25+
"imdbId": "tt1561755",
26+
"title": "Bob's Burgers",
27+
"sortTitle": "bob burgers",
28+
"cleanTitle": "bobsburgers",
29+
"seasonCount": 4,
30+
"status": "continuing",
31+
"overview": "Bob's Burgers follows a third-generation restaurateur, Bob, as he runs Bob's Burgers with the help of his wife and their three kids. Bob and his quirky family have big ideas about burgers, but fall short on service and sophistication. Despite the greasy counters, lousy location and a dearth of customers, Bob and his family are determined to make Bob's Burgers \"grand re-re-re-opening\" a success.",
32+
"airTime": "17:30",
33+
"monitored": true,
34+
"qualityProfileId": 1,
35+
"seasonFolder": true,
36+
"lastInfoSync": "2014-01-26T19:25:55.455594Z",
37+
"runtime": 30,
38+
"images": [
39+
{
40+
"coverType": "banner",
41+
"url": "http://slurm.trakt.us/images/banners/1387.6.jpg"
42+
},
43+
{
44+
"coverType": "poster",
45+
"url": "http://slurm.trakt.us/images/posters/1387.6-300.jpg"
46+
},
47+
{
48+
"coverType": "fanart",
49+
"url": "http://slurm.trakt.us/images/fanart/1387.6.jpg"
50+
}
51+
],
52+
"seriesType": "standard",
53+
"network": "FOX",
54+
"useSceneNumbering": false,
55+
"titleSlug": "bobs-burgers",
56+
"certification": "TV-14",
57+
"path": "T:\\Bob's Burgers",
58+
"year": 2011,
59+
"firstAired": "2011-01-10T01:30:00Z",
60+
"genres": [
61+
"Animation",
62+
"Comedy"
63+
],
64+
"tags": [],
65+
"added": "2011-01-26T19:25:55.455594Z",
66+
"qualityProfile": {
67+
"value": {
68+
"name": "SD",
69+
"allowed": [
70+
{
71+
"id": 1,
72+
"name": "SDTV",
73+
"weight": 1
74+
},
75+
{
76+
"id": 8,
77+
"name": "WEBDL-480p",
78+
"weight": 2
79+
},
80+
{
81+
"id": 2,
82+
"name": "DVD",
83+
"weight": 3
84+
}
85+
],
86+
"cutoff": {
87+
"id": 1,
88+
"name": "SDTV",
89+
"weight": 1
90+
},
91+
"id": 1
92+
},
93+
"isLoaded": true
94+
},
95+
"seasons": [
96+
{
97+
"seasonNumber": 4,
98+
"monitored": true
99+
},
100+
{
101+
"seasonNumber": 3,
102+
"monitored": true
103+
},
104+
{
105+
"seasonNumber": 2,
106+
"monitored": true
107+
},
108+
{
109+
"seasonNumber": 1,
110+
"monitored": true
111+
},
112+
{
113+
"seasonNumber": 0,
114+
"monitored": false
115+
}
116+
],
117+
"id": 66
118+
},
119+
"downloading": false,
120+
"id": 14402
121+
},
122+
{
123+
"seriesId": 17,
124+
"episodeFileId": 0,
125+
"seasonNumber": 1,
126+
"episodeNumber": 1,
127+
"title": "The New Housekeeper",
128+
"airDate": "1960-10-03",
129+
"airDateUtc": "1960-10-03T01:00:00Z",
130+
"overview": "Sheriff Andy Taylor and his young son Opie are in need of a new housekeeper. Andy's Aunt Bee looks like the perfect candidate and moves in, but her presence causes friction with Opie.",
131+
"hasFile": false,
132+
"monitored": true,
133+
"sceneEpisodeNumber": 0,
134+
"sceneSeasonNumber": 0,
135+
"tvDbEpisodeId": 0,
136+
"series": {
137+
"imdbId": "",
138+
"tvdbId": 77754,
139+
"tvRageId": 5574,
140+
"tvMazeId": 3853,
141+
"title": "The Andy Griffith Show",
142+
"sortTitle": "andy griffith show",
143+
"cleanTitle": "theandygriffithshow",
144+
"seasonCount": 8,
145+
"status": "ended",
146+
"overview": "Down-home humor and an endearing cast of characters helped make The Andy Griffith Show one of the most beloved comedies in the history of TV. The show centered around widower Andy Taylor, who divided his time between raising his young son Opie, and his job as sheriff of the sleepy North Carolina town, Mayberry. Andy and Opie live with Andy's Aunt Bee, who serves as a surrogate mother to both father and son. Andy's nervous cousin, Barney Fife, is his deputy sheriff whose incompetence is tolerated because Mayberry is virtually crime-free.",
147+
"airTime": "21:30",
148+
"monitored": true,
149+
"qualityProfileId": 1,
150+
"seasonFolder": true,
151+
"lastInfoSync": "2016-02-05T16:40:11.614176Z",
152+
"runtime": 25,
153+
"images": [
154+
{
155+
"coverType": "fanart",
156+
"url": "https://artworks.thetvdb.com/banners/fanart/original/77754-5.jpg"
157+
},
158+
{
159+
"coverType": "banner",
160+
"url": "https://artworks.thetvdb.com/banners/graphical/77754-g.jpg"
161+
},
162+
{
163+
"coverType": "poster",
164+
"url": "https://artworks.thetvdb.com/banners/posters/77754-4.jpg"
165+
}
166+
],
167+
"seriesType": "standard",
168+
"network": "CBS",
169+
"useSceneNumbering": false,
170+
"titleSlug": "the-andy-griffith-show",
171+
"certification": "TV-G",
172+
"path": "F:\\The Andy Griffith Show",
173+
"year": 1960,
174+
"firstAired": "1960-02-15T06:00:00Z",
175+
"genres": [
176+
"Comedy"
177+
],
178+
"tags": [],
179+
"added": "2008-02-04T13:44:24.204583Z",
180+
"qualityProfile": {
181+
"value": {
182+
"name": "SD",
183+
"allowed": [
184+
{
185+
"id": 1,
186+
"name": "SDTV",
187+
"weight": 1
188+
},
189+
{
190+
"id": 8,
191+
"name": "WEBDL-480p",
192+
"weight": 2
193+
},
194+
{
195+
"id": 2,
196+
"name": "DVD",
197+
"weight": 3
198+
}
199+
],
200+
"cutoff": {
201+
"id": 1,
202+
"name": "SDTV",
203+
"weight": 1
204+
},
205+
"id": 1
206+
},
207+
"isLoaded": true
208+
},
209+
"seasons": [
210+
{
211+
"seasonNumber": 0,
212+
"monitored": false
213+
},
214+
{
215+
"seasonNumber": 1,
216+
"monitored": false
217+
},
218+
{
219+
"seasonNumber": 2,
220+
"monitored": true
221+
},
222+
{
223+
"seasonNumber": 3,
224+
"monitored": false
225+
},
226+
{
227+
"seasonNumber": 4,
228+
"monitored": false
229+
},
230+
{
231+
"seasonNumber": 5,
232+
"monitored": true
233+
},
234+
{
235+
"seasonNumber": 6,
236+
"monitored": true
237+
},
238+
{
239+
"seasonNumber": 7,
240+
"monitored": true
241+
},
242+
{
243+
"seasonNumber": 8,
244+
"monitored": true
245+
}
246+
],
247+
"id": 17
248+
},
249+
"downloading": false,
250+
"id": 889
251+
}
252+
]
253+
}

0 commit comments

Comments
 (0)