Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
clinton-hall committed Apr 16, 2020
2 parents 5a68377 + 54534c4 commit f5e4ec0
Show file tree
Hide file tree
Showing 17 changed files with 534 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 12.1.04
current_version = 12.1.05
commit = True
tag = False

Expand Down
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Installation instructions for this are available in the [wiki](https://github.co

Contribution
------------
We who have developed nzbToMedia believe in the openness of open-source, and as such we hope that any modifications will lead back to the [orignal repo](https://github.com/clinton-hall/nzbToMedia "orignal repo") via pull requests.
We who have developed nzbToMedia believe in the openness of open-source, and as such we hope that any modifications will lead back to the [original repo](https://github.com/clinton-hall/nzbToMedia "orignal repo") via pull requests.

Founder: [clinton-hall](https://github.com/clinton-hall "clinton-hall")

Expand Down
9 changes: 7 additions & 2 deletions autoProcessMedia.cfg.spec
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
default_downloadDirectory =

[Torrent]
###### clientAgent - Supported clients: utorrent, transmission, deluge, rtorrent, vuze, qbittorrent, other
###### clientAgent - Supported clients: utorrent, transmission, deluge, rtorrent, vuze, qbittorrent, synods, other
clientAgent = other
###### useLink - Set to hard for physical links, sym for symbolic links, move to move, move-sym to move and link back, and no to not use links (copy)
useLink = hard
Expand All @@ -382,10 +382,15 @@
DelugeUSR = your username
DelugePWD = your password
###### qBittorrent (You must edit this if you're using TorrentToMedia.py with qBittorrent)
qBittorrenHost = localhost
qBittorrentHost = localhost
qBittorrentPort = 8080
qBittorrentUSR = your username
qBittorrentPWD = your password
###### Synology Download Station (You must edit this if you're using TorrentToMedia.py with Synology DS)
synoHost = localhost
synoPort = 5000
synoUSR = your username
synoPWD = your password
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######
deleteOriginal = 0
chmodDirectory = 0
Expand Down
7 changes: 6 additions & 1 deletion core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
wake_up,
)

__version__ = '12.1.04'
__version__ = '12.1.05'

# Client Agents
NZB_CLIENTS = ['sabnzbd', 'nzbget', 'manual']
Expand Down Expand Up @@ -178,6 +178,11 @@
TRANSMISSION_USER = None
TRANSMISSION_PASSWORD = None

SYNO_HOST = None
SYNO_PORT = None
SYNO_USER = None
SYNO_PASSWORD = None

DELUGE_HOST = None
DELUGE_PORT = None
DELUGE_USER = None
Expand Down
10 changes: 8 additions & 2 deletions core/auto_process/movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,21 +548,27 @@ def get_release(base_url, imdb_id=None, download_id=None, release_id=None):

# Narrow results by removing old releases by comparing their last_edit field
if len(results) > 1:
rem_id = []
for id1, x1 in results.items():
for x2 in results.values():
try:
if x2['last_edit'] > x1['last_edit']:
results.pop(id1)
rem_id.append(id1)
except Exception:
continue
for id in rem_id:
results.pop(id)

# Search downloads on clients for a match to try and narrow our results down to 1
if len(results) > 1:
rem_id = []
for cur_id, x in results.items():
try:
if not find_download(str(x['download_info']['downloader']).lower(), x['download_info']['id']):
results.pop(cur_id)
rem_id.append(cur_id)
except Exception:
continue
for id in rem_id:
results.pop(id)

return results
9 changes: 7 additions & 2 deletions core/auto_process/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,12 @@ def process(section, dir_name, input_name=None, failed=False, client_agent='manu
url = None
if section == 'SickBeard':
if apikey:
url = '{0}{1}:{2}{3}/api/{4}/?cmd=postprocess'.format(protocol, host, port, web_root, apikey)
url = '{0}{1}:{2}{3}/api/{4}/'.format(protocol, host, port, web_root, apikey)
if not 'cmd' in fork_params:
if 'SickGear' in fork:
fork_params['cmd'] = 'sg.postprocess'
else:
fork_params['cmd'] = 'postprocess'
elif fork == 'Stheno':
url = '{0}{1}:{2}{3}/home/postprocess/process_episode'.format(protocol, host, port, web_root)
else:
Expand Down Expand Up @@ -300,7 +305,7 @@ def process(section, dir_name, input_name=None, failed=False, client_agent='manu
login = '{0}{1}:{2}{3}/login'.format(protocol, host, port, web_root)
login_params = {'username': username, 'password': password}
r = s.get(login, verify=False, timeout=(30, 60))
if r.status_code == 401 and r.cookies.get('_xsrf'):
if r.status_code in [401, 403] and r.cookies.get('_xsrf'):
login_params['_xsrf'] = r.cookies.get('_xsrf')
s.post(login, data=login_params, stream=True, verify=False, timeout=(30, 60))
r = s.get(url, auth=(username, password), params=fork_params, stream=True, verify=False, timeout=(30, 1800))
Expand Down
3 changes: 3 additions & 0 deletions core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ def cleanup_values(values, section):
if option == 'forceClean':
CFG_NEW['General']['force_clean'] = value
values.pop(option)
if option == 'qBittorrenHost': #We had a typo that is now fixed.
CFG_NEW['Torrent']['qBittorrentHost'] = value
values.pop(option)
if section in ['Transcoder']:
if option in ['niceness']:
CFG_NEW['Posix'][option] = value
Expand Down
18 changes: 14 additions & 4 deletions core/forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)

import requests
import six
from six import iteritems

import core
Expand All @@ -28,6 +29,12 @@ def api_check(r, params, rem_params):
logger.debug('Response received: {}'.format(json_data))
raise
else:
if six.PY3:
str_type = (str)
else:
str_type = (str, unicode)
if isinstance(json_data, str_type):
return rem_params, False
json_data = json_data.get('data', json_data)

try:
Expand Down Expand Up @@ -104,7 +111,7 @@ def auto_fork(section, input_category):
# then in order of most unique parameters.

if apikey:
url = '{protocol}{host}:{port}{root}/api/{apikey}/?cmd=help&subject=postprocess'.format(
url = '{protocol}{host}:{port}{root}/api/{apikey}/?cmd=sg.postprocess&help=1'.format(
protocol=protocol, host=host, port=port, root=web_root, apikey=apikey,
)
else:
Expand All @@ -120,7 +127,7 @@ def auto_fork(section, input_category):
protocol=protocol, host=host, port=port, root=web_root)
login_params = {'username': username, 'password': password}
r = s.get(login, verify=False, timeout=(30, 60))
if r.status_code == 401 and r.cookies.get('_xsrf'):
if r.status_code in [401, 403] and r.cookies.get('_xsrf'):
login_params['_xsrf'] = r.cookies.get('_xsrf')
s.post(login, data=login_params, stream=True, verify=False)
r = s.get(url, auth=(username, password), verify=False)
Expand All @@ -131,8 +138,10 @@ def auto_fork(section, input_category):
if r and r.ok:
if apikey:
rem_params, found = api_check(r, params, rem_params)
if not found: # try different api set for SickGear.
url = '{protocol}{host}:{port}{root}/api/{apikey}/?cmd=postprocess&help=1'.format(
if found:
params['cmd'] = 'sg.postprocess'
else: # try different api set for non-SickGear forks.
url = '{protocol}{host}:{port}{root}/api/{apikey}/?cmd=help&subject=postprocess'.format(
protocol=protocol, host=host, port=port, root=web_root, apikey=apikey,
)
try:
Expand All @@ -141,6 +150,7 @@ def auto_fork(section, input_category):
logger.info('Could not connect to {section}:{category} to perform auto-fork detection!'.format
(section=section, category=input_category))
rem_params, found = api_check(r, params, rem_params)
params['cmd'] = 'postprocess'
else:
# Find excess parameters
rem_params.extend(
Expand Down
12 changes: 10 additions & 2 deletions core/plugins/downloaders/torrent/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def configure_torrents(config):
torrent_config = config['Torrent']
core.TORRENT_CLIENT_AGENT = torrent_config['clientAgent'] # utorrent | deluge | transmission | rtorrent | vuze | qbittorrent |other
core.TORRENT_CLIENT_AGENT = torrent_config['clientAgent'] # utorrent | deluge | transmission | rtorrent | vuze | qbittorrent | synods | other
core.OUTPUT_DIRECTORY = torrent_config['outputDirectory'] # /abs/path/to/complete/
core.TORRENT_DEFAULT_DIRECTORY = torrent_config['default_downloadDirectory']

Expand All @@ -25,6 +25,7 @@ def configure_torrents(config):
configure_transmission(torrent_config)
configure_deluge(torrent_config)
configure_qbittorrent(torrent_config)
configure_syno(torrent_config)


def configure_torrent_linking(config):
Expand Down Expand Up @@ -69,6 +70,13 @@ def configure_transmission(config):
core.TRANSMISSION_PASSWORD = config['TransmissionPWD'] # mysecretpwr


def configure_syno(config):
core.SYNO_HOST = config['synoHost'] # localhost
core.SYNO_PORT = int(config['synoPort'])
core.SYNO_USER = config['synoUSR'] # mysecretusr
core.SYNO_PASSWORD = config['synoPWD'] # mysecretpwr


def configure_deluge(config):
core.DELUGE_HOST = config['DelugeHost'] # localhost
core.DELUGE_PORT = int(config['DelugePort']) # 8084
Expand All @@ -77,7 +85,7 @@ def configure_deluge(config):


def configure_qbittorrent(config):
core.QBITTORRENT_HOST = config['qBittorrenHost'] # localhost
core.QBITTORRENT_HOST = config['qBittorrentHost'] # localhost
core.QBITTORRENT_PORT = int(config['qBittorrentPort']) # 8080
core.QBITTORRENT_USER = config['qBittorrentUSR'] # mysecretusr
core.QBITTORRENT_PASSWORD = config['qBittorrentPWD'] # mysecretpwr
Expand Down
27 changes: 27 additions & 0 deletions core/plugins/downloaders/torrent/synology.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import (
absolute_import,
division,
print_function,
unicode_literals,
)

from syno.downloadstation import DownloadStation

import core
from core import logger


def configure_client():
agent = 'synology'
host = core.SYNO_HOST
port = core.SYNO_PORT
user = core.SYNO_USER
password = core.SYNO_PASSWORD

logger.debug('Connecting to {0}: http://{1}:{2}'.format(agent, host, port))
try:
client = DownloadStation(host, port, user, password)
except Exception:
logger.error('Failed to connect to synology')
else:
return client
8 changes: 8 additions & 0 deletions core/plugins/downloaders/torrent/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
from .qbittorrent import configure_client as qbittorrent_client
from .transmission import configure_client as transmission_client
from .utorrent import configure_client as utorrent_client
from .synology import configure_client as synology_client

torrent_clients = {
'deluge': deluge_client,
'qbittorrent': qbittorrent_client,
'transmission': transmission_client,
'utorrent': utorrent_client,
'synods': synology_client,
}


Expand All @@ -39,6 +41,8 @@ def pause_torrent(client_agent, input_hash, input_id, input_name):
core.TORRENT_CLASS.stop(input_hash)
if client_agent == 'transmission' and core.TORRENT_CLASS != '':
core.TORRENT_CLASS.stop_torrent(input_id)
if client_agent == 'synods' and core.TORRENT_CLASS != '':
core.TORRENT_CLASS.pause_task(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 != '':
Expand All @@ -57,6 +61,8 @@ def resume_torrent(client_agent, input_hash, input_id, input_name):
core.TORRENT_CLASS.start(input_hash)
if client_agent == 'transmission' and core.TORRENT_CLASS != '':
core.TORRENT_CLASS.start_torrent(input_id)
if client_agent == 'synods' and core.TORRENT_CLASS != '':
core.TORRENT_CLASS.resume_task(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 != '':
Expand All @@ -75,6 +81,8 @@ def remove_torrent(client_agent, input_hash, input_id, input_name):
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 == 'synods' and core.TORRENT_CLASS != '':
core.TORRENT_CLASS.delete_task(input_id)
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 != '':
Expand Down
32 changes: 32 additions & 0 deletions core/utils/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os

import core
from core import logger


def parse_other(args):
Expand Down Expand Up @@ -81,6 +82,36 @@ def parse_transmission(args):
return input_directory, input_name, input_category, input_hash, input_id


def parse_synods(args):
# Synology/Transmission usage: call TorrenToMedia.py (%TR_TORRENT_DIR% %TR_TORRENT_NAME% is passed on as environmental variables)
input_directory = ''
input_id = ''
input_category = ''
input_name = os.getenv('TR_TORRENT_NAME')
input_hash = os.getenv('TR_TORRENT_HASH')
if not input_name: # No info passed. Assume manual download.
return input_directory, input_name, input_category, input_hash, input_id
input_id = 'dbid_{0}'.format(os.getenv('TR_TORRENT_ID'))
#res = core.TORRENT_CLASS.tasks_list(additional_param='detail')
res = core.TORRENT_CLASS.tasks_info(input_id, additional_param='detail')
logger.debug('result from syno {0}'.format(res))
if res['success']:
try:
tasks = res['data']['tasks']
task = [ task for task in tasks if task['id'] == input_id ][0]
input_id = task['id']
input_directory = task['additional']['detail']['destination']
except:
logger.error('unable to find download details in Synology DS')
#Syno paths appear to be relative. Let's test to see if the returned path exists, and if not append to /volume1/
if not os.path.isdir(input_directory):
for root in ['/volume1/', '/volume2/', '/volume3/', '/volume4/']:
if os.path.isdir(os.path.join(root, input_directory)):
input_directory = os.path.join(root, input_directory)
break
return input_directory, input_name, input_category, input_hash, input_id


def parse_vuze(args):
# vuze usage: C:\full\path\to\nzbToMedia\TorrentToMedia.py '%D%N%L%I%K%F'
try:
Expand Down Expand Up @@ -159,6 +190,7 @@ def parse_args(client_agent, args):
'transmission': parse_transmission,
'qbittorrent': parse_qbittorrent,
'vuze': parse_vuze,
'synods': parse_synods,
}

try:
Expand Down
Empty file added libs/custom/syno/__init__.py
Empty file.
Loading

0 comments on commit f5e4ec0

Please sign in to comment.