Skip to content

Commit

Permalink
Testing of handling failed season torrent to trigger series search in…
Browse files Browse the repository at this point in the history
…stead of episode search
  • Loading branch information
Feramance committed Jan 9, 2024
1 parent d6ef399 commit 112960e
Showing 1 changed file with 71 additions and 10 deletions.
81 changes: 71 additions & 10 deletions qBitrr/arss.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,12 +809,13 @@ def _process_failed_individual(self, hash_: str, entry: int, skip_blacklist: set
if self.re_search and object_id:
if self.type == "sonarr":
object_ids = object_id
for object_id in object_ids:
if self.series_search:
completed = True
while completed:
try:
completed = False
data = self.client.get_episode_by_episode_id(object_id)
episode = self.client.get_episode_by_episode_id(object_id[0])
data = self.client.get_series(episode["seriesId"])
name = data.get("title")
series_id = data.get("series", {}).get("id")
if name:
Expand All @@ -837,12 +838,12 @@ def _process_failed_individual(self, hash_: str, entry: int, skip_blacklist: set
absoluteEpisodeNumber,
name,
tvdbId,
object_id,
episode["id"],
)
else:
self.logger.notice(
"Re-Searching episode: %s",
object_id,
episode["id"],
)
except (
requests.exceptions.ChunkedEncodingError,
Expand All @@ -852,13 +853,15 @@ def _process_failed_individual(self, hash_: str, entry: int, skip_blacklist: set
):
completed = True

if object_id in self.queue_file_ids:
self.queue_file_ids.remove(object_id)
if episode["id"] in self.queue_file_ids:
self.queue_file_ids.remove(episode["id"])
completed = True
while completed:
try:
completed = False
self.client.post_command("EpisodeSearch", episodeIds=[object_id])
self.client.post_command(
self.search_api_command, seriesId=[data["id"]]
)
except (
requests.exceptions.ChunkedEncodingError,
requests.exceptions.ContentDecodingError,
Expand All @@ -867,6 +870,65 @@ def _process_failed_individual(self, hash_: str, entry: int, skip_blacklist: set
completed = True
if self.persistent_queue and series_id:
self.persistent_queue.insert(EntryId=series_id).on_conflict_ignore()
else:
for object_id in object_ids:
completed = True
while completed:
try:
completed = False
data = self.client.get_episode_by_episode_id(object_id)
name = data.get("title")
series_id = data.get("series", {}).get("id")
if name:
episodeNumber = data.get("episodeNumber", 0)
absoluteEpisodeNumber = data.get("absoluteEpisodeNumber", 0)
seasonNumber = data.get("seasonNumber", 0)
seriesTitle = data.get("series", {}).get("title")
year = data.get("series", {}).get("year", 0)
tvdbId = data.get("series", {}).get("tvdbId", 0)
self.logger.notice(
"Re-Searching episode: %s (%s) | "
"S%02dE%03d "
"(E%04d) | "
"%s | "
"[tvdbId=%s|id=%s]",
seriesTitle,
year,
seasonNumber,
episodeNumber,
absoluteEpisodeNumber,
name,
tvdbId,
object_id,
)
else:
self.logger.notice(
"Re-Searching episode: %s",
object_id,
)
except (
requests.exceptions.ChunkedEncodingError,
requests.exceptions.ContentDecodingError,
requests.exceptions.ConnectionError,
AttributeError,
):
completed = True

if object_id in self.queue_file_ids:
self.queue_file_ids.remove(object_id)
completed = True
while completed:
try:
completed = False
self.client.post_command("EpisodeSearch", episodeIds=[object_id])
except (
requests.exceptions.ChunkedEncodingError,
requests.exceptions.ContentDecodingError,
requests.exceptions.ConnectionError,
):
completed = True
if self.persistent_queue and series_id:
self.persistent_queue.insert(EntryId=series_id).on_conflict_ignore()
elif self.type == "radarr":
completed = True
while completed:
Expand Down Expand Up @@ -3162,7 +3224,7 @@ def _process_single_torrent_unprocessed(self, torrent: qbittorrentapi.TorrentDic
def _get_torrent_important_trackers(
self, torrent: qbittorrentapi.TorrentDictionary
) -> tuple[set[str], set[str]]:
current_trackers = {i.url for i in torrent.trackers}
current_trackers = {i.url for i in torrent.trackers if hasattr(i, "url")}
monitored_trackers = self._monitored_tracker_urls.intersection(current_trackers)
need_to_be_added = self._add_trackers_if_missing.difference(current_trackers)
monitored_trackers = monitored_trackers.union(need_to_be_added)
Expand Down Expand Up @@ -3430,8 +3492,7 @@ def _process_single_torrent_trackers(self, torrent: qbittorrentapi.TorrentDictio
def _process_single_torrent(self, torrent: qbittorrentapi.TorrentDictionary):
if torrent.category != RECHECK_CATEGORY:
self.manager.qbit_manager.cache[torrent.hash] = torrent.category
if hasattr(torrent, "Tracker"):
self._process_single_torrent_trackers(torrent)
self._process_single_torrent_trackers(torrent)
self.manager.qbit_manager.name_cache[torrent.hash] = torrent.name
time_now = time.time()
try:
Expand Down

0 comments on commit 112960e

Please sign in to comment.