Skip to content

Commit

Permalink
Fixes for Jackett support (#8711)
Browse files Browse the repository at this point in the history
* Perform santity check on response.next.url

* Pass provider and url to the SearchResult constructor since these values are needed by is_torrent

* Update constructor when creating class from JSON

* Fix issue reported by BKSteve

---------

Co-authored-by: BKSteve <[email protected]>
Co-authored-by: miigotu <[email protected]>
  • Loading branch information
3 people authored Feb 12, 2024
1 parent 5379d52 commit 053d0e6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
28 changes: 15 additions & 13 deletions sickchill/oldbeard/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class SearchResult(object):
Represents a search result from an indexer.
"""

def __init__(self, episodes):
self.provider: Union["GenericProvider", None] = None
def __init__(self, episodes, provider=None, url=""):
self.provider: Union["GenericProvider", None] = provider

# release show object
self.show: Union["TVShow", None] = None

# URL to the NZB/torrent file
self.url: str = ""
self.url: str = url

# used by some providers to store extra info associated with the result
self.extraInfo = []
Expand Down Expand Up @@ -62,12 +62,10 @@ def __init__(self, episodes):

def from_json(self, result_dict):
self.name = result_dict.get("name")
self.url = result_dict.get("url")
self.size = result_dict.get("size")
self.version = result_dict.get("version")
self.release_group = result_dict.get("release_group")
self.quality = int(result_dict.get("quality"))
self.provider = sickchill.oldbeard.providers.getProviderClass(result_dict.get("provider"))

@classmethod
def make_result(cls, result_dict):
Expand All @@ -76,8 +74,12 @@ def make_result(cls, result_dict):
return show[0]

show = show[1]

episode_objects = [show.get_episode(result_dict.get("season"), ep) for ep in result_dict.get("episodes").split("|") if ep]
result = cls(episode_objects)
provider = sickchill.oldbeard.providers.getProviderClass(result_dict.get("provider"))
url = result_dict.get("url")
result = cls(episode_objects, provider, url)

result.from_json(result_dict)
result.show = show

Expand All @@ -86,7 +88,7 @@ def make_result(cls, result_dict):
def __check_url(self):
if not self.__checked_url and self.url and "jackett_apikey" in self.url:
response = self.provider.get_url(self.url, allow_redirects=False, returns="response")
if response.next and response.next.url and response.next.url.startswith("magnet:") and re.search(r"urn:btih:(\w{32,40})", self.url):
if response.next and response.next.url and response.next.url.startswith("magnet:") and re.search(r"urn:btih:(\w{32,40})", response.next.url):
self.url = response.next.url
self.__checked_url = True

Expand Down Expand Up @@ -142,8 +144,8 @@ class NZBSearchResult(SearchResult):
Regular NZB result with a URL to the NZB
"""

def __init__(self, episodes):
super().__init__(episodes)
def __init__(self, episodes, provider, url):
super().__init__(episodes, provider, url)
self.result_type = "nzb"


Expand All @@ -152,8 +154,8 @@ class NZBDataSearchResult(SearchResult):
NZB result where the actual NZB XML data is stored in the extraInfo
"""

def __init__(self, episodes):
super().__init__(episodes)
def __init__(self, episodes, provider, url):
super().__init__(episodes, provider, url)
self.result_type = "nzbdata"


Expand All @@ -162,8 +164,8 @@ class TorrentSearchResult(SearchResult):
Torrent result with a URL to the torrent
"""

def __init__(self, episodes):
super().__init__(episodes)
def __init__(self, episodes, provider, url):
super().__init__(episodes, provider, url)
self.result_type = "torrent"


Expand Down
3 changes: 1 addition & 2 deletions sickchill/oldbeard/properFinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,8 @@ def _download_propers(self, proper_list):
episode_object = proper.show.get_episode(proper.season, proper.episode)

# make the result object
result = proper.provider.get_result([episode_object])
result = proper.provider.get_result([episode_object], proper.url)
result.show = proper.show
result.url = proper.url
result.name = proper.name
result.quality = proper.quality
result.release_group = proper.release_group
Expand Down
3 changes: 1 addition & 2 deletions sickchill/oldbeard/tvcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,8 @@ def find_needed_episodes(self, episode, manual_search=False, down_cur_quality=Fa

logger.info("Found result " + title + " at " + url)

result = self.provider.get_result([episode_object])
result = self.provider.get_result([episode_object], url)
result.show = show_obj
result.url = url
result.name = title
result.quality = cur_quality
result.release_group = cur_release_group
Expand Down
14 changes: 5 additions & 9 deletions sickchill/providers/GenericProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,8 @@ def find_search_results(self, show, episodes, search_mode, manual_search=False,
for current_episode in actual_episodes:
episode_objects.append(show_object.get_episode(actual_season, current_episode))

result = self.get_result(episode_objects)
result = self.get_result(episode_objects, url)
result.show = show_object
result.url = url
result.name = title
result.quality = quality
result.release_group = release_group
Expand Down Expand Up @@ -338,11 +337,8 @@ def get_quality(self, item, anime=False):

return quality

def get_result(self, episodes):
result = self._get_result(episodes)
result.provider = self

return result
def get_result(self, episodes, url):
return self._get_result(episodes, self, url)

# noinspection PyUnusedLocal
@staticmethod
Expand Down Expand Up @@ -413,8 +409,8 @@ def login(self):
def search(self, strings):
return []

def _get_result(self, episodes):
return SearchResult(episodes)
def _get_result(self, episodes, provider, url):
return SearchResult(episodes, provider, url)

def get_episode_search_strings(self, episode: "TVEpisode", add_string: str = "") -> Union[List[Dict], Iterable]:
if not episode:
Expand Down
4 changes: 2 additions & 2 deletions sickchill/providers/nzb/NZBProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def __init__(self, name):
def is_active(self):
return bool(settings.USE_NZBS) and self.is_enabled

def _get_result(self, episodes):
result = NZBSearchResult(episodes)
def _get_result(self, episodes, provider, url):
result = NZBSearchResult(episodes, provider, url)
if result.is_torrent:
result.result_type = GenericProvider.TORRENT

Expand Down
4 changes: 2 additions & 2 deletions sickchill/providers/torrent/TorrentProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def _custom_trackers(self):

return "&tr=" + "&tr=".join({x.strip() for x in settings.TRACKERS_LIST.split(",") if x.strip()})

def _get_result(self, episodes):
return TorrentSearchResult(episodes)
def _get_result(self, episodes, provider, url):
return TorrentSearchResult(episodes, provider, url)

def _get_size(self, item):
if isinstance(item, dict):
Expand Down

0 comments on commit 053d0e6

Please sign in to comment.