Skip to content

Commit

Permalink
FIX: Existing series detection does not work with Sonarr v2
Browse files Browse the repository at this point in the history
VER: 1.3.2
  • Loading branch information
toddrob99 committed Oct 26, 2020
1 parent 92ae272 commit eb9a991
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion searcharr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import sonarr
import settings

__version__ = "1.3.1"
__version__ = "1.3.2"

DBPATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data")
DBFILE = "searcharr.db"
Expand Down
19 changes: 18 additions & 1 deletion sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
https://github.com/toddrob99/searcharr
"""
import requests
import time
from urllib.parse import quote

from log import set_up_logger
Expand All @@ -18,6 +19,8 @@ def __init__(self, api_url, api_key, verbose=False):
if api_url[-1] == "/":
api_url = api_url[:-1]
self.api_url = api_url + "/api/{endpoint}?apikey=" + api_key
self._all_series = {}
self.get_all_series()

def lookup_series(self, title=None, tvdb_id=None):
r = self._api_get(
Expand All @@ -42,7 +45,7 @@ def lookup_series(self, title=None, tvdb_id=None):
"seriesType": x.get("seriesType"),
"imdbId": x.get("imdbId"),
"certification": x.get("certification"),
"id": x.get("id"),
"id": x.get("id", self._series_internal_id(x.get("tvdbId"))),
"titleSlug": x.get("titleSlug"),
"cleanTitle": x.get("cleanTitle"),
"tvRageId": x.get("tvRageId"),
Expand All @@ -52,6 +55,20 @@ def lookup_series(self, title=None, tvdb_id=None):
for x in r
]

def _series_internal_id(self, tvdb_id):
return next(
(x["id"] for x in self.get_all_series() if x.get("tvdbId", 0) == tvdb_id),
None,
)

def get_all_series(self):
if int(round(self._all_series.get("ts", 0))) < int(round(time.time())) - 30:
self.logger.debug("Refreshing all series cache...")
r = self._api_get("series", {})
self._all_series.update({"series": r, "ts": time.time()})

return self._all_series["series"]

def add_series(
self,
series_info=None,
Expand Down

0 comments on commit eb9a991

Please sign in to comment.