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

Commit 08e0c03

Browse files
authored
SSL Support / Air Date (#7)
1 parent 3a8437f commit 08e0c03

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

sonarr/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class Episode:
139139
identifier: str
140140
title: str
141141
overview: str
142+
airdate: str
142143
airs: datetime
143144
downloaded: bool
144145
downloading: bool
@@ -163,6 +164,7 @@ def from_dict(data: dict):
163164
identifier=identifier,
164165
title=data.get("title", ""),
165166
overview=data.get("overview", ""),
167+
airdate=data.get("airDate", ""),
166168
airs=airs,
167169
downloaded=data.get("hasFile", False),
168170
downloading=data.get("downloading", False),

sonarr/sonarr.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def __init__(
3333
port: int = 8989,
3434
request_timeout: int = 8,
3535
session: aiohttp.client.ClientSession = None,
36+
tls: bool = False,
37+
verify_ssl: bool = True,
3638
user_agent: str = None,
3739
) -> None:
3840
"""Initialize connection with receiver."""
@@ -44,6 +46,8 @@ def __init__(
4446
self.host = host
4547
self.port = port
4648
self.request_timeout = request_timeout
49+
self.tls = tls
50+
self.verify_ssl = verify_ssl
4751
self.user_agent = user_agent
4852

4953
if user_agent is None:
@@ -60,7 +64,7 @@ async def _request(
6064
params: Optional[Mapping[str, str]] = None,
6165
) -> Any:
6266
"""Handle a request to API."""
63-
scheme = "http"
67+
scheme = "https" if self.tls else "http"
6468

6569
url = URL.build(
6670
scheme=scheme, host=self.host, port=self.port, path=self.base_path
@@ -79,7 +83,12 @@ async def _request(
7983
try:
8084
with async_timeout.timeout(self.request_timeout):
8185
response = await self._session.request(
82-
method, url, data=data, params=params, headers=headers,
86+
method,
87+
url,
88+
data=data,
89+
params=params,
90+
headers=headers,
91+
ssl=self.verify_ssl,
8392
)
8493
except asyncio.TimeoutError as exception:
8594
raise SonarrConnectionError(
@@ -144,7 +153,7 @@ async def update(self, full_update: bool = False) -> Application:
144153
self._application.update_from_dict({"diskspace": diskspace})
145154
return self._application
146155

147-
async def calendar(self, start: int = None, end: int = None) -> List[Episode]:
156+
async def calendar(self, start: str = None, end: str = None) -> List[Episode]:
148157
"""Get upcoming episodes.
149158
150159
If start/end are not supplied, episodes airing

tests/test_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def test_episode() -> None:
9696
assert isinstance(episode.series, models.Series)
9797
assert episode.title == "Easy Com-mercial, Easy Go-mercial"
9898
assert episode.overview == overview.replace("\n", " ")
99+
assert episode.airdate == "2014-01-26"
99100
assert episode.airs == datetime(2014, 1, 27, 1, 30, tzinfo=timezone.utc)
100101
assert not episode.downloaded
101102
assert not episode.downloading

0 commit comments

Comments
 (0)