diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 031b6523..b6decbad 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -16,7 +16,7 @@ from nzbtomedia.autoProcess.autoProcessMusic import autoProcessMusic from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV from nzbtomedia.extractor import extractor 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 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) 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): final_result = int(0) # start at 0. @@ -327,8 +292,11 @@ def main(args): # Initialize the config nzbtomedia.initialize() + # clientAgent for Torrents + clientAgent = nzbtomedia.TORRENT_CLIENTAGENT + 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("#########################################################") # debug command line options @@ -337,8 +305,6 @@ def main(args): # Post-Processing Result result = 0 - # clientAgent for Torrents - clientAgent = nzbtomedia.CLIENTAGENT try: inputDirectory, inputName, inputCategory, inputHash, inputID = parse_args(clientAgent, args) @@ -346,10 +312,14 @@ def main(args): logger.error("There was a problem loading variables") return -1 - # check if this is a manual run - if inputDirectory is None: - clientAgent = 'manual' + if inputDirectory and inputName and inputHash and inputID: + result = processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent) + else: + # Perform Manual Run 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 category in subsection: 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) else: 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) if __name__ == "__main__": diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index 21361f4c..eb15427e 100644 --- a/autoProcessMedia.cfg.spec +++ b/autoProcessMedia.cfg.spec @@ -121,6 +121,14 @@ ##### Set to path where download client places completed downloads locally for this category 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] ###### clientAgent - Supported clients: utorrent, transmission, deluge, rtorrent, other clientAgent = other diff --git a/nzbToMedia.py b/nzbToMedia.py index c23cd05e..dbe34c2c 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -318,8 +318,11 @@ def main(args, section=None): # Initialize the config nzbtomedia.initialize(section) + # clientAgent for NZBs + clientAgent = nzbtomedia.NZB_CLIENTAGENT + 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("#########################################################") # debug command line options @@ -329,6 +332,7 @@ def main(args, section=None): result = 0 status = 0 + # NZBGet V11+ # 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': @@ -376,7 +380,8 @@ def main(args, section=None): download_id = os.environ['NZBPR_COUCHPOTATO'] # 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 elif len(args) == nzbtomedia.SABNZB_NO_OF_ARGUMENTS: # SABnzbd argv: @@ -387,8 +392,9 @@ def main(args, section=None): # 5 User-defined category # 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 + clientAgent = '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+ elif len(args) >= nzbtomedia.SABNZB_0717_NO_OF_ARGUMENTS: # SABnzbd argv: @@ -400,20 +406,22 @@ def main(args, section=None): # 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 # 8 Failure URL + clientAgent = 'sabnzbd' 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: # Perform Manual Run 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 category in subsection: if nzbtomedia.CFG[section][category].isenabled(): dirNames = get_dirnames(section, category) for dirName in dirNames: 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: logger.error("A problem was reported when trying to manually run %s:%s.", section, category) result = results @@ -426,7 +434,7 @@ def main(args, section=None): if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 sys.exit(nzbtomedia.NZBGET_POSTPROCESS_SUCCESS) 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 sys.exit(nzbtomedia.NZBGET_POSTPROCESS_ERROR) diff --git a/nzbtomedia/__init__.py b/nzbtomedia/__init__.py index f39bbbde..148c03e1 100644 --- a/nzbtomedia/__init__.py +++ b/nzbtomedia/__init__.py @@ -5,7 +5,7 @@ import sys import platform from nzbtomedia import logger, versionCheck from nzbtomedia.nzbToMediaConfig import config -from nzbtomedia.nzbToMediaUtil import WakeUp +from nzbtomedia.nzbToMediaUtil import WakeUp, makeDir # sabnzbd constants SABNZB_NO_OF_ARGUMENTS = 8 @@ -55,7 +55,12 @@ GIT_USER = None GIT_BRANCH = None GIT_REPO = None -CLIENTAGENT = None +NZB_CLIENTAGENT = None +SABNZBDHOST = None +SABNZBDPORT = None +SABNZBDAPIKEY = None + +TORRENT_CLIENTAGENT = None USELINK = None OUTPUTDIRECTORY = None CATEGORIES = [] @@ -102,12 +107,12 @@ def initialize(section=None): 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, \ 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, \ TRANSMISSIONPWD, TRANSMISSIONUSR, COMPRESSEDCONTAINER, MEDIACONTAINER, METACONTAINER, MINSAMPLESIZE, SAMPLEIDS, \ 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, \ - 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__: @@ -150,7 +155,7 @@ def initialize(section=None): print 'or find another way to force Python to use ' + SYS_ENCODING + ' for string encoding.' sys.exit(1) - if not nzbToMediaUtil.makeDir(LOG_DIR): + if not makeDir(LOG_DIR): print("!!! No log folder, logging to screen only!") # init logging @@ -196,7 +201,12 @@ def initialize(section=None): 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 OUTPUTDIRECTORY = CFG["Torrent"]["outputDirectory"] # /abs/path/to/complete/ CATEGORIES = (CFG["Torrent"]["categories"]) # music,music_videos,pictures,software @@ -207,12 +217,12 @@ def initialize(section=None): UTORRENTPWD = CFG["Torrent"]["uTorrentPWD"] # mysecretpwr TRANSMISSIONHOST = CFG["Torrent"]["TransmissionHost"] # localhost - TRANSMISSIONPORT = CFG["Torrent"]["TransmissionPort"] # 8084 + TRANSMISSIONPORT = int(CFG["Torrent"]["TransmissionPort"]) TRANSMISSIONUSR = CFG["Torrent"]["TransmissionUSR"] # mysecretusr TRANSMISSIONPWD = CFG["Torrent"]["TransmissionPWD"] # mysecretpwr DELUGEHOST = CFG["Torrent"]["DelugeHost"] # localhost - DELUGEPORT = CFG["Torrent"]["DelugePort"] # 8084 + DELUGEPORT = int(CFG["Torrent"]["DelugePort"]) # 8084 DELUGEUSR = CFG["Torrent"]["DelugeUSR"] # mysecretusr DELUGEPWD = CFG["Torrent"]["DelugePWD"] # mysecretpwr @@ -221,6 +231,7 @@ def initialize(section=None): METACONTAINER = (CFG["Extensions"]["metaExtensions"]) # .nfo,.sub,.srt MINSAMPLESIZE = int(CFG["Extensions"]["minSampleSize"]) # 200 (in MB) SAMPLEIDS = (CFG["Extensions"]["SampleIDs"]) # sample,-s. + TRANSCODE = int(CFG["Transcoder"]["transcode"]) # check for script-defied section and if None set to allow sections SECTIONS = ("CouchPotato", "SickBeard", "NzbDrone", "HeadPhones", "Mylar", "Gamez") @@ -230,8 +241,6 @@ def initialize(section=None): SUBSECTIONS = CFG[SECTIONS] CATEGORIES += SUBSECTIONS.sections - TRANSCODE = int(CFG["Transcoder"]["transcode"]) - USER_SCRIPT_CATEGORIES = CFG["UserScript"]["user_script_categories"] if not "NONE" in USER_SCRIPT_CATEGORIES: USER_SCRIPT_MEDIAEXTENSIONS = (CFG["UserScript"]["user_script_mediaExtensions"]) diff --git a/nzbtomedia/extractor/extractor.py b/nzbtomedia/extractor/extractor.py index e577db16..21fb8f24 100644 --- a/nzbtomedia/extractor/extractor.py +++ b/nzbtomedia/extractor/extractor.py @@ -2,7 +2,7 @@ import os import sys import nzbtomedia from subprocess import call, Popen -from nzbtomedia.nzbToMediaUtil import create_destination +from nzbtomedia.nzbToMediaUtil import makeDir from nzbtomedia import logger # 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 # Create outputDestination folder - create_destination(outputDestination) + makeDir(outputDestination) passwordsfile = nzbtomedia.CFG["passwords"]["PassWordFile"] if passwordsfile != "" and os.path.isfile(os.path.normpath(passwordsfile)): diff --git a/nzbtomedia/nzbToMediaUtil.py b/nzbtomedia/nzbToMediaUtil.py index 7c0a0fe2..1e76ff27 100644 --- a/nzbtomedia/nzbToMediaUtil.py +++ b/nzbtomedia/nzbToMediaUtil.py @@ -14,31 +14,10 @@ from nzbtomedia.synchronousdeluge.client import DelugeClient from nzbtomedia.utorrent.client import UTorrentClient 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): safename = re.sub(r"[\/\\\:\*\?\"\<\>\|]", "", name) #make this name safe for use in directories for windows etc. 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): if not os.path.isdir(path): try: @@ -132,7 +111,7 @@ def copy_link(filePath, targetDirectory, useLink, outputDestination): logger.info("COPYLINK: target file already exists. Nothing to be done") return True - create_destination(outputDestination) + makeDir(outputDestination) if useLink == "hard": try: 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) return True - def flatten(outputDestination): logger.info("FLATTEN: Flattening directory: %s", outputDestination) 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) removeEmptyFolders(outputDestination) # Cleanup empty directories - def removeEmptyFolders(path): logger.info("REMOVER: Removing empty folders in: %s", path) if not os.path.isdir(path): @@ -221,7 +198,6 @@ def iterate_media_files(dirname): continue yield dirpath, os.path.join(dirpath, filename) - #Wake function def WakeOnLan(ethernet_address): @@ -253,10 +229,6 @@ def TestCon(host, port): return "Down" 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"]) if wake == 0: # just return if we don't need to wake anything. return @@ -278,10 +250,6 @@ def WakeUp(): logger.info("System with mac: %s has been woken. Continuing with the rest of the script.", mac) 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"]) 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 @@ -302,7 +270,6 @@ def convert_to_ascii(nzbName, dirName): return nzbName, dirName def parse_other(args): - return os.path.normpath(args[1]), '', '', '', '' def parse_rtorrent(args): @@ -446,31 +413,86 @@ def cleanup_directories(inputCategory, processCategories, result, directory): def create_torrent_class(clientAgent): # Hardlink solution for Torrents - TorrentClass = "" - if clientAgent in ['utorrent', 'transmission', 'deluge']: - if clientAgent == 'utorrent': - try: - logger.debug("Connecting to %s: %s", clientAgent, nzbtomedia.UTORRENTWEBUI) - TorrentClass = UTorrentClient(nzbtomedia.UTORRENTWEBUI, nzbtomedia.UTORRENTUSR, nzbtomedia.UTORRENTPWD) - except: - logger.error("Failed to connect to uTorrent") + TorrentClass = None + if clientAgent == 'utorrent': + try: + logger.debug("Connecting to %s: %s", clientAgent, nzbtomedia.UTORRENTWEBUI) + TorrentClass = UTorrentClient(nzbtomedia.UTORRENTWEBUI, nzbtomedia.UTORRENTUSR, nzbtomedia.UTORRENTPWD) + except: + logger.error("Failed to connect to uTorrent") - if clientAgent == 'transmission': - try: - logger.debug("Connecting to %s: http://%s:%s", clientAgent, nzbtomedia.TRANSMISSIONHOST, - nzbtomedia.TRANSMISSIONPORT) - TorrentClass = TransmissionClient(nzbtomedia.TRANSMISSIONHOST, nzbtomedia.TRANSMISSIONPORT, nzbtomedia.TRANSMISSIONUSR, - nzbtomedia.TRANSMISSIONPWD) - except: - logger.error("Failed to connect to Transmission") + if clientAgent == 'transmission': + try: + logger.debug("Connecting to %s: http://%s:%s", clientAgent, nzbtomedia.TRANSMISSIONHOST, + nzbtomedia.TRANSMISSIONPORT) + TorrentClass = TransmissionClient(nzbtomedia.TRANSMISSIONHOST, nzbtomedia.TRANSMISSIONPORT, nzbtomedia.TRANSMISSIONUSR, + nzbtomedia.TRANSMISSIONPWD) + except: + logger.error("Failed to connect to Transmission") - if clientAgent == 'deluge': - try: - logger.debug("Connecting to %s: http://%s:%s", clientAgent, nzbtomedia.DELUGEHOST, - nzbtomedia.DELUGEPORT) - TorrentClass = DelugeClient() - TorrentClass.connect(host =nzbtomedia.DELUGEHOST, port =nzbtomedia.DELUGEPORT, username =nzbtomedia.DELUGEUSR, password =nzbtomedia.DELUGEPWD) - except: - logger.error("Failed to connect to deluge") + if clientAgent == 'deluge': + try: + logger.debug("Connecting to %s: http://%s:%s", clientAgent, nzbtomedia.DELUGEHOST, + nzbtomedia.DELUGEPORT) + TorrentClass = DelugeClient() + TorrentClass.connect(host =nzbtomedia.DELUGEHOST, port =nzbtomedia.DELUGEPORT, username =nzbtomedia.DELUGEUSR, password =nzbtomedia.DELUGEPWD) + except: + logger.error("Failed to connect to Deluge") - return TorrentClass \ No newline at end of file + 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 \ No newline at end of file diff --git a/tests/general.py b/tests/general.py index 3da64ac3..83e58c51 100644 --- a/tests/general.py +++ b/tests/general.py @@ -1,25 +1,27 @@ +import os +import sys import nzbtomedia -import datetime -from nzbtomedia.versionCheck import CheckVersion -from nzbtomedia import logger +import TorrentToMedia +from nzbtomedia.nzbToMediaUtil import find_download -def dict_diff(dict_a, dict_b): - return dict([ - (key, dict_b.get(key, dict_a.get(key))) - for key in set(dict_a.keys()+dict_b.keys()) - if ( - (key in dict_a and (not key in dict_b or dict_a[key] != dict_b[key])) or - (key in dict_b and (not key in dict_a or dict_a[key] != dict_b[key])) - ) - ]) - -releases = {u'aa03e62650c24a09a5f034286674b951': {u'status': u'available', u'info': {u'seeders': 38, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The Art of the Steal 2013 LIMITED BRRip XviD AC3-RARBG', u'url': u'magnet:?xt=urn:btih:B0CCABF053CA6936F61A491812F8BBFCF96B6F9E&dn=the+art+of+the+steal+2013+limited+brrip+xvid+ac3+rarbg&tr=udp%3A%2F%2F12.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 1, u'seed_ratio': 0.0, u'leechers': 51, u'score': 457, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-brrip-xvid-ac3-rarbg-t9000422.html', u'type': u'movie', u'id': u'9000422', u'size': 1249.28}, u'identifier': u'629a130713bc1350cc858085ef40b187', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'0003322b', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'aa03e62650c24a09a5f034286674b951', u'quality': u'brrip'}, u'f9239f22604848d4b9215b94f6a005fb': {u'status': u'available', u'info': {u'seeders': 121, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The Art of the Steal 2013 LIMITED BRRip XviD MP3-RARBG', u'url': u'magnet:?xt=urn:btih:41CE100FD220B56ADB1F0F127553C61DFD9AB5CB&dn=the+art+of+the+steal+2013+limited+brrip+xvid+mp3+rarbg&tr=udp%3A%2F%2F12.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 1, u'seed_ratio': 0.0, u'leechers': 89, u'score': 1134, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-brrip-xvid-mp3-rarbg-t9000421.html', u'type': u'movie', u'id': u'9000421', u'size': 840.78}, u'download_info': {u'status_support': True, u'id': u'41ce100fd220b56adb1f0f127553c61dfd9ab5cb', u'downloader': u'Transmission'}, u'identifier': u'0ad26fca02ca07b8191876616fa2f42a', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'0007329d', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721748, u'_id': u'f9239f22604848d4b9215b94f6a005fb', u'quality': u'brrip'}, u'00ee6c785ef248328f260e7eec8115c8': {u'status': u'available', u'info': {u'size': 959.74, u'protocol': u'nzb', u'description': u'', u'url': u'https://www.binsearch.info/fcgi/nzb.fcgi?q=123339072', u'age': 23, u'id': u'123339072', u'score': 5, u'provider': u'BinSearch', u'seed_time': u'', u'provider_extra': u'', u'detail_url': u'https://www.binsearch.info/?b=The.Art.of.the.Steal.2013.BDRip.XviD-NfS&g=alt.binaries.movies.divx&p=XviD%40world.net+%28XvidWorld%29&max=250', u'type': u'movie', u'seed_ratio': u'', u'name': u'The.Art.of.the.Steal.2013.BDRip.XviD-NfS.nfo [01/70] - "The.Art.of.the.Steal.2013.BDRip.XviD-NfS.nfo" yEnc (1/1)'}, u'identifier': u'e224251e41fe494e8f7b57620f2f9271', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'000298ae', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'00ee6c785ef248328f260e7eec8115c8', u'quality': u'brrip'}, u'a34ab12605a949738baf1c0c3a15695b': {u'status': u'available', u'info': {u'size': 793.12, u'protocol': u'nzb', u'description': u'', u'url': u'https://www.binsearch.info/fcgi/nzb.fcgi?q=117974223', u'age': 68, u'id': u'117974223', u'score': -2, u'provider': u'BinSearch', u'seed_time': u'', u'provider_extra': u'', u'detail_url': u'https://www.binsearch.info/?b=The.Art.of.the.Steal.2013.HDRip.XviD-AQOS&g=alt.binaries.boneless&p=none%40none.com+%28Bonehead%29&max=250', u'type': u'movie', u'seed_ratio': u'', u'name': u'The.Art.of.the.Steal.2013.HDRip.XviD-AQOS [01/26] - "The.Art.of.the.Steal.2013.HDRip.XviD-AQOS.nfo" yEnc (1/1)'}, u'identifier': u'4cd0abd13711a9fe63133756c0285410', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'0002b7e1', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'a34ab12605a949738baf1c0c3a15695b', u'quality': u'brrip'}, u'72f44e880c3c4978aae939ad71402ce7': {u'status': u'available', u'info': {u'seeders': 34, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The Art of the Steal 2013 LIMITED 720p BRRip x264 AC3-UNDERCOVER', u'url': u'magnet:?xt=urn:btih:0719836DAF8E285C566797481AE8FE880719487B&dn=the+art+of+the+steal+2013+limited+720p+brrip+x264+ac3+undercover&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce', u'age': 1, u'seed_ratio': 0.0, u'leechers': 81, u'score': 541, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-720p-brrip-x264-ac3-undercover-t9000412.html', u'type': u'movie', u'id': u'9000412', u'size': 2232.32}, u'identifier': u'a44d376cc77288e8ccc375585af5af9b', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'000335d3', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'72f44e880c3c4978aae939ad71402ce7', u'quality': u'brrip'}, u'59010dc34122424d8a0ef5bee4fc2eb8': {u'status': u'available', u'info': {u'seeders': 114, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The Art of the Steal (2013) 720p BRrip.x264 SUJAIDR', u'url': u'magnet:?xt=urn:btih:5CC3326C1115A8F4F94311F1924F28445F8D1952&dn=the+art+of+the+steal+2013+720p+brrip+x264+sujaidr&tr=http%3A%2F%2Ftracker.pimp4003.net%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 1, u'seed_ratio': 0.0, u'leechers': 73, u'score': 1056, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-720p-brrip-x264-sujaidr-t9001162.html', u'type': u'movie', u'id': u'9001162', u'size': 785.3}, u'identifier': u'75e8270389300db233a49b1e802e5a3c', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'00033fc2', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'59010dc34122424d8a0ef5bee4fc2eb8', u'quality': u'brrip'}, u'bcdf7926211b4895a8730ac832aa1011': {u'status': u'available', u'info': {u'size': 778.57, u'protocol': u'nzb', u'description': u'', u'url': u'https://www.binsearch.info/fcgi/nzb.fcgi?q=117974508', u'age': 68, u'id': u'117974508', u'score': 17, u'provider': u'BinSearch', u'seed_time': u'', u'provider_extra': u'', u'detail_url': u'https://www.binsearch.info/?b=Art+of+the+Steal&g=alt.binaries.movies.xvid&p=here%40the.net+%28Par+Yer+Rars%29&max=250', u'type': u'movie', u'seed_ratio': u'', u'name': u'The Art of the Steal 2013 HDRip XviD-AQOS "Art of the Steal.nfo" (1/1)'}, u'identifier': u'3748b17c0040f313b42704b67a401427', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'00023179', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'bcdf7926211b4895a8730ac832aa1011', u'quality': u'brrip'}, u'9213cef04b384a2bbe8731ff82fe16ff': {u'status': u'available', u'info': {u'seeders': 86, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The Art of the Steal 2013 LIMITED 1080p BRRip h264 AAC-RARBG', u'url': u'magnet:?xt=urn:btih:154206E6390A03BBF01E61F013E1A52494A52DFA&dn=the+art+of+the+steal+2013+limited+1080p+brrip+h264+aac+rarbg&tr=udp%3A%2F%2F12.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 1, u'seed_ratio': 0.0, u'leechers': 143, u'score': 1092, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-1080p-brrip-h264-aac-rarbg-t9001241.html', u'type': u'movie', u'id': u'9001241', u'size': 1781.76}, u'identifier': u'9ab5cc07a4718ff5a4eff2a5c0a5b77c', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'0003ca03', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'9213cef04b384a2bbe8731ff82fe16ff', u'quality': u'brrip'}, u'9cc23887faf444f7b93a4bafb2647ac3': {u'status': u'available', u'info': {u'seeders': 38, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The Art of the Steal 2013 LIMITED 720p BRRip h264 AAC-RARBG', u'url': u'magnet:?xt=urn:btih:47B2EE9DC2245CA1AFCACD939CA603B9DBB18239&dn=the+art+of+the+steal+2013+limited+720p+brrip+h264+aac+rarbg&tr=udp%3A%2F%2F12.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 1, u'seed_ratio': 0.0, u'leechers': 40, u'score': 429, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-720p-brrip-h264-aac-rarbg-t9001238.html', u'type': u'movie', u'id': u'9001238', u'size': 1116.16}, u'identifier': u'e66074d518f9cbefbd04bc1342cbb32a', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'00030793', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'9cc23887faf444f7b93a4bafb2647ac3', u'quality': u'brrip'}, u'c18677b9357f4e60b328b42a6bba497a': {u'status': u'available', u'files': {u'nfo': [u'/mnt/vault/videos/Movies/Art of the Steal, The (2014)/The Art of the Steal.nfo'], u'movie': [u'/mnt/vault/videos/Movies/Art of the Steal, The (2014)/The Art of the Steal.mp4']}, u'identifier': u'tt2172985.None.720p', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'00045c30', u'_t': u'release', u'last_edit': 1397726258, u'_id': u'c18677b9357f4e60b328b42a6bba497a', u'quality': u'720p'}, u'c6379eb7b7144aa6ab333f06f5759947': {u'status': u'available', u'info': {u'seeders': 61, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The.Art.of.the.Steal.2013.LIMITED.BRRip.x264.AC3-MiLLENiUM', u'url': u'magnet:?xt=urn:btih:C3F24AD28CDC1F7A25AAD8B7D80BA9B5F1D7DAA8&dn=the+art+of+the+steal+2013+limited+brrip+x264+ac3+millenium&tr=udp%3A%2F%2F12.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 17, u'seed_ratio': 0.0, u'leechers': 64, u'score': 654, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-brrip-x264-ac3-millenium-t9002531.html', u'type': u'movie', u'id': u'9002531', u'size': 1013.09}, u'identifier': u'74373b65ea496c18bdecc6e3c7a5c110', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'0003027a', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'c6379eb7b7144aa6ab333f06f5759947', u'quality': u'brrip'}, u'2f88c95fb3b24a1d9aeff4686168ee9f': {u'status': u'available', u'info': {u'seeders': 38, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The.Art.of.the.Steal.2013.LIMITED.720p.BRRip.XviD.AC3-RARBG', u'url': u'magnet:?xt=urn:btih:A834FBF8A5E7E35DEAA544139148B40F4276332A&dn=the+art+of+the+steal+2013+limited+720p+brrip+xvid+ac3+rarbg&tr=udp%3A%2F%2F12.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 1, u'seed_ratio': 0.0, u'leechers': 68, u'score': 523, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-720p-brrip-xvid-ac3-rarbg-t9000418.html', u'type': u'movie', u'id': u'9000418', u'size': 2437.12}, u'identifier': u'9caa0dbdb805a8e58af8a69240c74b9e', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'0003dbfa', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'2f88c95fb3b24a1d9aeff4686168ee9f', u'quality': u'brrip'}} -releases_current = {u'aa03e62650c24a09a5f034286674b951': {u'status': u'available', u'info': {u'seeders': 38, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The Art of the Steal 2013 LIMITED BRRip XviD AC3-RARBG', u'url': u'magnet:?xt=urn:btih:B0CCABF053CA6936F61A491812F8BBFCF96B6F9E&dn=the+art+of+the+steal+2013+limited+brrip+xvid+ac3+rarbg&tr=udp%3A%2F%2F12.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 1, u'seed_ratio': 0.0, u'leechers': 51, u'score': 457, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-brrip-xvid-ac3-rarbg-t9000422.html', u'type': u'movie', u'id': u'9000422', u'size': 1249.28}, u'identifier': u'629a130713bc1350cc858085ef40b187', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'0003322b', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'aa03e62650c24a09a5f034286674b951', u'quality': u'brrip'}, u'f9239f22604848d4b9215b94f6a005fb': {u'status': u'available', u'info': {u'seeders': 121, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The Art of the Steal 2013 LIMITED BRRip XviD MP3-RARBG', u'url': u'magnet:?xt=urn:btih:41CE100FD220B56ADB1F0F127553C61DFD9AB5CB&dn=the+art+of+the+steal+2013+limited+brrip+xvid+mp3+rarbg&tr=udp%3A%2F%2F12.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 1, u'seed_ratio': 0.0, u'leechers': 89, u'score': 1134, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-brrip-xvid-mp3-rarbg-t9000421.html', u'type': u'movie', u'id': u'9000421', u'size': 840.78}, u'download_info': {u'status_support': True, u'id': u'41ce100fd220b56adb1f0f127553c61dfd9ab5cb', u'downloader': u'Transmission'}, u'identifier': u'0ad26fca02ca07b8191876616fa2f42a', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'0007329d', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721748, u'_id': u'f9239f22604848d4b9215b94f6a005fb', u'quality': u'brrip'}, u'00ee6c785ef248328f260e7eec8115c8': {u'status': u'available', u'info': {u'size': 959.74, u'protocol': u'nzb', u'description': u'', u'url': u'https://www.binsearch.info/fcgi/nzb.fcgi?q=123339072', u'age': 23, u'id': u'123339072', u'score': 5, u'provider': u'BinSearch', u'seed_time': u'', u'provider_extra': u'', u'detail_url': u'https://www.binsearch.info/?b=The.Art.of.the.Steal.2013.BDRip.XviD-NfS&g=alt.binaries.movies.divx&p=XviD%40world.net+%28XvidWorld%29&max=250', u'type': u'movie', u'seed_ratio': u'', u'name': u'The.Art.of.the.Steal.2013.BDRip.XviD-NfS.nfo [01/70] - "The.Art.of.the.Steal.2013.BDRip.XviD-NfS.nfo" yEnc (1/1)'}, u'identifier': u'e224251e41fe494e8f7b57620f2f9271', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'000298ae', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'00ee6c785ef248328f260e7eec8115c8', u'quality': u'brrip'}, u'a34ab12605a949738baf1c0c3a15695b': {u'status': u'available', u'info': {u'size': 793.12, u'protocol': u'nzb', u'description': u'', u'url': u'https://www.binsearch.info/fcgi/nzb.fcgi?q=117974223', u'age': 68, u'id': u'117974223', u'score': -2, u'provider': u'BinSearch', u'seed_time': u'', u'provider_extra': u'', u'detail_url': u'https://www.binsearch.info/?b=The.Art.of.the.Steal.2013.HDRip.XviD-AQOS&g=alt.binaries.boneless&p=none%40none.com+%28Bonehead%29&max=250', u'type': u'movie', u'seed_ratio': u'', u'name': u'The.Art.of.the.Steal.2013.HDRip.XviD-AQOS [01/26] - "The.Art.of.the.Steal.2013.HDRip.XviD-AQOS.nfo" yEnc (1/1)'}, u'identifier': u'4cd0abd13711a9fe63133756c0285410', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'0002b7e1', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'a34ab12605a949738baf1c0c3a15695b', u'quality': u'brrip'}, u'72f44e880c3c4978aae939ad71402ce7': {u'status': u'available', u'info': {u'seeders': 34, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The Art of the Steal 2013 LIMITED 720p BRRip x264 AC3-UNDERCOVER', u'url': u'magnet:?xt=urn:btih:0719836DAF8E285C566797481AE8FE880719487B&dn=the+art+of+the+steal+2013+limited+720p+brrip+x264+ac3+undercover&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce', u'age': 1, u'seed_ratio': 0.0, u'leechers': 81, u'score': 541, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-720p-brrip-x264-ac3-undercover-t9000412.html', u'type': u'movie', u'id': u'9000412', u'size': 2232.32}, u'identifier': u'a44d376cc77288e8ccc375585af5af9b', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'000335d3', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'72f44e880c3c4978aae939ad71402ce7', u'quality': u'brrip'}, u'59010dc34122424d8a0ef5bee4fc2eb8': {u'status': u'available', u'info': {u'seeders': 114, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The Art of the Steal (2013) 720p BRrip.x264 SUJAIDR', u'url': u'magnet:?xt=urn:btih:5CC3326C1115A8F4F94311F1924F28445F8D1952&dn=the+art+of+the+steal+2013+720p+brrip+x264+sujaidr&tr=http%3A%2F%2Ftracker.pimp4003.net%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 1, u'seed_ratio': 0.0, u'leechers': 73, u'score': 1056, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-720p-brrip-x264-sujaidr-t9001162.html', u'type': u'movie', u'id': u'9001162', u'size': 785.3}, u'identifier': u'75e8270389300db233a49b1e802e5a3c', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'00033fc2', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'59010dc34122424d8a0ef5bee4fc2eb8', u'quality': u'brrip'}, u'bcdf7926211b4895a8730ac832aa1011': {u'status': u'available', u'info': {u'size': 778.57, u'protocol': u'nzb', u'description': u'', u'url': u'https://www.binsearch.info/fcgi/nzb.fcgi?q=117974508', u'age': 68, u'id': u'117974508', u'score': 17, u'provider': u'BinSearch', u'seed_time': u'', u'provider_extra': u'', u'detail_url': u'https://www.binsearch.info/?b=Art+of+the+Steal&g=alt.binaries.movies.xvid&p=here%40the.net+%28Par+Yer+Rars%29&max=250', u'type': u'movie', u'seed_ratio': u'', u'name': u'The Art of the Steal 2013 HDRip XviD-AQOS "Art of the Steal.nfo" (1/1)'}, u'identifier': u'3748b17c0040f313b42704b67a401427', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'00023179', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'bcdf7926211b4895a8730ac832aa1011', u'quality': u'brrip'}, u'9213cef04b384a2bbe8731ff82fe16ff': {u'status': u'available', u'info': {u'seeders': 86, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The Art of the Steal 2013 LIMITED 1080p BRRip h264 AAC-RARBG', u'url': u'magnet:?xt=urn:btih:154206E6390A03BBF01E61F013E1A52494A52DFA&dn=the+art+of+the+steal+2013+limited+1080p+brrip+h264+aac+rarbg&tr=udp%3A%2F%2F12.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 1, u'seed_ratio': 0.0, u'leechers': 143, u'score': 1092, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-1080p-brrip-h264-aac-rarbg-t9001241.html', u'type': u'movie', u'id': u'9001241', u'size': 1781.76}, u'identifier': u'9ab5cc07a4718ff5a4eff2a5c0a5b77c', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'0003ca03', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'9213cef04b384a2bbe8731ff82fe16ff', u'quality': u'brrip'}, u'9cc23887faf444f7b93a4bafb2647ac3': {u'status': u'available', u'info': {u'seeders': 38, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The Art of the Steal 2013 LIMITED 720p BRRip h264 AAC-RARBG', u'url': u'magnet:?xt=urn:btih:47B2EE9DC2245CA1AFCACD939CA603B9DBB18239&dn=the+art+of+the+steal+2013+limited+720p+brrip+h264+aac+rarbg&tr=udp%3A%2F%2F12.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 1, u'seed_ratio': 0.0, u'leechers': 40, u'score': 429, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-720p-brrip-h264-aac-rarbg-t9001238.html', u'type': u'movie', u'id': u'9001238', u'size': 1116.16}, u'identifier': u'e66074d518f9cbefbd04bc1342cbb32a', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'00030793', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'9cc23887faf444f7b93a4bafb2647ac3', u'quality': u'brrip'}, u'c18677b9357f4e60b328b42a6bba497a': {u'status': u'done', u'files': {u'nfo': [u'/mnt/vault/videos/Movies/Art of the Steal, The (2014)/The Art of the Steal.nfo'], u'movie': [u'/mnt/vault/videos/Movies/Art of the Steal, The (2014)/The Art of the Steal.mp4']}, u'identifier': u'tt2172985.None.720p', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'000566ec', u'_t': u'release', u'last_edit': 1397726295, u'_id': u'c18677b9357f4e60b328b42a6bba497a', u'quality': u'720p'}, u'c6379eb7b7144aa6ab333f06f5759947': {u'status': u'available', u'info': {u'seeders': 61, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The.Art.of.the.Steal.2013.LIMITED.BRRip.x264.AC3-MiLLENiUM', u'url': u'magnet:?xt=urn:btih:C3F24AD28CDC1F7A25AAD8B7D80BA9B5F1D7DAA8&dn=the+art+of+the+steal+2013+limited+brrip+x264+ac3+millenium&tr=udp%3A%2F%2F12.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 17, u'seed_ratio': 0.0, u'leechers': 64, u'score': 654, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-brrip-x264-ac3-millenium-t9002531.html', u'type': u'movie', u'id': u'9002531', u'size': 1013.09}, u'identifier': u'74373b65ea496c18bdecc6e3c7a5c110', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'0003027a', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'c6379eb7b7144aa6ab333f06f5759947', u'quality': u'brrip'}, u'2f88c95fb3b24a1d9aeff4686168ee9f': {u'status': u'available', u'info': {u'seeders': 38, u'protocol': u'torrent_magnet', u'description': u'', u'name': u'The.Art.of.the.Steal.2013.LIMITED.720p.BRRip.XviD.AC3-RARBG', u'url': u'magnet:?xt=urn:btih:A834FBF8A5E7E35DEAA544139148B40F4276332A&dn=the+art+of+the+steal+2013+limited+720p+brrip+xvid+ac3+rarbg&tr=udp%3A%2F%2F12.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337', u'age': 1, u'seed_ratio': 0.0, u'leechers': 68, u'score': 523, u'provider': u'KickAssTorrents', u'seed_time': 0, u'provider_extra': u'', u'detail_url': u'https://kickass.to/the-art-of-the-steal-2013-limited-720p-brrip-xvid-ac3-rarbg-t9000418.html', u'type': u'movie', u'id': u'9000418', u'size': 2437.12}, u'identifier': u'9caa0dbdb805a8e58af8a69240c74b9e', u'media_id': u'e16bb0f1d6484257a32b63d4b859555c', u'_rev': u'0003dbfa', u'_t': u'release', u'is_3d': False, u'last_edit': 1397721735, u'_id': u'2f88c95fb3b24a1d9aeff4686168ee9f', u'quality': u'brrip'}} -release = dict_diff(releases, releases_current) -test = release[release.keys()[0]]['status'] +os.environ['TR_TORRENT_DIR']="z:/downloads/complete/movie/The.Art.of.the.Steal.2013.LIMITED.1080p.BRRip.h264.AAC-RARBG" +os.environ['TR_TORRENT_NAME']="The.Art.of.the.Steal.2013.LIMITED.1080p.BRRip.h264.AAC-RARBG" +os.environ['TR_TORRENT_ID']="154206e6390a03bbf01e61f013e1a52494a52dfa" +os.environ['TR_TORRENT_HASH']="154206e6390a03bbf01e61f013e1a52494a52dfa" +#TorrentToMedia.main(sys.argv) # Initialize the config nzbtomedia.initialize() + +clientAgent = nzbtomedia.TORRENT_CLIENTAGENT +nzbName = 'Ron.White.A.Little.Unprofessional.2012.DVDRip.XViD-IGUANA[rarbg]' +download_id = '51C9B415382894727C5C7D8442554D3AC08B390F' + +if find_download(clientAgent, nzbName, download_id): + print 'found' +else: + print 'no luck' + print nzbtomedia.CFG['SickBear','NzbDrone']['tv'].isenabled() print nzbtomedia.CFG['SickBeard','NzbDrone']['tv'].isenabled()