Merge branch 'nightly' into dev

This commit is contained in:
Clinton Hall 2017-06-13 22:36:42 +09:30 committed by GitHub
commit f467213284
11 changed files with 535 additions and 71 deletions

View file

@ -200,7 +200,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
core.flatten(outputDestination)
# Now check if video files exist in destination:
if sectionName in ["SickBeard", "NzbDrone", "CouchPotato"]:
if sectionName in ["SickBeard", "NzbDrone", "Sonarr", "CouchPotato", "Radarr"]:
numVideos = len(
core.listMediaFiles(outputDestination, media=True, audio=False, meta=False, archives=False))
if numVideos > 0:
@ -214,7 +214,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
# Only these sections can handling failed downloads
# so make sure everything else gets through without the check for failed
if sectionName not in ['CouchPotato', 'SickBeard', 'NzbDrone']:
if sectionName not in ['CouchPotato', 'Radarr', 'SickBeard', 'NzbDrone', 'Sonarr']:
status = 0
logger.info("Calling {0}:{1} to post-process:{2}".format(sectionName, usercat, inputName))
@ -226,10 +226,10 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
if sectionName == 'UserScript':
result = external_script(outputDestination, inputName, inputCategory, section)
elif sectionName == 'CouchPotato':
elif sectionName in ['CouchPotato', 'Radarr']:
result = core.autoProcessMovie().process(sectionName, outputDestination, inputName,
status, clientAgent, inputHash, inputCategory)
elif sectionName in ['SickBeard', 'NzbDrone']:
elif sectionName in ['SickBeard', 'NzbDrone', 'Sonarr']:
if inputHash:
inputHash = inputHash.upper()
result = core.autoProcessTV().processEpisode(sectionName, outputDestination, inputName,

View file

@ -71,6 +71,33 @@
# api key for www.omdbapi.com (used as alternative to imdb)
omdbapikey =
[Radarr]
#### autoProcessing for Movies
#### raCategory - category that gets called for post-processing with Radarr
[[movie]]
enabled = 0
apikey =
host = localhost
port = 7878
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######
web_root =
ssl = 0
delete_failed = 0
# Enable/Disable linking for Torrents
Torrent_NoLink = 0
keep_archive = 1
extract = 1
nzbExtractionBy = Downloader
wait_for = 6
# Set this to minimum required size to consider a media file valid (in MB)
minSize = 0
# Enable/Disable deleting ignored files (samples and invalid media files)
delete_ignored = 0
##### Enable if NzbDrone is on a remote server for this category
remote_path = 0
##### Set to path where download client places completed downloads locally for this category
watch_dir =
[SickBeard]
#### autoProcessing for TV Series
#### tv - category that gets called for post-processing with SB
@ -109,8 +136,9 @@
chmodDirectory = 0
[NzbDrone]
#### Formerly known as NzbDrone this is now Sonarr
#### autoProcessing for TV Series
#### ndCategory - category that gets called for post-processing with NzbDrone
#### ndCategory - category that gets called for post-processing with NzbDrone/Sonarr
[[tv]]
enabled = 0
apikey =
@ -127,7 +155,7 @@
keep_archive = 1
extract = 1
nzbExtractionBy = Downloader
wait_for = 2
wait_for = 6
# Set this to minimum required size to consider a media file valid (in MB)
minSize = 0
# Enable/Disable deleting ignored files (samples and invalid media files)

View file

@ -3,6 +3,7 @@
import os
import time
import requests
import json
import core
from core.nzbToMediaSceneExceptions import process_all_exceptions
@ -20,13 +21,13 @@ class autoProcessMovie(object):
# determine cmd and params to send to CouchPotato to get our results
section = 'movies'
cmd = "/media.list"
cmd = "media.list"
if release_id or imdbid:
section = 'media'
cmd = "/media.get"
cmd = "media.get"
params['id'] = release_id or imdbid
url = baseURL + cmd
url = "{0}{1}".format(baseURL, cmd)
logger.debug("Opening URL: {0} with PARAMS: {1}".format(url, params))
try:
@ -103,6 +104,39 @@ class autoProcessMovie(object):
return results
def command_complete(self, url, params, headers, section):
try:
r = requests.get(url, params=params, headers=headers, stream=True, verify=False, timeout=(30, 60))
except requests.ConnectionError:
logger.error("Unable to open URL: {0}".format(url), section)
return None
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
logger.error("Server returned status {0}".format(r.status_code), section)
return None
else:
try:
return r.json()['state']
except (ValueError, KeyError):
# ValueError catches simplejson's JSONDecodeError and json's ValueError
logger.error("{0} did not return expected json data.".format(section), section)
return None
def CDH(self, url2, headers, section="MAIN"):
try:
r = requests.get(url2, params={}, headers=headers, stream=True, verify=False, timeout=(30, 60))
except requests.ConnectionError:
logger.error("Unable to open URL: {0}".format(url2), section)
return False
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
logger.error("Server returned status {0}".format(r.status_code), section)
return False
else:
try:
return r.json().get("enableCompletedDownloadHandling", False)
except ValueError:
# ValueError catches simplejson's JSONDecodeError and json's ValueError
return False
def process(self, section, dirName, inputName=None, status=0, clientAgent="manual", download_id="", inputCategory=None, failureLink=None):
cfg = dict(core.CFG[section][inputCategory])
@ -110,7 +144,10 @@ class autoProcessMovie(object):
host = cfg["host"]
port = cfg["port"]
apikey = cfg["apikey"]
method = cfg["method"]
if section == "CouchPotato":
method = cfg["method"]
else:
method = None
delete_failed = int(cfg["delete_failed"])
wait_for = int(cfg["wait_for"])
ssl = int(cfg.get("ssl", 0))
@ -124,14 +161,25 @@ class autoProcessMovie(object):
else:
extract = int(cfg.get("extract", 0))
baseURL = "{0}{1}:{2}{3}/api/{4}".format(protocol, host, port, web_root, apikey)
if not server_responding(baseURL):
imdbid = find_imdbid(dirName, inputName)
if section == "CouchPotato":
baseURL = "{0}{1}:{2}{3}/api/{4}/".format(protocol, host, port, web_root, apikey)
if section == "Radarr":
baseURL = "{0}{1}:{2}{3}/api/command".format(protocol, host, port, web_root)
url2 = "{0}{1}:{2}{3}/api/config/downloadClient".format(protocol, host, port, web_root)
headers = {'X-Api-Key': apikey}
if not apikey:
logger.info('No CouchPotato or Radarr apikey entered. Performing transcoder functions only')
release = None
elif server_responding(baseURL):
if section == "CouchPotato":
release = self.get_release(baseURL, imdbid, download_id)
else:
release = None
else:
logger.error("Server did not respond. Exiting", section)
return [1, "{0}: Failed to post-process - {1} did not respond.".format(section, section)]
imdbid = find_imdbid(dirName, inputName, omdbapikey)
release = self.get_release(baseURL, imdbid, download_id)
# pull info from release found if available
release_id = None
media_id = None
@ -216,6 +264,10 @@ class autoProcessMovie(object):
logger.debug('Renaming: {0} to: {1}'.format(video, video2))
os.rename(video, video2)
if not apikey: #If only using Transcoder functions, exit here.
logger.info('No CouchPotato or Radarr apikey entered. Processing completed.')
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
params = {}
if download_id:
params['downloader'] = downloader or clientAgent
@ -223,20 +275,29 @@ class autoProcessMovie(object):
params['media_folder'] = remoteDir(dirName) if remote_path else dirName
if method == "manage":
command = "/manage.update"
params = {}
else:
command = "/renamer.scan"
if section == "CouchPotato":
if method == "manage":
command = "manage.update"
params = {}
else:
command = "renamer.scan"
url = "{0}{1}".format(baseURL, command)
url = "{0}{1}".format(baseURL, command)
logger.debug("Opening URL: {0} with PARAMS: {1}".format(url, params), section)
logger.postprocess("Starting {0} scan for {1}".format(method, inputName), section)
logger.debug("Opening URL: {0} with PARAMS: {1}".format(url, params), section)
logger.postprocess("Starting {0} scan for {1}".format(method, inputName), section)
if section == "Radarr":
payload = {'name': 'DownloadedMoviesScan', 'path': params['media_folder'], 'downloadClientId': download_id}
if not download_id:
payload.pop("downloadClientId")
logger.debug("Opening URL: {0} with PARAMS: {1}".format(baseURL, payload), section)
logger.postprocess("Starting DownloadedMoviesScan scan for {0}".format(inputName), section)
try:
r = requests.get(url, params=params, verify=False, timeout=(30, 1800))
if section == "CouchPotato":
r = requests.get(url, params=params, verify=False, timeout=(30, 1800))
else:
r = requests.post(baseURL, data=json.dumps(payload), headers=headers, stream=True, verify=False, timeout=(30, 1800))
except requests.ConnectionError:
logger.error("Unable to open URL", section)
return [1, "{0}: Failed to post-process - Unable to connect to {1}".format(section, section)]
@ -245,10 +306,20 @@ class autoProcessMovie(object):
if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]:
logger.error("Server returned status {0}".format(r.status_code), section)
return [1, "{0}: Failed to post-process - Server returned status {1}".format(section, r.status_code)]
elif result['success']:
elif section == "CouchPotato" and result['success']:
logger.postprocess("SUCCESS: Finished {0} scan for folder {1}".format(method, dirName), section)
if method == "manage":
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
elif section == "Radarr":
logger.postprocess("Radarr response: {0}".format(result['state']))
try:
res = json.loads(r.content)
scan_id = int(res['id'])
logger.debug("Scan started with id: {0}".format(scan_id), section)
Started = True
except Exception as e:
logger.warning("No scan id was returned due to: {0}".format(e), section)
scan_id = None
else:
logger.error("FAILED: {0} scan was unable to finish for folder {1}. exiting!".format(method, dirName),
section)
@ -260,6 +331,10 @@ class autoProcessMovie(object):
if failureLink:
reportNzb(failureLink, clientAgent)
if section == "Radarr":
logger.postprocess("FAILED: The download failed. Sending failed download to {0} for CDH processing".format(section), section)
return [1, "{0}: Download Failed. Sending back to {1}".format(section, section)] # Return as failed to flag this in the downloader.
if delete_failed and os.path.isdir(dirName) and not os.path.dirname(dirName) == dirName:
logger.postprocess("Deleting failed files and folder {0}".format(dirName), section)
rmDir(dirName)
@ -272,7 +347,7 @@ class autoProcessMovie(object):
if release_id:
logger.postprocess("Setting failed release {0} to ignored ...".format(inputName), section)
url = "{url}/release.ignore".format(url=baseURL)
url = "{url}release.ignore".format(url=baseURL)
params = {'id': release_id}
logger.debug("Opening URL: {0} with PARAMS: {1}".format(url, params), section)
@ -295,7 +370,7 @@ class autoProcessMovie(object):
logger.postprocess("Trying to snatch the next highest ranked release.", section)
url = "{0}/movie.searcher.try_next".format(baseURL)
url = "{0}movie.searcher.try_next".format(baseURL)
logger.debug("Opening URL: {0}".format(url), section)
try:
@ -323,7 +398,11 @@ class autoProcessMovie(object):
timeout = time.time() + 60 * wait_for
while time.time() < timeout: # only wait 2 (default) minutes, then return.
logger.postprocess("Checking for status change, please stand by ...", section)
release = self.get_release(baseURL, imdbid, download_id, release_id)
if section == "CouchPotato":
release = self.get_release(baseURL, imdbid, download_id, release_id)
scan_id = None
else:
release = None
if release:
try:
if release_id is None and release_status_old is None: # we didn't have a release before, but now we do.
@ -337,6 +416,18 @@ class autoProcessMovie(object):
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
except:
pass
elif scan_id:
url = "{0}/{1}".format(baseURL, scan_id)
command_status = self.command_complete(url, params, headers, section)
if command_status:
logger.debug("The Scan command return status: {0}".format(command_status), section)
if command_status in ['completed']:
logger.debug("The Scan command has completed successfully. Renaming was successful.", section)
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
elif command_status in ['failed']:
logger.debug("The Scan command has failed. Renaming was not successful.", section)
# return [1, "%s: Failed to post-process %s" % (section, inputName) ]
if not os.path.isdir(dirName):
logger.postprocess("SUCCESS: Input Directory [{0}] has been processed and removed".format(
dirName), section)
@ -347,10 +438,13 @@ class autoProcessMovie(object):
dirName), section)
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
# pause and let CouchPotatoServer catch its breath
# pause and let CouchPotatoServer/Radarr catch its breath
time.sleep(10 * wait_for)
# The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resume seeding now.
# The status hasn't changed. we have waited wait_for minutes which is more than enough. uTorrent can resume seeding now.
if section == "Radarr" and self.CDH(url2, headers, section=section):
logger.debug("The Scan command did not return status completed, but complete Download Handling is enabled. Passing back to {0}.".format(section), section)
return [status, "{0}: Complete DownLoad Handling is enabled. Passing back to {1}".format(section, section)]
logger.warning(
"{0} does not appear to have changed status after {1} minutes, Please check your logs.".format(inputName, wait_for),
section)

