Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local variable 'cfunmet' referenced before assignment #109

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 61 additions & 102 deletions qBitrr/arss.py
Original file line number Diff line number Diff line change
Expand Up @@ -4421,116 +4421,75 @@ def _process_single_torrent(self, torrent: qbittorrentapi.TorrentDictionary):

def custom_format_unmet_check(self, torrent: qbittorrentapi.TorrentDictionary) -> bool:
try:
completed = True
while completed:
completed = False
# Retry getting the queue until it succeeds
while True:
try:
queue = self.client.get_queue()
break
except (
requests.exceptions.ChunkedEncodingError,
requests.exceptions.ContentDecodingError,
requests.exceptions.ConnectionError,
JSONDecodeError,
) as e:
completed = True
if len(queue["records"]) > 0:
if self.type == "sonarr":
if not self.series_search:
entry = next(
(
record["episodeId"]
for record in queue["records"]
if record["downloadId"] == torrent.hash.upper()
),
None,
)
if not entry:
return False
customFormat = next(
(
record["customFormatScore"]
for record in queue["records"]
if record["downloadId"] == torrent.hash.upper()
),
None,
)
episode = (
self.model_file.select()
.where(self.model_file.EntryId == entry)
.first()
)
if episode.EpisodeFileId != 0:
cfunmet = customFormat < episode.CustomFormatScore
if self.force_minimum_custom_format:
cfunmet = cfunmet & customFormat < episode.MinCustomFormatScore
if cfunmet:
return True
else:
return False
else:
entry = next(
(
record["seriesId"]
for record in queue["records"]
if record["downloadId"] == torrent.hash.upper()
),
None,
)
if not entry:
return False
customFormat = next(
(
record["customFormatScore"]
for record in queue["records"]
if record["downloadId"] == torrent.hash.upper()
),
None,
)
series = (
self.model_file.select()
.where(self.model_file.EntryId == entry)
.first()
)
if self.force_minimum_custom_format:
cfunmet = customFormat < series.MinCustomFormatScore
else:
return True
if cfunmet:
return True
else:
return False
elif self.type == "radarr":
entry = next(
(
record["movieId"]
for record in queue["records"]
if record["downloadId"] == torrent.hash.upper()
),
None,
)
if not entry:
return False
customFormat = next(
(
record["customFormatScore"]
for record in queue["records"]
if record["downloadId"] == torrent.hash.upper()
),
None,
)
movie = (
self.model_file.select().where(self.model_file.EntryId == entry).first()
)
if movie.MovieFileId != 0:
cfunmet = customFormat < movie.CustomFormatScore
):
continue # Retry on exceptions

if not queue.get("records"):
return False

download_id = torrent.hash.upper()
record = next(
(r for r in queue["records"] if r.get("downloadId") == download_id),
None,
)

if not record:
return False

custom_format_score = record.get("customFormatScore")
if custom_format_score is None:
return False

# Default assumption: custom format requirements are met
cf_unmet = False

if self.type == "sonarr":
entry_id_field = "seriesId" if self.series_search else "episodeId"
file_id_field = None if self.series_search else "EpisodeFileId"
elif self.type == "radarr":
entry_id_field = "movieId"
file_id_field = "MovieFileId"
else:
return False # Unknown type

entry_id = record.get(entry_id_field)
if not entry_id:
return False

# Retrieve the model entry from the database
model_entry = (
self.model_file.select().where(self.model_file.EntryId == entry_id).first()
)
if not model_entry:
return False

if self.type == "sonarr" and self.series_search:
if self.force_minimum_custom_format:
min_score = getattr(model_entry, "MinCustomFormatScore", 0)
cf_unmet = custom_format_score < min_score
else:
file_id = getattr(model_entry, file_id_field, 0) if file_id_field else 0
if file_id != 0:
model_cf_score = getattr(model_entry, "CustomFormatScore", 0)
cf_unmet = custom_format_score < model_cf_score
if self.force_minimum_custom_format:
cfunmet = cfunmet & customFormat < movie.MinCustomFormatScore
if cfunmet:
return True
else:
return False
except KeyError:
pass
min_score = getattr(model_entry, "MinCustomFormatScore", 0)
cf_unmet = cf_unmet and custom_format_score < min_score

return cf_unmet

except Exception:
return False

def torrent_limit_check(
self, torrent: qbittorrentapi.TorrentDictionary, seeding_time_limit, ratio_limit
Expand Down
Loading