diff --git a/lib/ScreenShot.py b/lib/ScreenShot.py index d533409..f88628f 100644 --- a/lib/ScreenShot.py +++ b/lib/ScreenShot.py @@ -182,8 +182,8 @@ class ScreenShot: f"scale={self.WIDTH}:{self.HEIGHT}", output_file, "-y" ] - result = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - self.console.debug("result : ",result) + result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + # self.console.debug("result : ",result.stdout) # print(" ".join(cmd)) # print(result) # Draw timestamp with Pillow diff --git a/lib/torrent_creator.py b/lib/torrent_creator.py index f862db5..4099a4b 100644 --- a/lib/torrent_creator.py +++ b/lib/torrent_creator.py @@ -133,23 +133,31 @@ class qBittorrent: result.append(False) # return return all(result) - async def set_super_seed(self,rename): - async with self.session.get(f"{self.url}/api/v2/torrents/info") as torrents: - torrents = await torrents.json() - result=[] - for torrent in torrents: - if rename not in torrent['name']: - continue - # print(torrent["hash"]) + async def set_super_seed(self, rename): + for _ in range(5): + async with self.session.get(f"{self.url}/api/v2/torrents/info") as resp: + torrents = await resp.json() - async with self.session.post(f"{self.url}/api/v2/torrents/setSuperSeeding", data={"hashes": torrent["hash"],"value":True}) as response: + torrent = next((t for t in torrents if rename in t["name"]), None) + + if torrent is None: + self.console.warn(f"Not found {rename} in qBittorrent. Wait for 5 seconds") + await asyncio.sleep(5) + continue + + async with self.session.post( + f"{self.url}/api/v2/torrents/setSuperSeeding", + data={"hashes": torrent["hash"], "value": True}, + ) as response: if response.status == 200: - self.console.log("✅ Successfully stop torrent :", torrent['name']) - result.append(True) + self.console.log("✅ Successfully set super seed torrent:", torrent["name"]) + return True else: - self.console.error("❌ Failed to stop torrent :" , torrent['name']) - result.append(False) - return all(result) + self.console.error("❌ Failed to set super seed torrent:", torrent["name"]) + return False + + self.console.warn(f"Not found {rename} in qBittorrent. Super seed will not set") + return False class BearBit: """Class to interact with BearBit API""" @@ -220,13 +228,12 @@ class BearBit: if not await self.check_login(): await self.login() + # response = await self.retry(self.session.get, url, headers=headers, verify=False) url = f"{self.baseurl}/toserv.php" headers = { 'User-Agent': self.user_agent } - - # response = await self.retry(self.session.get, url, headers=headers, verify=False) async with self.session.get(url, headers=headers, verify_ssl=False) as response: # await response.text() @@ -237,6 +244,8 @@ class BearBit: soup = BeautifulSoup(text, 'html.parser') passkey_field = soup.find('input', {'name': 'passk'}) self.TRACKER_BEARBIT = passkey_field.get('value') + # return TRACKER_BEARBIT + # self.TRACKER_BEARBIT = await self.retry(get_tracker_bb) async def upload_torrent(self,name:str,sdescr:str,poster_url:str,category:str,imdburl:str,source_type:str,codec:str,standard:str,country:str,source:str,original_platform:int,tracktype:str,torrent_file_path,description:str): """Upload a torrent file to BearBit""" @@ -440,6 +449,7 @@ class BearBit: self.console.warn(f"Error: {e}. Retrying...") attempts += 1 await asyncio.sleep(delay_seconds) # If using asyncio, replace with await asyncio.sleep(delay_seconds) + self.console.error("Max retry attempts reached.") raise Exception("Max retry attempts reached.") class TorrentDD: @@ -1096,8 +1106,9 @@ class TorrentUpload(TorrentCreator): # for torrent_all in torrent.torrent_path["all"]: name = await rename(torrent.metadata[0], torrent.torrent_path["all"], is_movie,pack=pack,tmdb_response=tmdb_response_eng) await self.qbit.add_torrent(torrent.torrent_path["all"], save_path=os.path.dirname(torrent.metadata[0]['path']),category=qbit_category, rename=name) - await asyncio.sleep(1) - await self.qbit.set_super_seed(name) + # await asyncio.sleep(5) + self.console.debug(f"qBittorrent name : {name}") + await self.qbit.set_super_seed(name.strip()) await asyncio.sleep(1) # Sleep to avoid overwhelming the qBittorrent API # for i,torrent in enumerate(sorted(torrent_files['all'])): # print(f"Adding torrent for: {torrent_files['metadata'][i]['path']}")