View file

@ -60,17 +60,20 @@ class autoProcessTV(object):
ssl = int(cfg.get("ssl", 0))
web_root = cfg.get("web_root", "")
protocol = "https://" if ssl else "http://"
if not server_responding("{0}{1}:{2}{3}".format(protocol, host, port, web_root)):
logger.error("Server did not respond. Exiting", section)
return [1, "{0}: Failed to post-process - {1} did not respond.".format(section, section)]
# auto-detect correct fork
fork, fork_params = autoFork(section, inputCategory)
username = cfg.get("username", "")
password = cfg.get("password", "")
apikey = cfg.get("apikey", "")
if server_responding("{0}{1}:{2}{3}".format(protocol, host, port, web_root)):
# auto-detect correct fork
fork, fork_params = autoFork(section, inputCategory)
elif not username and not apikey:
logger.info('No SickBeard username or Sonarr apikey entered. Performing transcoder functions only')
fork, fork_params = "None", {}
else:
logger.error("Server did not respond. Exiting", section)
return [1, "{0}: Failed to post-process - {1} did not respond.".format(section, section)]
delete_failed = int(cfg.get("delete_failed", 0))
nzbExtractionBy = cfg.get("nzbExtractionBy", "Downloader")
process_method = cfg.get("process_method")
@ -223,6 +226,9 @@ class autoProcessTV(object):
[fork_params.pop(k) for k, v in fork_params.items() if v is None]
if status == 0:
if section == "NzbDrone" and not apikey:
logger.info('No Sonarr apikey entered. Processing completed.')
return [0, "{0}: Successfully post-processed {1}".format(section, inputName)]
logger.postprocess("SUCCESS: The download succeeded, sending a post-process request", section)
else:
core.FAILED = True

