diff --git a/comet/debrid/stremthru.py b/comet/debrid/stremthru.py index c8e2a2e..a85a54e 100644 --- a/comet/debrid/stremthru.py +++ b/comet/debrid/stremthru.py @@ -184,8 +184,9 @@ async def generate_download_link( name_parsed = parse(name) target_file = None + debrid_files = magnet["data"]["files"] files = [] - for file in magnet["data"]["files"]: + for file in debrid_files: filename = file["name"] filename_parsed = parse(filename) @@ -223,6 +224,13 @@ async def generate_download_link( if len(files) > 0: asyncio.create_task(cache_availability(self.real_debrid_name, files)) + if not target_file and len(debrid_files) > 0: + files_with_link = [ + file for file in debrid_files if "link" in file and file["link"] + ] + if len(files_with_link) > 0: + target_file = max(files_with_link, key=lambda x: x["size"]) + if not target_file: return diff --git a/comet/utils/torrent.py b/comet/utils/torrent.py index 792ff52..9c2c496 100644 --- a/comet/utils/torrent.py +++ b/comet/utils/torrent.py @@ -287,11 +287,13 @@ async def _process_queue(self): await self._flush_batch() self.is_running = False - + def _reset_batches(self): for key in self.batches: if len(self.batches[key]) > 0: - logger.warning(f"Ignoring {len(self.batches[key])} items in problematic '{key}' batch") + logger.warning( + f"Ignoring {len(self.batches[key])} items in problematic '{key}' batch" + ) self.batches[key] = [] async def _flush_batch(self): @@ -327,14 +329,22 @@ async def _flush_batch(self): existing_set = { ( row["info_hash"], - row["season"] if row["season"] is not None else None, - row["episode"] if row["episode"] is not None else None, + row["season"] + if row["season"] is not None + else None, + row["episode"] + if row["episode"] is not None + else None, ) for row in existing_rows } for item in sub_batch: - key = (item["info_hash"], item["season"], item["episode"]) + key = ( + item["info_hash"], + item["season"], + item["episode"], + ) if key in existing_set: self.batches["updates"].append(item["params"]) else: