refs #2340: Replaces ctorrent with aria2c and mktorrent

pull/73/head
Nicolas Arenas 2025-06-26 18:42:31 +02:00
parent 4c191aa730
commit 5321325142
1 changed files with 49 additions and 23 deletions

View File

@ -671,7 +671,7 @@ def ogTorrentStart (disk=None, par=None, container=None, torrentfile=None, torre
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'device or torrentfile {dev_err} not found')
return
if subprocess.run (['ctorrent', '-x', source]).returncode: ## if True, then ctorrent failed
if subprocess.run (['aria2c', '-S', source]).returncode: ## if True, then aria2c failed
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, '')
return None
@ -697,24 +697,25 @@ def ogTorrentStart (disk=None, par=None, container=None, torrentfile=None, torre
OPTION = None
cwd = os.getcwd()
# si No fichero .bf, y Si fichero destino imagen ya descargada y su chequeo fue comprobado en su descarga inicial.
if not os.path.exists (f'{source}.bf') and os.path.exists (target):
# si No fichero .aria2, y Si fichero destino imagen ya descargada y su chequeo fue comprobado en su descarga inicial.
if not os.path.exists (f'{target}.aria2') and os.path.exists (target):
print ('imagen ya descargada')
if 'seeder' != mode: return 'success' ## return any true value
print ('MODE seeder ctorrent')
print ('MODE seeder aria2c')
os.chdir (dirsource)
subprocess.run (['timeout', '--signal', 'INT', time, 'ctorrent', '-f', source])
aria2_cmd = ["aria2c", "--check-integrity=true", "--bt-seed-unverified=true", "--seed-ratio=0.0", f"--seed-time={time}", "--enable-dht=false", "--enable-peer-exchange=false", f"--dir={dirsource}", f"{source}"]
subprocess.run (aria2_cmd)
os.chdir (cwd)
return 'success'
#Si no existe bf ni fichero destino descarga inicial.
if not os.path.exists (f'{source}.bf') and not os.path.exists (target):
#Si no existe bf ni fichero destino descarga inicial.
if not os.path.exists (f'{target}.aria2') and not os.path.exists (target):
print ('descarga inicial')
OPTION = 'DOWNLOAD'
# Si fichero bf descarga anterior no completada -.
if os.path.exists (f'{source}.bf') and os.path.exists (target):
if os.path.exists (f'{target}.aria2') and os.path.exists (target):
print ('Continuar con Descargar inicial no terminada.')
OPTION = 'DOWNLOAD'
@ -723,25 +724,50 @@ def ogTorrentStart (disk=None, par=None, container=None, torrentfile=None, torre
os.chdir (dirsource)
if 'peer' == mode:
print ('Donwloading Torrent as peer')
# Creamos el fichero de resumen por defecto
open (f'{source}.bf', 'w').close()
# ctorrent controla otro fichero -b ${SOURCE}.bfog
ctorrent_cmd = ['ctorrent', '-f', '-c', '-X', f'sleep {time}; kill -2 $(pidof ctorrent)', '-C', '100', source, '-s', target, '-b', f'{source}.bfog']
SystemLib.ogEcho(["session","log"],"warning",f'Starting PeerTorrent download in PEER mode')
aria2_cmd = [
"aria2c",
"--enable-dht=false",
"--enable-peer-exchange=false",
f"--seed-time={time}",
f"--dir={dirsource}",
f"{source}"
]
elif 'leecher' == mode:
print ('Donwloading Torrent as leecher')
ctorrent_cmd = ['ctorrent', source, '-X', 'sleep 30; kill -2 $(pidof ctorrent)', '-C', '100', '-U', '0']
SystemLib.ogEcho(["session","log"],"warning",f'Starting PeerTorrent download in LEECHER mode')
aria2_cmd = [
"aria2c",
"--enable-dht=false",
"--enable-peer-exchange=false",
"--disable-ipv6" ,
"--seed-time=0",
"bt-max-peers=0",
f"--dir={dirsource}",
f"{source}"
]
elif 'seeder' == mode:
print ('MODE seeder ctorrent')
# Creamos el fichero de resumen por defecto
open (f'{source}.bf', 'w').close()
# ctorrent controla otro fichero -b ${SOURCE}.bfog
ctorrent_cmd = ['ctorrent', '-f', '-c', '-X', f'sleep {time}; kill -2 $(pidof ctorrent)', '-C', '100', source, '-s', target, '-b', f'{source}.bfog']
print ('MODE seeder aria2c')
SystemLib.ogEcho(["session","log"],"warning",f'Starting PeerTorrent download in SEEDER mode')
aria2_cmd = [
"aria2c",
"--check-integrity=true",
"--bt-seed-unverified=true",
"--seed-ratio=0.0",
f"--seed-time={time}",
"--enable-dht=false",
"--enable-peer-exchange=false",
f"--dir={dirsource}", f"{source}"
]
else:
print ('this should not happen')
return None
print (f'executing ctorrent: {' '.join(ctorrent_cmd)}')
subprocess.run (ctorrent_cmd)
SystemLib.ogEcho(["session","log"],"warning",f'Launching torrent command: {aria2_cmd}')
subprocess.run (aria2_cmd)
os.chdir (cwd)
@ -811,8 +837,8 @@ def ogCreateTorrent (disk=None, par=None, container=None, file=None, ip_bttrack=
cwd = os.getcwd()
os.chdir (os.path.dirname (source))
print (f'ctorrent -t {os.path.basename (source)} -u http://{ip_bttrack}:6969/announce -s {source}.torrent')
subprocess.run (['ctorrent', '-t', os.path.basename (source), '-u', f'http://{ip_bttrack}:6969/announce', '-s', f'{source}.torrent'])
print (f'mktorrent -a http://{ip_bttrack}:6969/announce -o {source}.torrent {source}')
subprocess.run (['mktorrent' , '-a', f'http://{ip_bttrack}:6969/announce', '-o', f'{source}.torrent', source])
os.chdir (cwd)