mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-16 02:02:53 -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
153
core/__init__.py
153
core/__init__.py
|
@ -46,12 +46,21 @@ from six.moves import reload_module
|
|||
|
||||
from core import logger, main_db, version_check, databases, transcoder
|
||||
from core.configuration import config
|
||||
from core.plugins.downloaders.configuration import (
|
||||
configure_nzbs,
|
||||
configure_torrents,
|
||||
configure_torrent_class,
|
||||
)
|
||||
from core.plugins.downloaders.utils import (
|
||||
pause_torrent,
|
||||
remove_torrent,
|
||||
resume_torrent,
|
||||
)
|
||||
from core.utils import (
|
||||
RunningProcess,
|
||||
category_search,
|
||||
clean_dir,
|
||||
copy_link,
|
||||
create_torrent_class,
|
||||
extract_files,
|
||||
flatten,
|
||||
get_dirs,
|
||||
|
@ -59,13 +68,10 @@ from core.utils import (
|
|||
list_media_files,
|
||||
make_dir,
|
||||
parse_args,
|
||||
pause_torrent,
|
||||
rchmod,
|
||||
remove_dir,
|
||||
remove_read_only,
|
||||
remove_torrent,
|
||||
restart,
|
||||
resume_torrent,
|
||||
sanitize_name,
|
||||
update_download_info_status,
|
||||
wake_up,
|
||||
|
@ -403,26 +409,6 @@ def configure_wake_on_lan():
|
|||
wake_up()
|
||||
|
||||
|
||||
def configure_sabnzbd():
|
||||
global SABNZBD_HOST
|
||||
global SABNZBD_PORT
|
||||
global SABNZBD_APIKEY
|
||||
|
||||
SABNZBD_HOST = CFG['Nzb']['sabnzbd_host']
|
||||
SABNZBD_PORT = int(CFG['Nzb']['sabnzbd_port'] or 8080) # defaults to accommodate NzbGet
|
||||
SABNZBD_APIKEY = CFG['Nzb']['sabnzbd_apikey']
|
||||
|
||||
|
||||
def configure_nzbs():
|
||||
global NZB_CLIENT_AGENT
|
||||
global NZB_DEFAULT_DIRECTORY
|
||||
|
||||
NZB_CLIENT_AGENT = CFG['Nzb']['clientAgent'] # sabnzbd
|
||||
NZB_DEFAULT_DIRECTORY = CFG['Nzb']['default_downloadDirectory']
|
||||
|
||||
configure_sabnzbd()
|
||||
|
||||
|
||||
def configure_groups():
|
||||
global GROUPS
|
||||
|
||||
|
@ -435,114 +421,6 @@ def configure_groups():
|
|||
GROUPS = None
|
||||
|
||||
|
||||
def configure_utorrent():
|
||||
global UTORRENT_WEB_UI
|
||||
global UTORRENT_USER
|
||||
global UTORRENT_PASSWORD
|
||||
|
||||
UTORRENT_WEB_UI = CFG['Torrent']['uTorrentWEBui'] # http://localhost:8090/gui/
|
||||
UTORRENT_USER = CFG['Torrent']['uTorrentUSR'] # mysecretusr
|
||||
UTORRENT_PASSWORD = CFG['Torrent']['uTorrentPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_transmission():
|
||||
global TRANSMISSION_HOST
|
||||
global TRANSMISSION_PORT
|
||||
global TRANSMISSION_USER
|
||||
global TRANSMISSION_PASSWORD
|
||||
|
||||
TRANSMISSION_HOST = CFG['Torrent']['TransmissionHost'] # localhost
|
||||
TRANSMISSION_PORT = int(CFG['Torrent']['TransmissionPort'])
|
||||
TRANSMISSION_USER = CFG['Torrent']['TransmissionUSR'] # mysecretusr
|
||||
TRANSMISSION_PASSWORD = CFG['Torrent']['TransmissionPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_deluge():
|
||||
global DELUGE_HOST
|
||||
global DELUGE_PORT
|
||||
global DELUGE_USER
|
||||
global DELUGE_PASSWORD
|
||||
|
||||
DELUGE_HOST = CFG['Torrent']['DelugeHost'] # localhost
|
||||
DELUGE_PORT = int(CFG['Torrent']['DelugePort']) # 8084
|
||||
DELUGE_USER = CFG['Torrent']['DelugeUSR'] # mysecretusr
|
||||
DELUGE_PASSWORD = CFG['Torrent']['DelugePWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_qbittorrent():
|
||||
global QBITTORRENT_HOST
|
||||
global QBITTORRENT_PORT
|
||||
global QBITTORRENT_USER
|
||||
global QBITTORRENT_PASSWORD
|
||||
|
||||
QBITTORRENT_HOST = CFG['Torrent']['qBittorrenHost'] # localhost
|
||||
QBITTORRENT_PORT = int(CFG['Torrent']['qBittorrentPort']) # 8080
|
||||
QBITTORRENT_USER = CFG['Torrent']['qBittorrentUSR'] # mysecretusr
|
||||
QBITTORRENT_PASSWORD = CFG['Torrent']['qBittorrentPWD'] # mysecretpwr
|
||||
|
||||
|
||||
def configure_flattening():
|
||||
global NOFLATTEN
|
||||
|
||||
NOFLATTEN = (CFG['Torrent']['noFlatten'])
|
||||
if isinstance(NOFLATTEN, str):
|
||||
NOFLATTEN = NOFLATTEN.split(',')
|
||||
|
||||
|
||||
def configure_torrent_categories():
|
||||
global CATEGORIES
|
||||
|
||||
CATEGORIES = (CFG['Torrent']['categories']) # music,music_videos,pictures,software
|
||||
if isinstance(CATEGORIES, str):
|
||||
CATEGORIES = CATEGORIES.split(',')
|
||||
|
||||
|
||||
def configure_torrent_resuming():
|
||||
global TORRENT_RESUME
|
||||
global TORRENT_RESUME_ON_FAILURE
|
||||
|
||||
TORRENT_RESUME_ON_FAILURE = int(CFG['Torrent']['resumeOnFailure'])
|
||||
TORRENT_RESUME = int(CFG['Torrent']['resume'])
|
||||
|
||||
|
||||
def configure_torrent_permissions():
|
||||
global TORRENT_CHMOD_DIRECTORY
|
||||
|
||||
TORRENT_CHMOD_DIRECTORY = int(str(CFG['Torrent']['chmodDirectory']), 8)
|
||||
|
||||
|
||||
def configure_torrent_deltetion():
|
||||
global DELETE_ORIGINAL
|
||||
|
||||
DELETE_ORIGINAL = int(CFG['Torrent']['deleteOriginal'])
|
||||
|
||||
|
||||
def configure_torrent_linking():
|
||||
global USE_LINK
|
||||
|
||||
USE_LINK = CFG['Torrent']['useLink'] # no | hard | sym
|
||||
|
||||
|
||||
def configure_torrents():
|
||||
global TORRENT_CLIENT_AGENT
|
||||
global OUTPUT_DIRECTORY
|
||||
global TORRENT_DEFAULT_DIRECTORY
|
||||
|
||||
TORRENT_CLIENT_AGENT = CFG['Torrent']['clientAgent'] # utorrent | deluge | transmission | rtorrent | vuze | qbittorrent |other
|
||||
OUTPUT_DIRECTORY = CFG['Torrent']['outputDirectory'] # /abs/path/to/complete/
|
||||
TORRENT_DEFAULT_DIRECTORY = CFG['Torrent']['default_downloadDirectory']
|
||||
configure_torrent_linking()
|
||||
configure_flattening()
|
||||
configure_torrent_deltetion()
|
||||
configure_torrent_categories()
|
||||
configure_torrent_permissions()
|
||||
configure_torrent_resuming()
|
||||
configure_utorrent()
|
||||
configure_transmission()
|
||||
configure_deluge()
|
||||
configure_qbittorrent()
|
||||
|
||||
|
||||
def configure_remote_paths():
|
||||
global REMOTE_PATHS
|
||||
|
||||
|
@ -973,13 +851,6 @@ def configure_passwords_file():
|
|||
PASSWORDS_FILE = CFG['passwords']['PassWordFile']
|
||||
|
||||
|
||||
def configure_torrent_class():
|
||||
global TORRENT_CLASS
|
||||
|
||||
# create torrent class
|
||||
TORRENT_CLASS = create_torrent_class(TORRENT_CLIENT_AGENT)
|
||||
|
||||
|
||||
def configure_sections(section):
|
||||
global SECTIONS
|
||||
global CATEGORIES
|
||||
|
@ -1138,8 +1009,8 @@ def initialize(section=None):
|
|||
configure_general()
|
||||
configure_updates()
|
||||
configure_wake_on_lan()
|
||||
configure_nzbs()
|
||||
configure_torrents()
|
||||
configure_nzbs(CFG)
|
||||
configure_torrents(CFG)
|
||||
configure_remote_paths()
|
||||
configure_plex()
|
||||
configure_niceness()
|
||||
|
|
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
|
|
@ -1,55 +1,28 @@
|
|||
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
|
||||
|
||||
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):
|
||||
# Hardlink solution for Torrents
|
||||
tc = None
|
||||
if not core.APP_NAME == 'TorrentToMedia.py': #Skip loading Torrent for NZBs.
|
||||
return tc
|
||||
if not core.APP_NAME == 'TorrentToMedia.py':
|
||||
return # Skip loading Torrent for NZBs.
|
||||
|
||||
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
|
||||
client = torrent_clients.get(client_agent)
|
||||
if client:
|
||||
return client()
|
||||
|
||||
|
||||
def pause_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,
|
||||
)
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue