From 08a05ef74835b005704c5e589827a20279c6c9fa Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Mon, 25 Feb 2013 23:19:11 -0800 Subject: [PATCH 1/3] 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 2/3] 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() From ec6398fcb6fc2aaffc9376c21f8e757ea32e96c9 Mon Sep 17 00:00:00 2001 From: Jon Monroe Date: Tue, 26 Feb 2013 08:55:35 -0500 Subject: [PATCH 3/3] Simplified is_sample --- TorrentToMedia.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 81b7a52f..9a5e5af3 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -125,12 +125,10 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories): def is_sample(filePath, inputName): # 200 MB in bytes + # Maybe let the users change this? SIZE_CUTOFF = 200 * 1024 * 1024 # Ignore 'sample' in files unless 'sample' in Torrent Name - if ('sample' in filePath.lower()) and (not 'sample' in inputName) and (os.path.getsize(filePath) < SIZE_CUTOFF): - return True - else: - return False + return ('sample' in filePath.lower()) and (not 'sample' in inputName) and (os.path.getsize(filePath) < SIZE_CUTOFF) def copy_link(source, target, useLink, outputDestination): # Create destination folder