mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 18:47:09 -07:00
Refactor downloader configuration to plugins.downloaders
This commit is contained in:
parent
ef950d8024
commit
e1aa32aee7
15 changed files with 218 additions and 186 deletions
|
@ -45,7 +45,6 @@ from core.utils.paths import (
|
|||
)
|
||||
from core.utils.processes import RunningProcess, restart
|
||||
from core.utils.subtitles import import_subs
|
||||
from core.utils.torrents import create_torrent_class, pause_torrent, remove_torrent, resume_torrent
|
||||
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
shutil_custom.monkey_patch()
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
import time
|
||||
|
||||
from qbittorrent import Client as qBittorrentClient
|
||||
from synchronousdeluge.client import DelugeClient
|
||||
from transmissionrpc.client import Client as TransmissionClient
|
||||
from utorrent.client import UTorrentClient
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
|
||||
|
||||
def create_torrent_class(client_agent):
|
||||
# Hardlink solution for Torrents
|
||||
tc = None
|
||||
if not core.APP_NAME == 'TorrentToMedia.py': #Skip loading Torrent for NZBs.
|
||||
return tc
|
||||
|
||||
if client_agent == 'utorrent':
|
||||
try:
|
||||
logger.debug('Connecting to {0}: {1}'.format(client_agent, core.UTORRENT_WEB_UI))
|
||||
tc = UTorrentClient(core.UTORRENT_WEB_UI, core.UTORRENT_USER, core.UTORRENT_PASSWORD)
|
||||
except Exception:
|
||||
logger.error('Failed to connect to uTorrent')
|
||||
|
||||
if client_agent == 'transmission':
|
||||
try:
|
||||
logger.debug('Connecting to {0}: http://{1}:{2}'.format(
|
||||
client_agent, core.TRANSMISSION_HOST, core.TRANSMISSION_PORT))
|
||||
tc = TransmissionClient(core.TRANSMISSION_HOST, core.TRANSMISSION_PORT,
|
||||
core.TRANSMISSION_USER,
|
||||
core.TRANSMISSION_PASSWORD)
|
||||
except Exception:
|
||||
logger.error('Failed to connect to Transmission')
|
||||
|
||||
if client_agent == 'deluge':
|
||||
try:
|
||||
logger.debug('Connecting to {0}: http://{1}:{2}'.format(client_agent, core.DELUGE_HOST, core.DELUGE_PORT))
|
||||
tc = DelugeClient()
|
||||
tc.connect(host=core.DELUGE_HOST, port=core.DELUGE_PORT, username=core.DELUGE_USER,
|
||||
password=core.DELUGE_PASSWORD)
|
||||
except Exception:
|
||||
logger.error('Failed to connect to Deluge')
|
||||
|
||||
if client_agent == 'qbittorrent':
|
||||
try:
|
||||
logger.debug('Connecting to {0}: http://{1}:{2}'.format(client_agent, core.QBITTORRENT_HOST, core.QBITTORRENT_PORT))
|
||||
tc = qBittorrentClient('http://{0}:{1}/'.format(core.QBITTORRENT_HOST, core.QBITTORRENT_PORT))
|
||||
tc.login(core.QBITTORRENT_USER, core.QBITTORRENT_PASSWORD)
|
||||
except Exception:
|
||||
logger.error('Failed to connect to qBittorrent')
|
||||
|
||||
return tc
|
||||
|
||||
|
||||
def pause_torrent(client_agent, input_hash, input_id, input_name):
|
||||
logger.debug('Stopping torrent {0} in {1} while processing'.format(input_name, client_agent))
|
||||
try:
|
||||
if client_agent == 'utorrent' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.stop(input_hash)
|
||||
if client_agent == 'transmission' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.stop_torrent(input_id)
|
||||
if client_agent == 'deluge' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.core.pause_torrent([input_id])
|
||||
if client_agent == 'qbittorrent' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.pause(input_hash)
|
||||
time.sleep(5)
|
||||
except Exception:
|
||||
logger.warning('Failed to stop torrent {0} in {1}'.format(input_name, client_agent))
|
||||
|
||||
|
||||
def resume_torrent(client_agent, input_hash, input_id, input_name):
|
||||
if not core.TORRENT_RESUME == 1:
|
||||
return
|
||||
logger.debug('Starting torrent {0} in {1}'.format(input_name, client_agent))
|
||||
try:
|
||||
if client_agent == 'utorrent' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.start(input_hash)
|
||||
if client_agent == 'transmission' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.start_torrent(input_id)
|
||||
if client_agent == 'deluge' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.core.resume_torrent([input_id])
|
||||
if client_agent == 'qbittorrent' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.resume(input_hash)
|
||||
time.sleep(5)
|
||||
except Exception:
|
||||
logger.warning('Failed to start torrent {0} in {1}'.format(input_name, client_agent))
|
||||
|
||||
|
||||
def remove_torrent(client_agent, input_hash, input_id, input_name):
|
||||
if core.DELETE_ORIGINAL == 1 or core.USE_LINK == 'move':
|
||||
logger.debug('Deleting torrent {0} from {1}'.format(input_name, client_agent))
|
||||
try:
|
||||
if client_agent == 'utorrent' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.removedata(input_hash)
|
||||
core.TORRENT_CLASS.remove(input_hash)
|
||||
if client_agent == 'transmission' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.remove_torrent(input_id, True)
|
||||
if client_agent == 'deluge' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.core.remove_torrent(input_id, True)
|
||||
if client_agent == 'qbittorrent' and core.TORRENT_CLASS != '':
|
||||
core.TORRENT_CLASS.delete_permanently(input_hash)
|
||||
time.sleep(5)
|
||||
except Exception:
|
||||
logger.warning('Failed to delete torrent {0} in {1}'.format(input_name, client_agent))
|
||||
else:
|
||||
resume_torrent(client_agent, input_hash, input_id, input_name)
|
Loading…
Add table
Add a link
Reference in a new issue