Skip to content

Commit

Permalink
Add more debugging for qbit torrent storage directory
Browse files Browse the repository at this point in the history
Should help with #13
  • Loading branch information
Audionut committed Aug 25, 2024
1 parent 0e79eb2 commit bc940fd
Showing 1 changed file with 10 additions and 31 deletions.
41 changes: 10 additions & 31 deletions src/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
import ssl
import shutil
import time


from src.console import console



class Clients():
"""
Add to torrent client
Expand All @@ -26,7 +22,6 @@ def __init__(self, config):
self.config = config
pass


async def add_to_client(self, meta, tracker):
torrent_path = f"{meta['base_dir']}/tmp/{meta['uuid']}/[{tracker}]{meta['clean_name']}.torrent"
if meta.get('no_seed', False) == True:
Expand Down Expand Up @@ -63,8 +58,6 @@ async def add_to_client(self, meta, tracker):
shutil.copy(torrent_path, client['watch_folder'])
return



async def find_existing_torrent(self, meta):
if meta.get('client', None) == None:
default_torrent_client = self.config['DEFAULT']['default_torrent_client']
Expand Down Expand Up @@ -103,7 +96,6 @@ async def find_existing_torrent(self, meta):

return None


async def is_valid_torrent(self, meta, torrent_path, torrenthash, torrent_client, print_err=False):
valid = False
wrong_file = False
Expand Down Expand Up @@ -165,10 +157,14 @@ async def is_valid_torrent(self, meta, torrent_path, torrenthash, torrent_client
console.print(err_print)
return valid, torrent_path


async def search_qbit_for_torrent(self, meta, client):
console.print("[green]Searching qbittorrent for an existing .torrent")
torrent_storage_dir = client.get('torrent_storage_dir', None)
if meta['debug']:
if torrent_storage_dir:
print(f"Torrent storage directory found: {torrent_storage_dir}")
else:
print("No torrent storage directory found.")
if torrent_storage_dir == None and client.get("torrent_client", None) != "watch":
console.print(f"[bold red]Missing torrent_storage_dir for {self.config['DEFAULT']['default_torrent_client']}")
return None
Expand All @@ -188,6 +184,10 @@ async def search_qbit_for_torrent(self, meta, client):
local_path, remote_path = await self.remote_path_map(meta)
if local_path.lower() in meta['path'].lower() and local_path.lower() != remote_path.lower():
remote_path_map = True
if meta['debug']:
print(f"Remote path mapping found!")
print(f"Local path: {local_path}")
print(f"Remote path: {remote_path}")

torrents = qbt_client.torrents.info()
for torrent in torrents:
Expand Down Expand Up @@ -215,17 +215,6 @@ async def search_qbit_for_torrent(self, meta, client):
return torrent.hash
return None












def rtorrent(self, path, torrent_path, torrent, meta, local_path, remote_path, client):
rtorrent = xmlrpc.client.Server(client['rtorrent_url'], context=ssl._create_stdlib_context())
metainfo = bencode.bread(torrent_path)
Expand All @@ -234,15 +223,13 @@ def rtorrent(self, path, torrent_path, torrent, meta, local_path, remote_path, c
except EnvironmentError as exc:
console.print("[red]Error making fast-resume data (%s)" % (exc,))
raise


new_meta = bencode.bencode(fast_resume)
if new_meta != metainfo:
fr_file = torrent_path.replace('.torrent', '-resume.torrent')
console.print("Creating fast resume")
bencode.bwrite(fast_resume, fr_file)


isdir = os.path.isdir(path)
# if meta['type'] == "DISC":
# path = os.path.dirname(path)
Expand All @@ -258,7 +245,6 @@ def rtorrent(self, path, torrent_path, torrent, meta, local_path, remote_path, c
if isdir == False:
path = os.path.dirname(path)


console.print("[bold yellow]Adding and starting torrent")
rtorrent.load.start_verbose('', fr_file, f"d.directory_base.set={path}")
time.sleep(1)
Expand All @@ -275,7 +261,6 @@ def rtorrent(self, path, torrent_path, torrent, meta, local_path, remote_path, c
console.print(f"[cyan]Path: {path}")
return


async def qbittorrent(self, path, torrent, local_path, remote_path, client, is_disc, filelist, meta):
# infohash = torrent.infohash
#Remote path mount
Expand Down Expand Up @@ -323,8 +308,6 @@ async def qbittorrent(self, path, torrent, local_path, remote_path, client, is_d
qbt_client.torrents_add_tags(tags=meta.get('qbit_tag'), torrent_hashes=torrent.infohash)
console.print(f"Added to: {path}")



def deluge(self, path, torrent_path, torrent, local_path, remote_path, client, meta):
client = DelugeRPCClient(client['deluge_url'], int(client['deluge_port']), client['deluge_user'], client['deluge_pass'])
# client = LocalDelugeRPCClient()
Expand All @@ -345,9 +328,6 @@ def deluge(self, path, torrent_path, torrent, local_path, remote_path, client, m
else:
console.print("[bold red]Unable to connect to deluge")




def add_fast_resume(self, metainfo, datapath, torrent):
""" Add fast resume data to a metafile dict.
"""
Expand Down Expand Up @@ -392,7 +372,6 @@ def add_fast_resume(self, metainfo, datapath, torrent):

return metainfo


async def remote_path_map(self, meta):
if meta.get('client', None) == None:
torrent_client = self.config['DEFAULT']['default_torrent_client']
Expand All @@ -405,7 +384,7 @@ async def remote_path_map(self, meta):
if os.path.normpath(local_path[i]).lower() in meta['path'].lower():
list_local_path = local_path[i]
list_remote_path = remote_path[i]

local_path = os.path.normpath(list_local_path)
remote_path = os.path.normpath(list_remote_path)
if local_path.endswith(os.sep):
Expand Down

0 comments on commit bc940fd

Please sign in to comment.