- add limit ratio
- add limit ratio and super seed parameter to upload
This commit is contained in:
@@ -158,7 +158,37 @@ class qBittorrent:
|
||||
|
||||
self.console.warn(f"Not found {rename} in qBittorrent. Super seed will not set")
|
||||
return False
|
||||
|
||||
async def set_limit_ratio(self,rename,ratioLimit=-1,seedingTimeLimit=-1,inactiveSeedingTimeLimit=-1):
|
||||
for _ in range(5):
|
||||
async with self.session.get(f"{self.url}/api/v2/torrents/info") as resp:
|
||||
torrents = await resp.json()
|
||||
|
||||
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
|
||||
data = {
|
||||
'hashes': torrent["hash"],
|
||||
'ratioLimit': ratioLimit,
|
||||
'seedingTimeLimit': seedingTimeLimit,
|
||||
'inactiveSeedingTimeLimit': inactiveSeedingTimeLimit,
|
||||
}
|
||||
|
||||
|
||||
async with self.session.post(
|
||||
f"{self.url}/api/v2/torrents/setShareLimits",
|
||||
data=data,
|
||||
) as response:
|
||||
if response.status == 200:
|
||||
self.console.log("✅ Successfully set limit ratio torrent:", torrent["name"])
|
||||
return True
|
||||
else:
|
||||
self.console.error("❌ Failed to set limit ratio torrent:", torrent["name"])
|
||||
return False
|
||||
self.console.warn(f"Not found {rename} in qBittorrent. limit ratio will not set")
|
||||
return False
|
||||
class BearBit:
|
||||
"""Class to interact with BearBit API"""
|
||||
|
||||
@@ -983,7 +1013,7 @@ class TorrentUpload(TorrentCreator):
|
||||
self.dd = dd or TorrentDD(console=console)
|
||||
# self.console = console or logger(app_name="torrent_uploader",log_dir="./log")
|
||||
|
||||
async def upload_torrent(self,entry:dict,qbit_category="SeFree"):
|
||||
async def upload_torrent(self,entry:dict,qbit_category="SeFree",super_seed=False,ratioLimit=-1,seedingTimeLimit=-1,inactiveSeedingTimeLimit=-1):
|
||||
|
||||
file_path = entry['file_path']
|
||||
imdb_id = entry['imdb_id']
|
||||
@@ -1108,8 +1138,10 @@ class TorrentUpload(TorrentCreator):
|
||||
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(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
|
||||
if super_seed:
|
||||
await self.qbit.set_super_seed(name.strip())
|
||||
# await asyncio.sleep(1) # Sleep to avoid overwhelming the qBittorrent API
|
||||
await self.qbit.set_limit_ratio(name.strip(),ratioLimit=ratioLimit,seedingTimeLimit=seedingTimeLimit,inactiveSeedingTimeLimit=inactiveSeedingTimeLimit)
|
||||
# for i,torrent in enumerate(sorted(torrent_files['all'])):
|
||||
# print(f"Adding torrent for: {torrent_files['metadata'][i]['path']}")
|
||||
# qbit.add_torrent(torrent, save_path=os.path.dirname(torrent_files['metadata'][i]['path']))
|
||||
|
||||
Reference in New Issue
Block a user