mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-19 21:03:14 -07:00
Added NZB_CLIENTAGENT and TORRENT_CLIENTAGENT variables to compliment adding in Nzb client API support for SabNZBD and NzbGet.
Partially added in searching for downloads via download client API calls, more work to be done on this. NZB Client users but set there client in the cfg, either sabnzbd or nzbget. Cleaned up some more of the code in TorrentToMedia and nzbToMedia.
This commit is contained in:
parent
8d2049cb14
commit
504ea8ac45
7 changed files with 160 additions and 139 deletions
|
@ -16,7 +16,7 @@ from nzbtomedia.autoProcess.autoProcessMusic import autoProcessMusic
|
||||||
from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV
|
from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV
|
||||||
from nzbtomedia.extractor import extractor
|
from nzbtomedia.extractor import extractor
|
||||||
from nzbtomedia.nzbToMediaUtil import category_search, safeName, is_sample, copy_link, parse_args, flatten, get_dirnames, \
|
from nzbtomedia.nzbToMediaUtil import category_search, safeName, is_sample, copy_link, parse_args, flatten, get_dirnames, \
|
||||||
remove_read_only, cleanup_directories, create_torrent_class
|
remove_read_only, cleanup_directories, create_torrent_class, pause_torrent, resume_torrent
|
||||||
from nzbtomedia import logger
|
from nzbtomedia import logger
|
||||||
|
|
||||||
def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent):
|
def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent):
|
||||||
|
@ -215,41 +215,6 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
cleanup_directories(inputCategory, processCategories, result, outputDestination)
|
cleanup_directories(inputCategory, processCategories, result, outputDestination)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def pause_torrent(clientAgent, TorrentClass, inputHash, inputID, inputName):
|
|
||||||
# if we are using links with Torrents it means we need to pause it in order to access the files
|
|
||||||
logger.debug("Stoping torrent %s in %s while processing", inputName, clientAgent)
|
|
||||||
if clientAgent == 'utorrent' and TorrentClass != "":
|
|
||||||
TorrentClass.stop(inputHash)
|
|
||||||
if clientAgent == 'transmission' and TorrentClass !="":
|
|
||||||
TorrentClass.stop_torrent(inputID)
|
|
||||||
if clientAgent == 'deluge' and TorrentClass != "":
|
|
||||||
TorrentClass.core.pause_torrent([inputID])
|
|
||||||
time.sleep(5) # Give Torrent client some time to catch up with the change
|
|
||||||
|
|
||||||
def resume_torrent(clientAgent, TorrentClass, inputHash, inputID, result, inputName):
|
|
||||||
# Hardlink solution for uTorrent, need to implent support for deluge, transmission
|
|
||||||
if clientAgent in ['utorrent', 'transmission', 'deluge'] and inputHash:
|
|
||||||
# Delete torrent and torrentdata from Torrent client if processing was successful.
|
|
||||||
if (int(nzbtomedia.CFG["Torrent"]["deleteOriginal"]) is 1 and result != 1) or nzbtomedia.USELINK == 'move': # if we move files, nothing to resume seeding.
|
|
||||||
logger.debug("Deleting torrent %s from %s", inputName, clientAgent)
|
|
||||||
if clientAgent == 'utorrent' and TorrentClass != "":
|
|
||||||
TorrentClass.removedata(inputHash)
|
|
||||||
TorrentClass.remove(inputHash)
|
|
||||||
if clientAgent == 'transmission' and TorrentClass !="":
|
|
||||||
TorrentClass.remove_torrent(inputID, True)
|
|
||||||
if clientAgent == 'deluge' and TorrentClass != "":
|
|
||||||
TorrentClass.core.remove_torrent(inputID, True)
|
|
||||||
# we always want to resume seeding, for now manually find out what is wrong when extraction fails
|
|
||||||
else:
|
|
||||||
logger.debug("Starting torrent %s in %s", inputName, clientAgent)
|
|
||||||
if clientAgent == 'utorrent' and TorrentClass != "":
|
|
||||||
TorrentClass.start(inputHash)
|
|
||||||
if clientAgent == 'transmission' and TorrentClass !="":
|
|
||||||
TorrentClass.start_torrent(inputID)
|
|
||||||
if clientAgent == 'deluge' and TorrentClass != "":
|
|
||||||
TorrentClass.core.resume_torrent([inputID])
|
|
||||||
time.sleep(5)
|
|
||||||
|
|
||||||
def external_script(outputDestination, torrentName, torrentLabel):
|
def external_script(outputDestination, torrentName, torrentLabel):
|
||||||
|
|
||||||
final_result = int(0) # start at 0.
|
final_result = int(0) # start at 0.
|
||||||
|
@ -327,8 +292,11 @@ def main(args):
|
||||||
# Initialize the config
|
# Initialize the config
|
||||||
nzbtomedia.initialize()
|
nzbtomedia.initialize()
|
||||||
|
|
||||||
|
# clientAgent for Torrents
|
||||||
|
clientAgent = nzbtomedia.TORRENT_CLIENTAGENT
|
||||||
|
|
||||||
logger.postprocess("#########################################################")
|
logger.postprocess("#########################################################")
|
||||||
logger.postprocess("## ..::[%s]::.. :: STARTING", os.path.splitext(os.path.basename(os.path.normpath(os.path.abspath(__file__))))[0])
|
logger.postprocess("## ..::[%s]::.. CLIENT:%s ## STARTING", args[0], clientAgent)
|
||||||
logger.postprocess("#########################################################")
|
logger.postprocess("#########################################################")
|
||||||
|
|
||||||
# debug command line options
|
# debug command line options
|
||||||
|
@ -337,8 +305,6 @@ def main(args):
|
||||||
# Post-Processing Result
|
# Post-Processing Result
|
||||||
result = 0
|
result = 0
|
||||||
|
|
||||||
# clientAgent for Torrents
|
|
||||||
clientAgent = nzbtomedia.CLIENTAGENT
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
inputDirectory, inputName, inputCategory, inputHash, inputID = parse_args(clientAgent, args)
|
inputDirectory, inputName, inputCategory, inputHash, inputID = parse_args(clientAgent, args)
|
||||||
|
@ -346,10 +312,14 @@ def main(args):
|
||||||
logger.error("There was a problem loading variables")
|
logger.error("There was a problem loading variables")
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
# check if this is a manual run
|
if inputDirectory and inputName and inputHash and inputID:
|
||||||
if inputDirectory is None:
|
result = processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent)
|
||||||
clientAgent = 'manual'
|
else:
|
||||||
|
# Perform Manual Run
|
||||||
logger.warning("Invalid number of arguments received from client, Switching to manual run mode ...")
|
logger.warning("Invalid number of arguments received from client, Switching to manual run mode ...")
|
||||||
|
|
||||||
|
# Loop and auto-process
|
||||||
|
clientAgent = 'manual'
|
||||||
for section, subsection in nzbtomedia.SUBSECTIONS.items():
|
for section, subsection in nzbtomedia.SUBSECTIONS.items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if nzbtomedia.CFG[section][category].isenabled():
|
if nzbtomedia.CFG[section][category].isenabled():
|
||||||
|
@ -362,10 +332,12 @@ def main(args):
|
||||||
logger.error("A problem was reported when trying to manually run %s:%s.", section, category)
|
logger.error("A problem was reported when trying to manually run %s:%s.", section, category)
|
||||||
else:
|
else:
|
||||||
logger.warning("%s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, category)
|
logger.warning("%s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ...", section, category)
|
||||||
else:
|
|
||||||
result = processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent)
|
|
||||||
|
|
||||||
logger.postprocess("All done.")
|
if result == 0:
|
||||||
|
logger.postprocess("The %s script completed successfully.", args[0])
|
||||||
|
else:
|
||||||
|
logger.error("A problem was reported in the %s script.", args[0])
|
||||||
|
|
||||||
sys.exit(result)
|
sys.exit(result)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -121,6 +121,14 @@
|
||||||
##### Set to path where download client places completed downloads locally for this category
|
##### Set to path where download client places completed downloads locally for this category
|
||||||
watch_dir =
|
watch_dir =
|
||||||
|
|
||||||
|
[Nzb]
|
||||||
|
###### clientAgent - Supported clients: sabnzbd, nzbget
|
||||||
|
clientAgent = sabnzbd
|
||||||
|
###### SabNZBD (You must edit this if your using nzbToMedia.py with SabNZBD)
|
||||||
|
sabnzbd_host = localhost
|
||||||
|
sabnzbd_port = 8080
|
||||||
|
sabnzbd_apikey =
|
||||||
|
|
||||||
[Torrent]
|
[Torrent]
|
||||||
###### clientAgent - Supported clients: utorrent, transmission, deluge, rtorrent, other
|
###### clientAgent - Supported clients: utorrent, transmission, deluge, rtorrent, other
|
||||||
clientAgent = other
|
clientAgent = other
|
||||||
|
|
|
@ -318,8 +318,11 @@ def main(args, section=None):
|
||||||
# Initialize the config
|
# Initialize the config
|
||||||
nzbtomedia.initialize(section)
|
nzbtomedia.initialize(section)
|
||||||
|
|
||||||
|
# clientAgent for NZBs
|
||||||
|
clientAgent = nzbtomedia.NZB_CLIENTAGENT
|
||||||
|
|
||||||
logger.postprocess("#########################################################")
|
logger.postprocess("#########################################################")
|
||||||
logger.postprocess("## ..::[%s]::.. :: STARTING", os.path.splitext(os.path.basename(os.path.normpath(os.path.abspath(__file__))))[0])
|
logger.postprocess("## ..::[%s]::.. CLIENT:%s ## STARTING", args[0], clientAgent)
|
||||||
logger.postprocess("#########################################################")
|
logger.postprocess("#########################################################")
|
||||||
|
|
||||||
# debug command line options
|
# debug command line options
|
||||||
|
@ -329,6 +332,7 @@ def main(args, section=None):
|
||||||
result = 0
|
result = 0
|
||||||
status = 0
|
status = 0
|
||||||
|
|
||||||
|
|
||||||
# NZBGet V11+
|
# NZBGet V11+
|
||||||
# Check if the script is called from nzbget 11.0 or later
|
# Check if the script is called from nzbget 11.0 or later
|
||||||
if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5] < '11.0':
|
if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5] < '11.0':
|
||||||
|
@ -376,7 +380,8 @@ def main(args, section=None):
|
||||||
download_id = os.environ['NZBPR_COUCHPOTATO']
|
download_id = os.environ['NZBPR_COUCHPOTATO']
|
||||||
|
|
||||||
# All checks done, now launching the script.
|
# All checks done, now launching the script.
|
||||||
result = process(os.environ['NZBPP_DIRECTORY'], inputName=os.environ['NZBPP_NZBFILENAME'], status=status, clientAgent = "nzbget", download_id=download_id, inputCategory=os.environ['NZBPP_CATEGORY'])
|
clientAgent = 'nzbget'
|
||||||
|
result = process(os.environ['NZBPP_DIRECTORY'], inputName=os.environ['NZBPP_NZBFILENAME'], status=status, clientAgent=clientAgent, download_id=download_id, inputCategory=os.environ['NZBPP_CATEGORY'])
|
||||||
# SABnzbd Pre 0.7.17
|
# SABnzbd Pre 0.7.17
|
||||||
elif len(args) == nzbtomedia.SABNZB_NO_OF_ARGUMENTS:
|
elif len(args) == nzbtomedia.SABNZB_NO_OF_ARGUMENTS:
|
||||||
# SABnzbd argv:
|
# SABnzbd argv:
|
||||||
|
@ -387,8 +392,9 @@ def main(args, section=None):
|
||||||
# 5 User-defined category
|
# 5 User-defined category
|
||||||
# 6 Group that the NZB was posted in e.g. alt.binaries.x
|
# 6 Group that the NZB was posted in e.g. alt.binaries.x
|
||||||
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
|
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
|
||||||
|
clientAgent = 'sabnzbd'
|
||||||
logger.postprocess("Script triggered from SABnzbd")
|
logger.postprocess("Script triggered from SABnzbd")
|
||||||
result = process(args[1], inputName=args[2], status=args[7], inputCategory=args[5], clientAgent = "sabnzbd", download_id='')
|
result = process(args[1], inputName=args[2], status=args[7], inputCategory=args[5], clientAgent=clientAgent, download_id='')
|
||||||
# SABnzbd 0.7.17+
|
# SABnzbd 0.7.17+
|
||||||
elif len(args) >= nzbtomedia.SABNZB_0717_NO_OF_ARGUMENTS:
|
elif len(args) >= nzbtomedia.SABNZB_0717_NO_OF_ARGUMENTS:
|
||||||
# SABnzbd argv:
|
# SABnzbd argv:
|
||||||
|
@ -400,20 +406,22 @@ def main(args, section=None):
|
||||||
# 6 Group that the NZB was posted in e.g. alt.binaries.x
|
# 6 Group that the NZB was posted in e.g. alt.binaries.x
|
||||||
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
|
# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2
|
||||||
# 8 Failure URL
|
# 8 Failure URL
|
||||||
|
clientAgent = 'sabnzbd'
|
||||||
logger.postprocess("Script triggered from SABnzbd 0.7.17+")
|
logger.postprocess("Script triggered from SABnzbd 0.7.17+")
|
||||||
result = process(args[1], inputName=args[2], status=args[7], inputCategory=args[5], clientAgent = "sabnzbd", download_id='')
|
result = process(args[1], inputName=args[2], status=args[7], inputCategory=args[5], clientAgent=clientAgent, download_id='')
|
||||||
else:
|
else:
|
||||||
# Perform Manual Run
|
# Perform Manual Run
|
||||||
logger.warning("Invalid number of arguments received from client, Switching to manual run mode ...")
|
logger.warning("Invalid number of arguments received from client, Switching to manual run mode ...")
|
||||||
|
|
||||||
# Loop and auto-process
|
# Loop and auto-process
|
||||||
|
clientAgent = 'manual'
|
||||||
for section, subsection in nzbtomedia.SUBSECTIONS.items():
|
for section, subsection in nzbtomedia.SUBSECTIONS.items():
|
||||||
for category in subsection:
|
for category in subsection:
|
||||||
if nzbtomedia.CFG[section][category].isenabled():
|
if nzbtomedia.CFG[section][category].isenabled():
|
||||||
dirNames = get_dirnames(section, category)
|
dirNames = get_dirnames(section, category)
|
||||||
for dirName in dirNames:
|
for dirName in dirNames:
|
||||||
logger.postprocess("nzbToMedia running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
logger.postprocess("nzbToMedia running %s:%s as a manual run on folder %s ...", section, category, dirName)
|
||||||
results = process(dirName, os.path.basename(dirName), 0, inputCategory=category)
|
results = process(dirName, os.path.basename(dirName), 0, clientAgent=clientAgent, inputCategory=category)
|
||||||
if results != 0:
|
if results != 0:
|
||||||
logger.error("A problem was reported when trying to manually run %s:%s.", section, category)
|
logger.error("A problem was reported when trying to manually run %s:%s.", section, category)
|
||||||
result = results
|
result = results
|
||||||
|
@ -426,7 +434,7 @@ def main(args, section=None):
|
||||||
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
|
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
|
||||||
sys.exit(nzbtomedia.NZBGET_POSTPROCESS_SUCCESS)
|
sys.exit(nzbtomedia.NZBGET_POSTPROCESS_SUCCESS)
|
||||||
else:
|
else:
|
||||||
logger.error("A problem was reported in the nzbToMedia script.", args[0])
|
logger.error("A problem was reported in the %s script.", args[0])
|
||||||
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
|
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
|
||||||
sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR)
|
sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import sys
|
||||||
import platform
|
import platform
|
||||||
from nzbtomedia import logger, versionCheck
|
from nzbtomedia import logger, versionCheck
|
||||||
from nzbtomedia.nzbToMediaConfig import config
|
from nzbtomedia.nzbToMediaConfig import config
|
||||||
from nzbtomedia.nzbToMediaUtil import WakeUp
|
from nzbtomedia.nzbToMediaUtil import WakeUp, makeDir
|
||||||
|
|
||||||
# sabnzbd constants
|
# sabnzbd constants
|
||||||
SABNZB_NO_OF_ARGUMENTS = 8
|
SABNZB_NO_OF_ARGUMENTS = 8
|
||||||
|
@ -55,7 +55,12 @@ GIT_USER = None
|
||||||
GIT_BRANCH = None
|
GIT_BRANCH = None
|
||||||
GIT_REPO = None
|
GIT_REPO = None
|
||||||
|
|
||||||
CLIENTAGENT = None
|
NZB_CLIENTAGENT = None
|
||||||
|
SABNZBDHOST = None
|
||||||
|
SABNZBDPORT = None
|
||||||
|
SABNZBDAPIKEY = None
|
||||||
|
|
||||||
|
TORRENT_CLIENTAGENT = None
|
||||||
USELINK = None
|
USELINK = None
|
||||||
OUTPUTDIRECTORY = None
|
OUTPUTDIRECTORY = None
|
||||||
CATEGORIES = []
|
CATEGORIES = []
|
||||||
|
@ -102,12 +107,12 @@ def initialize(section=None):
|
||||||
NZBTOMEDIA_TIMEOUT, FORKS, FORK_DEFAULT, FORK_FAILED_TORRENT, FORK_FAILED, SICKBEARD_TORRENT, SICKBEARD_FAILED, \
|
NZBTOMEDIA_TIMEOUT, FORKS, FORK_DEFAULT, FORK_FAILED_TORRENT, FORK_FAILED, SICKBEARD_TORRENT, SICKBEARD_FAILED, \
|
||||||
PROGRAM_DIR, CFG, CFG_LOGGING, CONFIG_FILE, CONFIG_MOVIE_FILE, CONFIG_SPEC_FILE, LOG_DIR, NZBTOMEDIA_BRANCH, \
|
PROGRAM_DIR, CFG, CFG_LOGGING, CONFIG_FILE, CONFIG_MOVIE_FILE, CONFIG_SPEC_FILE, LOG_DIR, NZBTOMEDIA_BRANCH, \
|
||||||
CONFIG_TV_FILE, LOG_FILE, NZBTOMEDIA_VERSION, NEWEST_VERSION, NEWEST_VERSION_STRING, VERSION_NOTIFY, SYS_ARGV, \
|
CONFIG_TV_FILE, LOG_FILE, NZBTOMEDIA_VERSION, NEWEST_VERSION, NEWEST_VERSION_STRING, VERSION_NOTIFY, SYS_ARGV, \
|
||||||
SABNZB_NO_OF_ARGUMENTS, SABNZB_0717_NO_OF_ARGUMENTS, CATEGORIES, CLIENTAGENT, USELINK, OUTPUTDIRECTORY, NOFLATTEN, \
|
SABNZB_NO_OF_ARGUMENTS, SABNZB_0717_NO_OF_ARGUMENTS, CATEGORIES, TORRENT_CLIENTAGENT, USELINK, OUTPUTDIRECTORY, NOFLATTEN, \
|
||||||
UTORRENTPWD, UTORRENTUSR, UTORRENTWEBUI, DELUGEHOST, DELUGEPORT, DELUGEUSR, DELUGEPWD, TRANSMISSIONHOST, TRANSMISSIONPORT, \
|
UTORRENTPWD, UTORRENTUSR, UTORRENTWEBUI, DELUGEHOST, DELUGEPORT, DELUGEUSR, DELUGEPWD, TRANSMISSIONHOST, TRANSMISSIONPORT, \
|
||||||
TRANSMISSIONPWD, TRANSMISSIONUSR, COMPRESSEDCONTAINER, MEDIACONTAINER, METACONTAINER, MINSAMPLESIZE, SAMPLEIDS, \
|
TRANSMISSIONPWD, TRANSMISSIONUSR, COMPRESSEDCONTAINER, MEDIACONTAINER, METACONTAINER, MINSAMPLESIZE, SAMPLEIDS, \
|
||||||
SECTIONS, SUBSECTIONS, USER_SCRIPT_CATEGORIES, __INITIALIZED__, AUTO_UPDATE, APP_FILENAME, USER_DELAY, USER_SCRIPT_RUNONCE, \
|
SECTIONS, SUBSECTIONS, USER_SCRIPT_CATEGORIES, __INITIALIZED__, AUTO_UPDATE, APP_FILENAME, USER_DELAY, USER_SCRIPT_RUNONCE, \
|
||||||
APP_NAME,USER_SCRIPT_MEDIAEXTENSIONS, USER_SCRIPT, USER_SCRIPT_PARAM, USER_SCRIPT_SUCCESSCODES, USER_SCRIPT_CLEAN, \
|
APP_NAME,USER_SCRIPT_MEDIAEXTENSIONS, USER_SCRIPT, USER_SCRIPT_PARAM, USER_SCRIPT_SUCCESSCODES, USER_SCRIPT_CLEAN, \
|
||||||
TRANSCODE, GIT_PATH, GIT_USER, GIT_BRANCH, GIT_REPO, SYS_ENCODING
|
TRANSCODE, GIT_PATH, GIT_USER, GIT_BRANCH, GIT_REPO, SYS_ENCODING, NZB_CLIENTAGENT, SABNZBDHOST, SABNZBDPORT, SABNZBDAPIKEY
|
||||||
|
|
||||||
|
|
||||||
if __INITIALIZED__:
|
if __INITIALIZED__:
|
||||||
|
@ -150,7 +155,7 @@ def initialize(section=None):
|
||||||
print 'or find another way to force Python to use ' + SYS_ENCODING + ' for string encoding.'
|
print 'or find another way to force Python to use ' + SYS_ENCODING + ' for string encoding.'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not nzbToMediaUtil.makeDir(LOG_DIR):
|
if not makeDir(LOG_DIR):
|
||||||
print("!!! No log folder, logging to screen only!")
|
print("!!! No log folder, logging to screen only!")
|
||||||
|
|
||||||
# init logging
|
# init logging
|
||||||
|
@ -196,7 +201,12 @@ def initialize(section=None):
|
||||||
|
|
||||||
WakeUp()
|
WakeUp()
|
||||||
|
|
||||||
CLIENTAGENT = CFG["Torrent"]["clientAgent"] # utorrent | deluge | transmission | rtorrent | other
|
NZB_CLIENTAGENT = CFG["Nzb"]["clientAgent"] # sabnzbd
|
||||||
|
SABNZBDHOST = CFG["Nzb"]["sabnzbd_host"]
|
||||||
|
SABNZBDPORT = int(CFG["Nzb"]["sabnzbd_port"])
|
||||||
|
SABNZBDAPIKEY = CFG["Nzb"]["sabnzbd_apikey"]
|
||||||
|
|
||||||
|
TORRENT_CLIENTAGENT = CFG["Torrent"]["clientAgent"] # utorrent | deluge | transmission | rtorrent | other
|
||||||
USELINK = CFG["Torrent"]["useLink"] # no | hard | sym
|
USELINK = CFG["Torrent"]["useLink"] # no | hard | sym
|
||||||
OUTPUTDIRECTORY = CFG["Torrent"]["outputDirectory"] # /abs/path/to/complete/
|
OUTPUTDIRECTORY = CFG["Torrent"]["outputDirectory"] # /abs/path/to/complete/
|
||||||
CATEGORIES = (CFG["Torrent"]["categories"]) # music,music_videos,pictures,software
|
CATEGORIES = (CFG["Torrent"]["categories"]) # music,music_videos,pictures,software
|
||||||
|
@ -207,12 +217,12 @@ def initialize(section=None):
|
||||||
UTORRENTPWD = CFG["Torrent"]["uTorrentPWD"] # mysecretpwr
|
UTORRENTPWD = CFG["Torrent"]["uTorrentPWD"] # mysecretpwr
|
||||||
|
|
||||||
TRANSMISSIONHOST = CFG["Torrent"]["TransmissionHost"] # localhost
|
TRANSMISSIONHOST = CFG["Torrent"]["TransmissionHost"] # localhost
|
||||||
TRANSMISSIONPORT = CFG["Torrent"]["TransmissionPort"] # 8084
|
TRANSMISSIONPORT = int(CFG["Torrent"]["TransmissionPort"])
|
||||||
TRANSMISSIONUSR = CFG["Torrent"]["TransmissionUSR"] # mysecretusr
|
TRANSMISSIONUSR = CFG["Torrent"]["TransmissionUSR"] # mysecretusr
|
||||||
TRANSMISSIONPWD = CFG["Torrent"]["TransmissionPWD"] # mysecretpwr
|
TRANSMISSIONPWD = CFG["Torrent"]["TransmissionPWD"] # mysecretpwr
|
||||||
|
|
||||||
DELUGEHOST = CFG["Torrent"]["DelugeHost"] # localhost
|
DELUGEHOST = CFG["Torrent"]["DelugeHost"] # localhost
|
||||||
DELUGEPORT = CFG["Torrent"]["DelugePort"] # 8084
|
DELUGEPORT = int(CFG["Torrent"]["DelugePort"]) # 8084
|
||||||
DELUGEUSR = CFG["Torrent"]["DelugeUSR"] # mysecretusr
|
DELUGEUSR = CFG["Torrent"]["DelugeUSR"] # mysecretusr
|
||||||
DELUGEPWD = CFG["Torrent"]["DelugePWD"] # mysecretpwr
|
DELUGEPWD = CFG["Torrent"]["DelugePWD"] # mysecretpwr
|
||||||
|
|
||||||
|
@ -221,6 +231,7 @@ def initialize(section=None):
|
||||||
METACONTAINER = (CFG["Extensions"]["metaExtensions"]) # .nfo,.sub,.srt
|
METACONTAINER = (CFG["Extensions"]["metaExtensions"]) # .nfo,.sub,.srt
|
||||||
MINSAMPLESIZE = int(CFG["Extensions"]["minSampleSize"]) # 200 (in MB)
|
MINSAMPLESIZE = int(CFG["Extensions"]["minSampleSize"]) # 200 (in MB)
|
||||||
SAMPLEIDS = (CFG["Extensions"]["SampleIDs"]) # sample,-s.
|
SAMPLEIDS = (CFG["Extensions"]["SampleIDs"]) # sample,-s.
|
||||||
|
TRANSCODE = int(CFG["Transcoder"]["transcode"])
|
||||||
|
|
||||||
# check for script-defied section and if None set to allow sections
|
# check for script-defied section and if None set to allow sections
|
||||||
SECTIONS = ("CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez")
|
SECTIONS = ("CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez")
|
||||||
|
@ -230,8 +241,6 @@ def initialize(section=None):
|
||||||
SUBSECTIONS = CFG[SECTIONS]
|
SUBSECTIONS = CFG[SECTIONS]
|
||||||
CATEGORIES += SUBSECTIONS.sections
|
CATEGORIES += SUBSECTIONS.sections
|
||||||
|
|
||||||
TRANSCODE = int(CFG["Transcoder"]["transcode"])
|
|
||||||
|
|
||||||
USER_SCRIPT_CATEGORIES = CFG["UserScript"]["user_script_categories"]
|
USER_SCRIPT_CATEGORIES = CFG["UserScript"]["user_script_categories"]
|
||||||
if not "NONE" in USER_SCRIPT_CATEGORIES:
|
if not "NONE" in USER_SCRIPT_CATEGORIES:
|
||||||
USER_SCRIPT_MEDIAEXTENSIONS = (CFG["UserScript"]["user_script_mediaExtensions"])
|
USER_SCRIPT_MEDIAEXTENSIONS = (CFG["UserScript"]["user_script_mediaExtensions"])
|
||||||
|
|
|
@ -2,7 +2,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import nzbtomedia
|
import nzbtomedia
|
||||||
from subprocess import call, Popen
|
from subprocess import call, Popen
|
||||||
from nzbtomedia.nzbToMediaUtil import create_destination
|
from nzbtomedia.nzbToMediaUtil import makeDir
|
||||||
from nzbtomedia import logger
|
from nzbtomedia import logger
|
||||||
|
|
||||||
# which() and os_platform() breaks when running in Transmission (has to do with os.environ)
|
# which() and os_platform() breaks when running in Transmission (has to do with os.environ)
|
||||||
|
@ -91,7 +91,7 @@ def extract(filePath, outputDestination):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Create outputDestination folder
|
# Create outputDestination folder
|
||||||
create_destination(outputDestination)
|
makeDir(outputDestination)
|
||||||
|
|
||||||
passwordsfile = nzbtomedia.CFG["passwords"]["PassWordFile"]
|
passwordsfile = nzbtomedia.CFG["passwords"]["PassWordFile"]
|
||||||
if passwordsfile != "" and os.path.isfile(os.path.normpath(passwordsfile)):
|
if passwordsfile != "" and os.path.isfile(os.path.normpath(passwordsfile)):
|
||||||
|
|
|
@ -14,31 +14,10 @@ from nzbtomedia.synchronousdeluge.client import DelugeClient
|
||||||
from nzbtomedia.utorrent.client import UTorrentClient
|
from nzbtomedia.utorrent.client import UTorrentClient
|
||||||
from nzbtomedia.transmissionrpc.client import Client as TransmissionClient
|
from nzbtomedia.transmissionrpc.client import Client as TransmissionClient
|
||||||
|
|
||||||
|
|
||||||
def getDirectorySize(directory):
|
|
||||||
dir_size = 0
|
|
||||||
for (path, dirs, files) in os.walk(directory):
|
|
||||||
for file in files:
|
|
||||||
filename = os.path.join(path, file)
|
|
||||||
dir_size += os.path.getsize(filename)
|
|
||||||
dir_size = dir_size / (1024.0 * 1024.0 * 1024.0) # convert to GiB
|
|
||||||
return dir_size
|
|
||||||
|
|
||||||
|
|
||||||
def safeName(name):
|
def safeName(name):
|
||||||
safename = re.sub(r"[\/\\\:\*\?\"\<\>\|]", "", name) #make this name safe for use in directories for windows etc.
|
safename = re.sub(r"[\/\\\:\*\?\"\<\>\|]", "", name) #make this name safe for use in directories for windows etc.
|
||||||
return safename
|
return safename
|
||||||
|
|
||||||
def create_destination(outputDestination):
|
|
||||||
if os.path.exists(outputDestination):
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
logger.info("CREATE DESTINATION: Creating destination folder: %s", outputDestination)
|
|
||||||
os.makedirs(outputDestination)
|
|
||||||
except:
|
|
||||||
logger.error("CREATE DESTINATION: Not possible to create destination folder. Exiting")
|
|
||||||
sys.exit(-1)
|
|
||||||
|
|
||||||
def makeDir(path):
|
def makeDir(path):
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
try:
|
try:
|
||||||
|
@ -132,7 +111,7 @@ def copy_link(filePath, targetDirectory, useLink, outputDestination):
|
||||||
logger.info("COPYLINK: target file already exists. Nothing to be done")
|
logger.info("COPYLINK: target file already exists. Nothing to be done")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
create_destination(outputDestination)
|
makeDir(outputDestination)
|
||||||
if useLink == "hard":
|
if useLink == "hard":
|
||||||
try:
|
try:
|
||||||
logger.info("COPYLINK: Hard linking %s to %s", filePath, targetDirectory)
|
logger.info("COPYLINK: Hard linking %s to %s", filePath, targetDirectory)
|
||||||
|
@ -167,7 +146,6 @@ def copy_link(filePath, targetDirectory, useLink, outputDestination):
|
||||||
shutil.copy(filePath, targetDirectory)
|
shutil.copy(filePath, targetDirectory)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def flatten(outputDestination):
|
def flatten(outputDestination):
|
||||||
logger.info("FLATTEN: Flattening directory: %s", outputDestination)
|
logger.info("FLATTEN: Flattening directory: %s", outputDestination)
|
||||||
for dirpath, dirnames, filenames in os.walk(outputDestination): # Flatten out the directory to make postprocessing easier
|
for dirpath, dirnames, filenames in os.walk(outputDestination): # Flatten out the directory to make postprocessing easier
|
||||||
|
@ -182,7 +160,6 @@ def flatten(outputDestination):
|
||||||
logger.error("FLATTEN: Could not flatten %s", source)
|
logger.error("FLATTEN: Could not flatten %s", source)
|
||||||
removeEmptyFolders(outputDestination) # Cleanup empty directories
|
removeEmptyFolders(outputDestination) # Cleanup empty directories
|
||||||
|
|
||||||
|
|
||||||
def removeEmptyFolders(path):
|
def removeEmptyFolders(path):
|
||||||
logger.info("REMOVER: Removing empty folders in: %s", path)
|
logger.info("REMOVER: Removing empty folders in: %s", path)
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
|
@ -221,7 +198,6 @@ def iterate_media_files(dirname):
|
||||||
continue
|
continue
|
||||||
yield dirpath, os.path.join(dirpath, filename)
|
yield dirpath, os.path.join(dirpath, filename)
|
||||||
|
|
||||||
|
|
||||||
#Wake function
|
#Wake function
|
||||||
def WakeOnLan(ethernet_address):
|
def WakeOnLan(ethernet_address):
|
||||||
|
|
||||||
|
@ -253,10 +229,6 @@ def TestCon(host, port):
|
||||||
return "Down"
|
return "Down"
|
||||||
|
|
||||||
def WakeUp():
|
def WakeUp():
|
||||||
if not nzbtomedia.CFG:
|
|
||||||
logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
|
|
||||||
return
|
|
||||||
|
|
||||||
wake = int(nzbtomedia.CFG["WakeOnLan"]["wake"])
|
wake = int(nzbtomedia.CFG["WakeOnLan"]["wake"])
|
||||||
if wake == 0: # just return if we don't need to wake anything.
|
if wake == 0: # just return if we don't need to wake anything.
|
||||||
return
|
return
|
||||||
|
@ -278,10 +250,6 @@ def WakeUp():
|
||||||
logger.info("System with mac: %s has been woken. Continuing with the rest of the script.", mac)
|
logger.info("System with mac: %s has been woken. Continuing with the rest of the script.", mac)
|
||||||
|
|
||||||
def convert_to_ascii(nzbName, dirName):
|
def convert_to_ascii(nzbName, dirName):
|
||||||
if not nzbtomedia.CFG:
|
|
||||||
logger.error("You need an autoProcessMedia.cfg file - did you rename and edit the .sample?")
|
|
||||||
return nzbName, dirName
|
|
||||||
|
|
||||||
ascii_convert = int(nzbtomedia.CFG["ASCII"]["convert"])
|
ascii_convert = int(nzbtomedia.CFG["ASCII"]["convert"])
|
||||||
if ascii_convert == 0 or os.name == 'nt': # just return if we don't want to convert or on windows os and "\" is replaced!.
|
if ascii_convert == 0 or os.name == 'nt': # just return if we don't want to convert or on windows os and "\" is replaced!.
|
||||||
return nzbName, dirName
|
return nzbName, dirName
|
||||||
|
@ -302,7 +270,6 @@ def convert_to_ascii(nzbName, dirName):
|
||||||
return nzbName, dirName
|
return nzbName, dirName
|
||||||
|
|
||||||
def parse_other(args):
|
def parse_other(args):
|
||||||
|
|
||||||
return os.path.normpath(args[1]), '', '', '', ''
|
return os.path.normpath(args[1]), '', '', '', ''
|
||||||
|
|
||||||
def parse_rtorrent(args):
|
def parse_rtorrent(args):
|
||||||
|
@ -446,31 +413,86 @@ def cleanup_directories(inputCategory, processCategories, result, directory):
|
||||||
|
|
||||||
def create_torrent_class(clientAgent):
|
def create_torrent_class(clientAgent):
|
||||||
# Hardlink solution for Torrents
|
# Hardlink solution for Torrents
|
||||||
TorrentClass = ""
|
TorrentClass = None
|
||||||
if clientAgent in ['utorrent', 'transmission', 'deluge']:
|
if clientAgent == 'utorrent':
|
||||||
if clientAgent == 'utorrent':
|
try:
|
||||||
try:
|
logger.debug("Connecting to %s: %s", clientAgent, nzbtomedia.UTORRENTWEBUI)
|
||||||
logger.debug("Connecting to %s: %s", clientAgent, nzbtomedia.UTORRENTWEBUI)
|
TorrentClass = UTorrentClient(nzbtomedia.UTORRENTWEBUI, nzbtomedia.UTORRENTUSR, nzbtomedia.UTORRENTPWD)
|
||||||
TorrentClass = UTorrentClient(nzbtomedia.UTORRENTWEBUI, nzbtomedia.UTORRENTUSR, nzbtomedia.UTORRENTPWD)
|
except:
|
||||||
except:
|
logger.error("Failed to connect to uTorrent")
|
||||||
logger.error("Failed to connect to uTorrent")
|
|
||||||
|
|
||||||
if clientAgent == 'transmission':
|
if clientAgent == 'transmission':
|
||||||
try:
|
try:
|
||||||
logger.debug("Connecting to %s: http://%s:%s", clientAgent, nzbtomedia.TRANSMISSIONHOST,
|
logger.debug("Connecting to %s: http://%s:%s", clientAgent, nzbtomedia.TRANSMISSIONHOST,
|
||||||
nzbtomedia.TRANSMISSIONPORT)
|
nzbtomedia.TRANSMISSIONPORT)
|
||||||
TorrentClass = TransmissionClient(nzbtomedia.TRANSMISSIONHOST, nzbtomedia.TRANSMISSIONPORT, nzbtomedia.TRANSMISSIONUSR,
|
TorrentClass = TransmissionClient(nzbtomedia.TRANSMISSIONHOST, nzbtomedia.TRANSMISSIONPORT, nzbtomedia.TRANSMISSIONUSR,
|
||||||
nzbtomedia.TRANSMISSIONPWD)
|
nzbtomedia.TRANSMISSIONPWD)
|
||||||
except:
|
except:
|
||||||
logger.error("Failed to connect to Transmission")
|
logger.error("Failed to connect to Transmission")
|
||||||
|
|
||||||
if clientAgent == 'deluge':
|
if clientAgent == 'deluge':
|
||||||
try:
|
try:
|
||||||
logger.debug("Connecting to %s: http://%s:%s", clientAgent, nzbtomedia.DELUGEHOST,
|
logger.debug("Connecting to %s: http://%s:%s", clientAgent, nzbtomedia.DELUGEHOST,
|
||||||
nzbtomedia.DELUGEPORT)
|
nzbtomedia.DELUGEPORT)
|
||||||
TorrentClass = DelugeClient()
|
TorrentClass = DelugeClient()
|
||||||
TorrentClass.connect(host =nzbtomedia.DELUGEHOST, port =nzbtomedia.DELUGEPORT, username =nzbtomedia.DELUGEUSR, password =nzbtomedia.DELUGEPWD)
|
TorrentClass.connect(host =nzbtomedia.DELUGEHOST, port =nzbtomedia.DELUGEPORT, username =nzbtomedia.DELUGEUSR, password =nzbtomedia.DELUGEPWD)
|
||||||
except:
|
except:
|
||||||
logger.error("Failed to connect to deluge")
|
logger.error("Failed to connect to Deluge")
|
||||||
|
|
||||||
return TorrentClass
|
return TorrentClass
|
||||||
|
|
||||||
|
def pause_torrent(clientAgent, TorrentClass, inputHash, inputID, inputName):
|
||||||
|
# if we are using links with Torrents it means we need to pause it in order to access the files
|
||||||
|
logger.debug("Stoping torrent %s in %s while processing", inputName, clientAgent)
|
||||||
|
if clientAgent == 'utorrent' and TorrentClass != "":
|
||||||
|
TorrentClass.stop(inputHash)
|
||||||
|
if clientAgent == 'transmission' and TorrentClass !="":
|
||||||
|
TorrentClass.stop_torrent(inputID)
|
||||||
|
if clientAgent == 'deluge' and TorrentClass != "":
|
||||||
|
TorrentClass.core.pause_torrent([inputID])
|
||||||
|
time.sleep(5) # Give Torrent client some time to catch up with the change
|
||||||
|
|
||||||
|
def resume_torrent(clientAgent, TorrentClass, inputHash, inputID, result, inputName):
|
||||||
|
# Hardlink solution for uTorrent, need to implent support for deluge, transmission
|
||||||
|
if clientAgent in ['utorrent', 'transmission', 'deluge'] and inputHash:
|
||||||
|
# Delete torrent and torrentdata from Torrent client if processing was successful.
|
||||||
|
if (int(nzbtomedia.CFG["Torrent"]["deleteOriginal"]) is 1 and result != 1) or nzbtomedia.USELINK == 'move': # if we move files, nothing to resume seeding.
|
||||||
|
logger.debug("Deleting torrent %s from %s", inputName, clientAgent)
|
||||||
|
if clientAgent == 'utorrent' and TorrentClass != "":
|
||||||
|
TorrentClass.removedata(inputHash)
|
||||||
|
TorrentClass.remove(inputHash)
|
||||||
|
if clientAgent == 'transmission' and TorrentClass !="":
|
||||||
|
TorrentClass.remove_torrent(inputID, True)
|
||||||
|
if clientAgent == 'deluge' and TorrentClass != "":
|
||||||
|
TorrentClass.core.remove_torrent(inputID, True)
|
||||||
|
# we always want to resume seeding, for now manually find out what is wrong when extraction fails
|
||||||
|
else:
|
||||||
|
logger.debug("Starting torrent %s in %s", inputName, clientAgent)
|
||||||
|
if clientAgent == 'utorrent' and TorrentClass != "":
|
||||||
|
TorrentClass.start(inputHash)
|
||||||
|
if clientAgent == 'transmission' and TorrentClass !="":
|
||||||
|
TorrentClass.start_torrent(inputID)
|
||||||
|
if clientAgent == 'deluge' and TorrentClass != "":
|
||||||
|
TorrentClass.core.resume_torrent([inputID])
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
def find_download(clientAgent, nzbName, download_id):
|
||||||
|
tc = create_torrent_class(clientAgent)
|
||||||
|
|
||||||
|
logger.debug("Searching for Download on %s ...", clientAgent)
|
||||||
|
if clientAgent == 'utorrent':
|
||||||
|
torrents = tc.list()[1]['torrents']
|
||||||
|
if torrents:
|
||||||
|
for torrent in torrents:
|
||||||
|
if nzbName in torrent and download_id in torrent:
|
||||||
|
return True
|
||||||
|
if clientAgent == 'transmission':
|
||||||
|
torrent = tc.get_torrent(download_id)
|
||||||
|
if torrent:
|
||||||
|
name = torrent.name
|
||||||
|
if name == nzbName:
|
||||||
|
return True
|
||||||
|
if clientAgent == 'deluge':
|
||||||
|
pass
|
||||||
|
if clientAgent == 'sabnzbd':
|
||||||
|
pass
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue