mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 10:36:52 -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
0
core/plugins/__init__.py
Normal file
0
core/plugins/__init__.py
Normal file
0
core/plugins/downloaders/__init__.py
Normal file
0
core/plugins/downloaders/__init__.py
Normal file
5
core/plugins/downloaders/configuration.py
Normal file
5
core/plugins/downloaders/configuration.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from core.plugins.downloaders.nzb.configuration import configure_nzbs
|
||||
from core.plugins.downloaders.torrent.configuration import (
|
||||
configure_torrents,
|
||||
configure_torrent_class,
|
||||
)
|
0
core/plugins/downloaders/nzb/__init__.py
Normal file
0
core/plugins/downloaders/nzb/__init__.py
Normal file
15
core/plugins/downloaders/nzb/configuration.py
Normal file
15
core/plugins/downloaders/nzb/configuration.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
import core
|
||||
|
||||
|
||||
def configure_nzbs(config):
|
||||
nzb_config = config['Nzb']
|
||||
core.NZB_CLIENT_AGENT = nzb_config['clientAgent'] # sabnzbd
|
||||
core.NZB_DEFAULT_DIRECTORY = nzb_config['default_downloadDirectory']
|
||||
|
||||
configure_sabnzbd(nzb_config)
|
||||
|
||||
|
||||
def configure_sabnzbd(config):
|
||||
core.SABNZBD_HOST = config['sabnzbd_host']
|
||||
core.SABNZBD_PORT = int(config['sabnzbd_port'] or 8080) # defaults to accommodate NzbGet
|
||||
core.SABNZBD_APIKEY = config['sabnzbd_apikey']
|
0
core/plugins/downloaders/torrent/__init__.py
Normal file
0
core/plugins/downloaders/torrent/__init__.py
Normal file
81
core/plugins/downloaders/torrent/configuration.py
Normal file
81
core/plugins/downloaders/torrent/configuration.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
import core
|
||||
from core.plugins.downloaders.torrent.utils import create_torrent_class
|
||||
|
||||
|
||||
def configure_torrents(config):
|
||||
torrent_config = config['Torrent']
|
||||
core.TORRENT_CLIENT_AGENT = torrent_config['clientAgent'] # utorrent | deluge | transmission | rtorrent | vuze | qbittorrent |other
|
||||
core.OUTPUT_DIRECTORY = torrent_config['outputDirectory'] # /abs/path/to/complete/
|
||||
core.TORRENT_DEFAULT_DIRECTORY = torrent_config['default_downloadDirectory']
|
||||
|
||||
configure_torrent_linking(torrent_config)
|
||||
configure_flattening(torrent_config)
|
||||
configure_torrent_deletion(torrent_config)
|
||||
configure_torrent_categories(torrent_config)
|
||||
configure_torrent_permissions(torrent_config)
|
||||
configure_torrent_resuming(torrent_config)
|
||||
configure_utorrent(torrent_config)
|
||||
configure_transmission(torrent_config)
|
||||
configure_deluge(torrent_config)
|
||||
configure_qbittorrent(torrent_config)
|
||||
|
||||
|
||||
def configure_torrent_linking(config):
|
||||
core.USE_LINK = config['useLink'] # no | hard | sym
|
||||
|
||||
|
||||
def configure_flattening(config):
|
||||
core.NOFLATTEN = (config['noFlatten'])
|
||||
if isinstance(core.NOFLATTEN, str):
|
||||
core.NOFLATTEN = core.NOFLATTEN.split(',')
|
||||
|
||||
|
||||
def configure_torrent_categories(config):
|
||||
core.CATEGORIES = (config['categories']) # music,music_videos,pictures,software
|
||||
if isinstance(core.CATEGORIES, str):
|
||||
core.CATEGORIES = core.CATEGORIES.split(',')
|
||||
|
||||
|
||||
def configure_torrent_resuming(config):
|
||||
core.TORRENT_RESUME_ON_FAILURE = int(config['resumeOnFailure'])
|
||||
core.TORRENT_RESUME = int(config['resume'])
|
||||
|
||||
|
||||
def configure_torrent_permissions(config):
|
||||
core.TORRENT_CHMOD_DIRECTORY = int(str(config['chmodDirectory']), 8)
|
||||
|
||||
|
||||
def configure_torrent_deletion(config):
|
||||
core.DELETE_ORIGINAL = int(config['deleteOriginal'])
|
||||
|
||||
|
||||
def configure_utorrent(config):
|
||||
core.UTORRENT_WEB_UI = config['uTorrentWEBui'] # http://localhost:8090/gui/
|
||||
core.UTORRENT_USER = config['uTorrentUSR'] # mysecretusr
|
||||
core.UTORRENT_PASSWORD = config['uTorrentPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_transmission(config):
|
||||
core.TRANSMISSION_HOST = config['TransmissionHost'] # localhost
|
||||
core.TRANSMISSION_PORT = int(config['TransmissionPort'])
|
||||
core.TRANSMISSION_USER = config['TransmissionUSR'] # mysecretusr
|
||||
core.TRANSMISSION_PASSWORD = config['TransmissionPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_deluge(config):
|
||||
core.DELUGE_HOST = config['DelugeHost'] # localhost
|
||||
core.DELUGE_PORT = int(config['DelugePort']) # 8084
|
||||
core.DELUGE_USER = config['DelugeUSR'] # mysecretusr
|
||||
core.DELUGE_PASSWORD = config['DelugePWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_qbittorrent(config):
|
||||
core.QBITTORRENT_HOST = config['qBittorrenHost'] # localhost
|
||||
core.QBITTORRENT_PORT = int(config['qBittorrentPort']) # 8080
|
||||
core.QBITTORRENT_USER = config['qBittorrentUSR'] # mysecretusr
|
||||
core.QBITTORRENT_PASSWORD = config['qBittorrentPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_torrent_class():
|
||||
# create torrent class
|
||||
core.TORRENT_CLASS = create_torrent_class(core.TORRENT_CLIENT_AGENT)
|
21
core/plugins/downloaders/torrent/deluge.py
Normal file
21
core/plugins/downloaders/torrent/deluge.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from synchronousdeluge.client import DelugeClient
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
|
||||
|
||||
def configure_client():
|
||||
agent = 'deluge'
|
||||
host = core.DELUGE_HOST
|
||||
port = core.DELUGE_PORT
|
||||
user = core.DELUGE_USER
|
||||
password = core.DELUGE_PASSWORD
|
||||
|
||||
logger.debug('Connecting to {0}: http://{1}:{2}'.format(agent, host, port))
|
||||
client = DelugeClient()
|
||||
try:
|
||||
client.connect(host, port, user, password)
|
||||
except Exception:
|
||||
logger.error('Failed to connect to Deluge')
|
||||
else:
|
||||
return client
|
23
core/plugins/downloaders/torrent/qbittorrent.py
Normal file
23
core/plugins/downloaders/torrent/qbittorrent.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
from qbittorrent import Client as qBittorrentClient
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
|
||||
|
||||
def configure_client():
|
||||
agent = 'qbittorrent'
|
||||
host = core.QBITTORRENT_HOST
|
||||
port = core.QBITTORRENT_PORT
|
||||
user = core.QBITTORRENT_USER
|
||||
password = core.QBITTORRENT_PASSWORD
|
||||
|
||||
logger.debug(
|
||||
'Connecting to {0}: http://{1}:{2}'.format(agent, host, port)
|
||||
)
|
||||
client = qBittorrentClient('http://{0}:{1}/'.format(host, port))
|
||||
try:
|
||||
client.login(user, password)
|
||||
except Exception:
|
||||
logger.error('Failed to connect to qBittorrent')
|
||||
else:
|
||||
return client
|
20
core/plugins/downloaders/torrent/transmission.py
Normal file
20
core/plugins/downloaders/torrent/transmission.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from transmissionrpc.client import Client as TransmissionClient
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
|
||||
|
||||
def configure_client():
|
||||
agent = 'transmission'
|
||||
host = core.TRANSMISSION_HOST
|
||||
port = core.TRANSMISSION_PORT
|
||||
user = core.TRANSMISSION_USER
|
||||
password = core.TRANSMISSION_PASSWORD
|
||||
|
||||
logger.debug('Connecting to {0}: http://{1}:{2}'.format(agent, host, port))
|
||||
try:
|
||||
client = TransmissionClient(host, port, user, password)
|
||||
except Exception:
|
||||
logger.error('Failed to connect to Transmission')
|
||||
else:
|
||||
return client
|
79
core/plugins/downloaders/torrent/utils.py
Normal file
79
core/plugins/downloaders/torrent/utils.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
import time
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
|
||||
from .deluge import configure_client as deluge_client
|
||||
from .qbittorrent import configure_client as qbittorrent_client
|
||||
from .transmission import configure_client as transmission_client
|
||||
from .utorrent import configure_client as utorrent_client
|
||||
|
||||
torrent_clients = {
|
||||
'deluge': deluge_client,
|
||||
'qbittorrent': qbittorrent_client,
|
||||
'transmission': transmission_client,
|
||||
'utorrent': utorrent_client,
|
||||
}
|
||||
|
||||
|
||||
def create_torrent_class(client_agent):
|
||||
if not core.APP_NAME == 'TorrentToMedia.py':
|
||||
return # Skip loading Torrent for NZBs.
|
||||
|
||||
client = torrent_clients.get(client_agent)
|
||||
if client:
|
||||
return client()
|
||||
|
||||
|
||||
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)
|
19
core/plugins/downloaders/torrent/utorrent.py
Normal file
19
core/plugins/downloaders/torrent/utorrent.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from utorrent.client import UTorrentClient
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
|
||||
|
||||
def configure_client():
|
||||
agent = 'utorrent'
|
||||
web_ui = core.UTORRENT_WEB_UI
|
||||
user = core.UTORRENT_USER
|
||||
password = core.UTORRENT_PASSWORD
|
||||
|
||||
logger.debug('Connecting to {0}: {1}'.format(agent, web_ui))
|
||||
try:
|
||||
client = UTorrentClient(web_ui, user, password)
|
||||
except Exception:
|
||||
logger.error('Failed to connect to uTorrent')
|
||||
else:
|
||||
return client
|
5
core/plugins/downloaders/utils.py
Normal file
5
core/plugins/downloaders/utils.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from core.plugins.downloaders.torrent.utils import (
|
||||
pause_torrent,
|
||||
remove_torrent,
|
||||
resume_torrent,
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue