From dc379491e8ceb5e3bc75403397ce9c2ab861e172 Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Mon, 25 Feb 2013 22:34:24 -0800 Subject: [PATCH 1/4] Lowered utorrent args by 1. remove uselink test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we don't pass sys.argv[1] as 'utorrent' we need to reduce the input arg numbers by 1. We can't (as I understand) test for useLink here unless we pass it in... so let's just set up utorrentClass anyway and test for uselink back in TorrentToMedia.py also added try, except as this can cause issues if these parameters are not passed in... maybe a bit unnecessary, but doesn't hurt.  --- nzbToMediaUtil.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/nzbToMediaUtil.py b/nzbToMediaUtil.py index 0078068d..61f96ee2 100644 --- a/nzbToMediaUtil.py +++ b/nzbToMediaUtil.py @@ -18,14 +18,17 @@ def parse_other(args): def parse_utorrent(args): # uTorrent usage: call TorrentToMedia.py "%D" "%N" "%L" "%I" - inputDirectory = os.path.normpath(sys.argv[2]) - inputName = sys.argv[3] + inputDirectory = os.path.normpath(sys.argv[1]) + inputName = sys.argv[2] try: - inputCategory = sys.argv[4] + inputCategory = sys.argv[3] except: inputCategory = '' - inputHash = sys.argv[5] - if inputHash and useLink: + try: + inputHash = sys.argv[4] + except: + inputHash = '' + if inputHash: utorrentClass = UTorrentClient(uTorrentWEBui, uTorrentUSR, uTorrentPWD) def parse_deluge(args): From 36a3dabadb42befbcaeb484f700b1d4b78d7b4a4 Mon Sep 17 00:00:00 2001 From: Berkona Date: Tue, 26 Feb 2013 02:07:22 -0500 Subject: [PATCH 2/4] Forgot to add linkage between our new function parsing and TorrentToMedia --- TorrentToMedia.py | 7 ++++++- nzbToMediaUtil.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 4ff1949b..6b9e7f57 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -22,6 +22,11 @@ from utorrent.client import UTorrentClient nzbtomedia_configure_logging(os.path.dirname(sys.argv[0])) Logger = logging.getLogger(__name__) + +def category_search_recurs(inputDirectory, inputName, root, categories): + pass + + def category_search(inputDirectory, inputName, inputCategory, root, categories): categorySearch = [os.path.normpath(inputDirectory),""] #initializie notfound = 0 @@ -272,7 +277,7 @@ config.read(configFilename) clientAgent = config.get("Torrent", "clientAgent") try: - parse_args(clientAgent) + inputDirectory, inputName, inputCategory = parse_args(clientAgent) except: Logger.error("MAIN: There was a problem loading variables: Exiting") sys.exit(-1) diff --git a/nzbToMediaUtil.py b/nzbToMediaUtil.py index 61f96ee2..0adad281 100644 --- a/nzbToMediaUtil.py +++ b/nzbToMediaUtil.py @@ -13,9 +13,11 @@ def nzbtomedia_configure_logging(dirname): fileHandler.level = logging.DEBUG logging.getLogger().addHandler(fileHandler) + def parse_other(args): return os.path.normpath(sys.argv[1]), '', '' + def parse_utorrent(args): # uTorrent usage: call TorrentToMedia.py "%D" "%N" "%L" "%I" inputDirectory = os.path.normpath(sys.argv[1]) @@ -28,20 +30,28 @@ def parse_utorrent(args): inputHash = sys.argv[4] except: inputHash = '' + if inputHash: utorrentClass = UTorrentClient(uTorrentWEBui, uTorrentUSR, uTorrentPWD) + return inputDirectory, inputName, inputCategory + + def parse_deluge(args): # Deluge usage: call TorrentToMedia.py TORRENT_ID TORRENT_NAME TORRENT_DIR inputDirectory = os.path.normpath(sys.argv[3]) inputName = sys.argv[2] inputCategory = '' # We dont have a category yet + return inputDirectory, inputName, inputCategory + def parse_transmission(args): # Transmission usage: call TorrenToMedia.py (%TR_TORRENT_DIR% %TR_TORRENT_NAME% is passed on as environmental variables) inputDirectory = os.path.normpath(os.getenv('TR_TORRENT_DIR')) inputName = os.getenv('TR_TORRENT_NAME') inputCategory = '' # We dont have a category yet + return inputDirectory, inputName, inputCategory + __ARG_PARSERS__ = { 'other': parse_other, @@ -50,8 +60,9 @@ __ARG_PARSERS__ = { 'transmission': parse_transmission, } + def parse_args(clientAgent): parseFunc = __ARG_PARSERS__.get(clientAgent, None) if not parseFunc: raise RuntimeError("Could not find client-agent") - parseFunc(sys.argv) + return parseFunc(sys.argv) From 08a05ef74835b005704c5e589827a20279c6c9fa Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Mon, 25 Feb 2013 23:19:11 -0800 Subject: [PATCH 3/4] check for CPS renamer complete. + comments Can we still use logger while logfile open? We might want to review those two log entries... or add logging to the autoPorcess* scripts. --- TorrentToMedia.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 6b9e7f57..0a1cb3b3 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -393,6 +393,7 @@ for dirpath, dirnames, filenames in os.walk(outputDestination): Logger.info("file %s is a sample file. Removing", filePath) os.unlink(filePath) #remove samples else: + videofile = filePath video2 = video2 + 1 if video2 >= video and video2 > 0: # Check that all video files were moved status = 0 @@ -408,12 +409,6 @@ elif failed_extract == 1 and failed_link == 0: #failed to extract files only. else: Logger.info("MAIN: Something failed! Please check logs. Exiting") sys.exit(-1) -# Now we pass off to CouchPotato or Sick-Beard -# Log this output -old_stdout = sys.stdout # Still crude, but we wat to capture this for now -logFile = os.path.join(os.path.dirname(sys.argv[0]), "postprocess.log") -log_file = open(logFile,"a+") -sys.stdout = log_file # Hardlink solution with uTorrent if inputHash and useLink: @@ -421,16 +416,32 @@ if inputHash and useLink: utorrentClass.stop(inputHash) time.sleep(5) # Give uTorrent some time to catch up with the change +# Log this output +old_stdout = sys.stdout # Still crude, but we wat to capture this for now +logFile = os.path.join(os.path.dirname(sys.argv[0]), "postprocess.log") +log_file = open(logFile,"a+") +sys.stdout = log_file + +# Now we pass off to CouchPotato or Sick-Beard if inputCategory == movieCategory: - Logger.info("MAIN: Calling postprocessing script for CouchPotatoServer") + Logger.info("MAIN: Calling postprocessing script for CouchPotatoServer") ###can we use logger while logfile open? autoProcessMovie.process(outputDestination, inputName, status) elif inputCategory == tvCategory: - Logger.info("MAIN: Calling postprocessing script for Sick-Beard") + Logger.info("MAIN: Calling postprocessing script for Sick-Beard") ###can we use logger while logfile open? autoProcessTV.processEpisode(outputDestination, inputName, status) +sys.stdout = old_stdout +log_file.close() + +now = datetime.datetime.now() #set time for timeout +while os.path.exists(videofile): #while this file is still here, CPS hasn't finished renaming + if (datetime.datetime.now() - now) > datetime.timedelta(minutes=3): #note; minimum 1 minute delay in autoProcessMovie + Logger.info("MAIN: The file %s has not been moved after 3 minutes.") + break +else: #CPS (and SickBeard) have finished. We can now resume seeding. + Logger.info("MAIN: The file %s has been moved. Postprocessing appears to have succeeded." %videofile) + # Hardlink solution with uTorrent if inputHash and useLink: Logger.debug("MAIN: We are using hardlinks with uTorrent, calling uTorrent to resume download") utorrentClass.start(inputHash) -sys.stdout = old_stdout -log_file.close() \ No newline at end of file From e652fad81398c8fbfe3d59750fe5fdd43a7ef2b9 Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Mon, 25 Feb 2013 23:24:20 -0800 Subject: [PATCH 4/4] indenting We need to work on a standard... do we want to use tabs, 2 spaces, or 4 spaces? Most of what I did originally used 4 spaces (I think this is the default for idle). --- TorrentToMedia.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 0a1cb3b3..81b7a52f 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -427,8 +427,8 @@ if inputCategory == movieCategory: Logger.info("MAIN: Calling postprocessing script for CouchPotatoServer") ###can we use logger while logfile open? autoProcessMovie.process(outputDestination, inputName, status) elif inputCategory == tvCategory: - Logger.info("MAIN: Calling postprocessing script for Sick-Beard") ###can we use logger while logfile open? - autoProcessTV.processEpisode(outputDestination, inputName, status) + Logger.info("MAIN: Calling postprocessing script for Sick-Beard") ###can we use logger while logfile open? + autoProcessTV.processEpisode(outputDestination, inputName, status) sys.stdout = old_stdout log_file.close()