View file

@ -142,7 +142,7 @@ class ConfigObj(configobj.ConfigObj, Section):
if CFG_OLD[section].sections:
subsections.update({section: CFG_OLD[section].sections})
for option, value in CFG_OLD[section].items():
if option in ["category", "cpsCategory", "sbCategory", "hpCategory", "mlCategory", "gzCategory"]:
if option in ["category", "cpsCategory", "sbCategory", "hpCategory", "mlCategory", "gzCategory", "raCategory", "ndCategory"]:
if not isinstance(value, list):
value = [value]
@ -255,10 +255,14 @@ class ConfigObj(configobj.ConfigObj, Section):
try:
if 'NZBPO_NDCATEGORY' in os.environ and 'NZBPO_SBCATEGORY' in os.environ:
if os.environ['NZBPO_NDCATEGORY'] == os.environ['NZBPO_SBCATEGORY']:
logger.warning("{x} category is set for SickBeard and NzbDrone. "
logger.warning("{x} category is set for SickBeard and Sonarr. "
"Please check your config in NZBGet".format
(x=os.environ['NZBPO_NDCATEGORY']))
if 'NZBPO_RACATEGORY' in os.environ and 'NZBPO_CPSCATEGORY' in os.environ:
if os.environ['NZBPO_RACATEGORY'] == os.environ['NZBPO_CPSCATEGORY']:
logger.warning("{x} category is set for CouchPotato and Radarr. "
"Please check your config in NZBGet".format
(x=os.environ['NZBPO_RACATEGORY']))
section = "Nzb"
key = 'NZBOP_DESTDIR'
if key in os.environ:
@ -302,6 +306,8 @@ class ConfigObj(configobj.ConfigObj, Section):
CFG_NEW[section][os.environ[envCatKey]] = {}
CFG_NEW[section][os.environ[envCatKey]][option] = value
CFG_NEW[section][os.environ[envCatKey]]['enabled'] = 1
if os.environ[envCatKey] in CFG_NEW['Radarr'].sections:
CFG_NEW['Radarr'][envCatKey]['enabled'] = 0
section = "SickBeard"
envCatKey = 'NZBPO_SBCATEGORY'
@ -388,6 +394,25 @@ class ConfigObj(configobj.ConfigObj, Section):
if os.environ[envCatKey] in CFG_NEW['SickBeard'].sections:
CFG_NEW['SickBeard'][envCatKey]['enabled'] = 0
section = "Radarr"
envCatKey = 'NZBPO_RACATEGORY'
envKeys = ['ENABLED', 'HOST', 'APIKEY', 'PORT', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'FORK', 'DELETE_FAILED',
'TORRENT_NOLINK', 'NZBEXTRACTIONBY', 'WAIT_FOR', 'DELETE_FAILED', 'REMOTE_PATH']
cfgKeys = ['enabled', 'host', 'apikey', 'port', 'ssl', 'web_root', 'watch_dir', 'fork', 'delete_failed',
'Torrent_NoLink', 'nzbExtractionBy', 'wait_for', 'delete_failed', 'remote_path']
if envCatKey in os.environ:
for index in range(len(envKeys)):
key = 'NZBPO_RA{index}'.format(index=envKeys[index])
if key in os.environ:
option = cfgKeys[index]
value = os.environ[key]
if os.environ[envCatKey] not in CFG_NEW[section].sections:
CFG_NEW[section][os.environ[envCatKey]] = {}
CFG_NEW[section][os.environ[envCatKey]][option] = value
CFG_NEW[section][os.environ[envCatKey]]['enabled'] = 1
if os.environ[envCatKey] in CFG_NEW['CouchPotato'].sections:
CFG_NEW['CouchPotato'][envCatKey]['enabled'] = 0
section = "Extensions"
envKeys = ['COMPRESSEDEXTENSIONS', 'MEDIAEXTENSIONS', 'METAEXTENSIONS']
cfgKeys = ['compressedExtensions', 'mediaExtensions', 'metaExtensions']

View file

@ -61,6 +61,8 @@ def strip_groups(filename):
def rename_file(filename, newfilePath):
if os.path.isfile(newfilePath):
newfilePath = os.path.splitext(newfilePath)[0] + ".NTM" + os.path.splitext(newfilePath)[1]
logger.debug("Replacing file name {old} with download name {new}".format
(old=filename, new=newfilePath), "EXCEPTION")
try:

View file

@ -195,7 +195,7 @@ def getDirSize(inputPath):
from functools import partial
prepend = partial(os.path.join, inputPath)
return sum(
[(os.path.getsize(f) if os.path.isfile(f) else getDirSize(f)) for f in map(prepend, os.listdir(inputPath))])
[(os.path.getsize(f) if os.path.isfile(f) else getDirSize(f)) for f in map(prepend, os.listdir(unicode(inputPath)))])
def is_minSize(inputName, minSize):
@ -322,7 +322,7 @@ def removeEmptyFolders(path, removeRoot=True):
# remove empty subfolders
logger.debug("Checking for empty folders in:{0}".format(path))
files = os.listdir(path)
files = os.listdir(unicode(path))
if len(files):
for f in files:
fullpath = os.path.join(path, f)
@ -330,7 +330,7 @@ def removeEmptyFolders(path, removeRoot=True):
removeEmptyFolders(fullpath)
# if folder empty, delete it
files = os.listdir(path)
files = os.listdir(unicode(path))
if len(files) == 0 and removeRoot:
logger.debug("Removing empty folder:{}".format(path))
os.rmdir(path)
@ -607,9 +607,9 @@ def getDirs(section, subsection, link='hard'):
folders = []
logger.info("Searching {0} for mediafiles to post-process ...".format(path))
sync = [o for o in os.listdir(path) if os.path.splitext(o)[1] in ['.!sync', '.bts']]
sync = [o for o in os.listdir(unicode(path)) if os.path.splitext(o)[1] in ['.!sync', '.bts']]
# search for single files and move them into their own folder for post-processing
for mediafile in [os.path.join(path, o) for o in os.listdir(path) if
for mediafile in [os.path.join(path, o) for o in os.listdir(unicode(path)) if
os.path.isfile(os.path.join(path, o))]:
if len(sync) > 0:
break
@ -673,11 +673,11 @@ def getDirs(section, subsection, link='hard'):
# removeEmptyFolders(path, removeRoot=False)
if os.listdir(path):
for dir in [os.path.join(path, o) for o in os.listdir(path) if
if os.listdir(unicode(path)):
for dir in [os.path.join(path, o) for o in os.listdir(unicode(path)) if
os.path.isdir(os.path.join(path, o))]:
sync = [o for o in os.listdir(dir) if os.path.splitext(o)[1] in ['.!sync', '.bts']]
if len(sync) > 0 or len(os.listdir(dir)) == 0:
sync = [o for o in os.listdir(unicode(dir)) if os.path.splitext(o)[1] in ['.!sync', '.bts']]
if len(sync) > 0 or len(os.listdir(unicode(dir))) == 0:
continue
folders.extend([dir])
return folders
@ -728,7 +728,7 @@ def onerror(func, path, exc_info):
def rmDir(dirName):
logger.info("Deleting {0}".format(dirName))
try:
shutil.rmtree(dirName, onerror=onerror)
shutil.rmtree(unicode(dirName), onerror=onerror)
except:
logger.error("Unable to delete folder {0}".format(dirName))
@ -994,7 +994,7 @@ def listMediaFiles(path, minSize=0, delete_ignored=0, media=True, audio=True, me
return files
for curFile in os.listdir(path):
for curFile in os.listdir(unicode(path)):
fullCurFile = os.path.join(path, curFile)
# if it's a folder do it recursively
@ -1031,7 +1031,7 @@ def find_imdbid(dirName, inputName, omdbApiKey):
logger.info("Found imdbID [{0}]".format(imdbid))
return imdbid
if os.path.isdir(dirName):
for file in os.listdir(dirName):
for file in os.listdir(unicode(dirName)):
m = re.search('(tt\d{7})', file)
if m:
imdbid = m.group(1)
@ -1047,7 +1047,10 @@ def find_imdbid(dirName, inputName, omdbApiKey):
logger.info("Found imdbID [{0}] from DNZB-MoreInfo".format(imdbid))
return imdbid
logger.info('Searching IMDB for imdbID ...')
guess = guessit.guessit(inputName)
try:
guess = guessit.guessit(inputName)
except:
guess = None
if guess:
# Movie Title
title = None
@ -1072,12 +1075,15 @@ def find_imdbid(dirName, inputName, omdbApiKey):
logger.error("Unable to open URL {0}".format(url))
return
results = r.json()
try:
results = r.json()
except:
logger.error("No json data returned from omdbapi.com")
try:
imdbid = results['imdbID']
except:
pass
logger.error("No imdbID returned from omdbapi.com")
if imdbid:
logger.info("Found imdbID [{0}]".format(imdbid))

View file

@ -115,9 +115,9 @@ def getVideoDetails(videofile, img=None, bitbucket=None):
def buildCommands(file, newDir, movieName, bitbucket):
if isinstance(file, str):
if isinstance(file, basestring):
inputFile = file
if '"concat:' in file:
if 'concat:' in file:
file = file.split('|')[0].replace('concat:', '')
video_details, result = getVideoDetails(file)
dir, name = os.path.split(file)
@ -254,7 +254,15 @@ def buildCommands(file, newDir, movieName, bitbucket):
used_audio = 0
a_mapped = []
commentary = []
if audioStreams:
for i, val in reversed(list(enumerate(audioStreams))):
try:
if "Commentary" in val.get("tags").get("title"): # Split out commentry tracks.
commentary.append(val)
del audioStreams[i]
except:
continue
try:
audio1 = [item for item in audioStreams if item["tags"]["language"] == core.ALANGUAGE]
except: # no language tags. Assume only 1 language.
@ -374,6 +382,7 @@ def buildCommands(file, newDir, movieName, bitbucket):
audio_cmd.extend(audio_cmd2)
if core.AINCLUDE and core.ACODEC3:
audioStreams.extend(commentary) #add commentry tracks back here.
for audio in audioStreams:
if audio["index"] in a_mapped:
continue
@ -463,6 +472,10 @@ def buildCommands(file, newDir, movieName, bitbucket):
sub_details, result = getVideoDetails(subfile)
if not sub_details or not sub_details.get("streams"):
continue
if core.SCODEC == "mov_text":
subcode = [stream["codec_name"] for stream in sub_details["streams"]]
if set(subcode).intersection(["dvd_subtitle", "VobSub"]): # We can't convert these.
continue
command.extend(['-i', subfile])
lan = os.path.splitext(os.path.splitext(subfile)[0])[1][1:].split('-')[0]
metlan = None
@ -601,7 +614,7 @@ def processList(List, newDir, bitbucket):
if combine:
newList.extend(combineCD(combine))
for file in newList:
if isinstance(file, str) and 'concat:' not in file and not os.path.isfile(file):
if isinstance(file, basestring) and 'concat:' not in file and not os.path.isfile(file):
success = False
break
if success and newList:
@ -736,13 +749,13 @@ def Transcode_directory(dirName):
return 1, dirName
for file in List:
if isinstance(file, str) and os.path.splitext(file)[1] in core.IGNOREEXTENSIONS:
if isinstance(file, basestring) and os.path.splitext(file)[1] in core.IGNOREEXTENSIONS:
continue
command = buildCommands(file, newDir, movieName, bitbucket)
newfilePath = command[-1]
# transcoding files may remove the original file, so make sure to extract subtitles first
if core.SEXTRACT and isinstance(file, str):
if core.SEXTRACT and isinstance(file, basestring):
extract_subs(file, newfilePath, bitbucket)
try: # Try to remove the file that we're transcoding to just in case. (ffmpeg will return an error if it already exists for some reason)
@ -757,7 +770,7 @@ def Transcode_directory(dirName):
print_cmd(command)
result = 1 # set result to failed in case call fails.
try:
if isinstance(file, str):
if isinstance(file, basestring):
proc = subprocess.Popen(command, stdout=bitbucket, stderr=bitbucket)
else:
img, data = iteritems(file).next()
@ -772,7 +785,7 @@ def Transcode_directory(dirName):
except:
logger.error("Transcoding of video {0} has failed".format(newfilePath))
if core.SUBSDIR and result == 0 and isinstance(file, str):
if core.SUBSDIR and result == 0 and isinstance(file, basestring):
for sub in get_subs(file):
name = os.path.splitext(os.path.split(file)[1])[0]
subname = os.path.split(sub)[1]
@ -802,7 +815,7 @@ def Transcode_directory(dirName):
os.unlink(file)
except:
pass
if not os.listdir(newDir): # this is an empty directory and we didn't transcode into it.
if not os.listdir(unicode(newDir)): # this is an empty directory and we didn't transcode into it.
os.rmdir(newDir)
newDir = dirName
if not core.PROCESSOUTPUT and core.DUPLICATE: # We postprocess the original files to CP/SB

View file

@ -83,6 +83,49 @@
# Enable to replace local path with the path as per the mountPoints below.
#cpsremote_path=0
## Radarr
# Radarr script category.
#
# category that gets called for post-processing with NzbDrone.
#raCategory=movies2
# Radarr host.
#
# The ipaddress for your Radarr server. e.g For the Same system use localhost or 127.0.0.1
#rahost=localhost
# Radarr port.
#raport=7878
# Radarr API key.
#raapikey=
# Radarr uses ssl (0, 1).
#
# Set to 1 if using ssl, else set to 0.
#rassl=0
# Radarr web_root
#
# set this if using a reverse proxy.
#raweb_root=
# Radarr wait_for
#
# Set the number of minutes to wait after calling the renamer, to check the episode has changed status.
#rawait_for=6
# Radarr Delete Failed Downloads (0, 1).
#
# set to 1 to delete failed, or 0 to leave files in place.
#radelete_failed=0
# Radarr and NZBGet are a different system (0, 1).
#
# Enable to replace local path with the path as per the mountPoints below.
#raremote_path=0
## SickBeard
# SickBeard script category.
@ -175,7 +218,7 @@
# NzbDrone wait_for
#
# Set the number of minutes to wait after calling the renamer, to check the episode has changed status.
#ndwait_for=2
#ndwait_for=6
# NzbDrone Delete Failed Downloads (0, 1).
#
@ -613,10 +656,10 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down
logger.info("Calling {0}:{1} to post-process:{2}".format(sectionName, inputCategory, inputName))
if sectionName == "CouchPotato":
if sectionName in ["CouchPotato", "Radarr"]:
result = autoProcessMovie().process(sectionName, inputDirectory, inputName, status, clientAgent, download_id,
inputCategory, failureLink)
elif sectionName in ["SickBeard", "NzbDrone"]:
elif sectionName in ["SickBeard", "NzbDrone", "Sonarr"]:
result = autoProcessTV().processEpisode(sectionName, inputDirectory, inputName, status, clientAgent,
download_id, inputCategory, failureLink)
elif sectionName == "HeadPhones":
@ -637,7 +680,7 @@ def process(inputDirectory, inputName=None, status=0, clientAgent='manual', down
if clientAgent != 'manual':
# update download status in our DB
update_downloadInfoStatus(inputName, 1)
if sectionName not in ['UserScript', 'NzbDrone']:
if sectionName not in ['UserScript', 'NzbDrone', 'Sonarr', 'Radarr']:
# cleanup our processing folders of any misc unwanted files and empty directories
cleanDir(inputDirectory, sectionName, inputCategory)
@ -708,6 +751,8 @@ def main(args, section=None):
download_id = os.environ['NZBPR_DRONE']
elif 'NZBPR_SONARR' in os.environ:
download_id = os.environ['NZBPR_SONARR']
elif 'NZBPR_RADARR' in os.environ:
download_id = os.environ['NZBPR_RADARR']
if 'NZBPR__DNZB_FAILURE' in os.environ:
failureLink = os.environ['NZBPR__DNZB_FAILURE']

View file

@ -4,7 +4,7 @@
##############################################################################
### NZBGET POST-PROCESSING SCRIPT ###
# Post-Process to NzbDrone.
# Post-Process to NzbDrone/Sonarr.
#
# This script sends the download to your automated media management servers.
#
@ -66,7 +66,7 @@
# NzbDrone wait_for
#
# Set the number of minutes to wait after calling the renamer, to check the episode has changed status.
#ndwait_for=2
#ndwait_for=6
# NzbDrone Delete Failed Downloads (0, 1).
#

245
nzbToRadarr.py Executable file
View file

@ -0,0 +1,245 @@
#!/usr/bin/env python2
# coding=utf-8
#
##############################################################################
### NZBGET POST-PROCESSING SCRIPT ###
# Post-Process to Radarr.
#
# This script sends the download to your automated media management servers.
#
# NOTE: This script requires Python to be installed on your system.
##############################################################################
### OPTIONS ###
## General
# Auto Update nzbToMedia (0, 1).
#
# Set to 1 if you want nzbToMedia to automatically check for and update to the latest version
#auto_update=0
# Check Media for corruption (0, 1).
#
# Enable/Disable media file checking using ffprobe.
#check_media=1
# Safe Mode protection of DestDir (0, 1).
#
# Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake.
#safe_mode=1
# Disable additional extraction checks for failed (0, 1).
#
# Turn this on to disable additional extraction attempts for failed downloads. Default = 0 this will attempt to extract and verify if media is present.
#no_extract_failed = 0
## Radarr
# Radarr script category.
#
# category that gets called for post-processing with NzbDrone.
#raCategory=movies2
# Radarr host.
#
# The ipaddress for your Radarr server. e.g For the Same system use localhost or 127.0.0.1
#rahost=localhost
# Radarr port.
#raport=7878
# Radarr API key.
#raapikey=
# Radarr uses ssl (0, 1).
#
# Set to 1 if using ssl, else set to 0.
#rassl=0
# Radarr web_root
#
# set this if using a reverse proxy.
#raweb_root=
# Radarr wait_for
#
# Set the number of minutes to wait after calling the renamer, to check the episode has changed status.
#rawait_for=6
# Radarr Delete Failed Downloads (0, 1).
#
# set to 1 to delete failed, or 0 to leave files in place.
#radelete_failed=0
# Radarr and NZBGet are a different system (0, 1).
#
# Enable to replace local path with the path as per the mountPoints below.
#raremote_path=0
## Network
# Network Mount Points (Needed for remote path above)
#
# Enter Mount points as LocalPath,RemotePath and separate each pair with '|'
# e.g. mountPoints=/volume1/Public/,E:\|/volume2/share/,\\NAS\
#mountPoints=
## Extensions
# Media Extensions
#
# This is a list of media extensions that are used to verify that the download does contain valid media.
#mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso,.ts
## Posix
# Niceness for external tasks Extractor and Transcoder.
#
# Set the Niceness value for the nice command. These range from -20 (most favorable to the process) to 19 (least favorable to the process).
#niceness=10
# ionice scheduling class (0, 1, 2, 3).
#
# Set the ionice scheduling class. 0 for none, 1 for real time, 2 for best-effort, 3 for idle.
#ionice_class=2
# ionice scheduling class data.
#
# Set the ionice scheduling class data. This defines the class data, if the class accepts an argument. For real time and best-effort, 0-7 is valid data.
#ionice_classdata=4
## Transcoder
# getSubs (0, 1).
#
# set to 1 to download subtitles.
#getSubs = 0
# subLanguages.
#
# subLanguages. create a list of languages in the order you want them in your subtitles.
#subLanguages = eng,spa,fra
# Transcode (0, 1).
#
# set to 1 to transcode, otherwise set to 0.
#transcode=0
# create a duplicate, or replace the original (0, 1).
#
# set to 1 to cretae a new file or 0 to replace the original
#duplicate=1
# ignore extensions.
#
# list of extensions that won't be transcoded.
#ignoreExtensions=.avi,.mkv
# outputFastStart (0,1).
#
# outputFastStart. 1 will use -movflags + faststart. 0 will disable this from being used.
#outputFastStart = 0
# outputVideoPath.
#
# outputVideoPath. Set path you want transcoded videos moved to. Leave blank to disable.
#outputVideoPath =
# processOutput (0,1).
#
# processOutput. 1 will send the outputVideoPath to SickBeard/CouchPotato. 0 will send original files.
#processOutput = 0
# audioLanguage.
#
# audioLanguage. set the 3 letter language code you want as your primary audio track.
#audioLanguage = eng
# allAudioLanguages (0,1).
#
# allAudioLanguages. 1 will keep all audio tracks (uses AudioCodec3) where available.
#allAudioLanguages = 0
# allSubLanguages (0,1).
#
# allSubLanguages. 1 will keep all exisiting sub languages. 0 will discare those not in your list above.
#allSubLanguages = 0
# embedSubs (0,1).
#
# embedSubs. 1 will embded external sub/srt subs into your video if this is supported.
#embedSubs = 1
# burnInSubtitle (0,1).
#
# burnInSubtitle. burns the default sub language into your video (needed for players that don't support subs)
#burnInSubtitle = 0
# extractSubs (0,1).
#
# extractSubs. 1 will extract subs from the video file and save these as external srt files.
#extractSubs = 0
# externalSubDir.
#
# externalSubDir. set the directory where subs should be saved (if not the same directory as the video)
#externalSubDir =
# outputDefault (None, iPad, iPad-1080p, iPad-720p, Apple-TV2, iPod, iPhone, PS3, xbox, Roku-1080p, Roku-720p, Roku-480p, mkv, mp4-scene-release, MKV-SD).
#
# outputDefault. Loads default configs for the selected device. The remaining options below are ignored.
# If you want to use your own profile, set None and set the remaining options below.
#outputDefault = None
# hwAccel (0,1).
#
# hwAccel. 1 will set ffmpeg to enable hardware acceleration (this requires a recent ffmpeg).
#hwAccel=0
# ffmpeg output settings.
#outputVideoExtension=.mp4
#outputVideoCodec=libx264
#VideoCodecAllow =
#outputVideoResolution=720:-1
#outputVideoPreset=medium
#outputVideoFramerate=24
#outputVideoBitrate=800k
#outputAudioCodec=libmp3lame
#AudioCodecAllow =
#outputAudioBitrate=128k
#outputQualityPercent = 0
#outputAudioTrack2Codec = libfaac
#AudioCodec2Allow =
#outputAudioTrack2Bitrate = 128k
#outputAudioOtherCodec = libmp3lame
#AudioOtherCodecAllow =
#outputAudioOtherBitrate = 128k
#outputSubtitleCodec =
## WakeOnLan
# use WOL (0, 1).
#
# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified.
#wolwake=0
# WOL MAC
#
# enter the mac address of the system to be woken.
#wolmac=00:01:2e:2D:64:e1
# Set the Host and Port of a server to verify system has woken.
#wolhost=192.168.1.37
#wolport=80
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
import sys
import nzbToMedia
section = "Radarr"
result = nzbToMedia.main(sys.argv, section)
sys.exit(result)