From 19485f4db4100f9d1de7d34e660057f9f5d41adf Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 13 Feb 2014 13:57:48 +1030 Subject: [PATCH] added noFlatten categories and runOnce userscript. Fixes #262 --- TorrentToMedia.py | 19 ++++++++++++++++--- autoProcessMedia.cfg.sample | 6 +++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index 9f36fde0..eb0950d6 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -117,14 +117,21 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): delugeClient.core.pause_torrent([inputID]) time.sleep(5) # Give Torrent client some time to catch up with the change - Logger.debug("MAIN: Scanning files in directory: %s", inputDirectory) - + Logger.debug("MAIN: Scanning files in directory: %s", inputDirectory) + + outputDestinationMaster = outputDestination # Save the original, so we can cahnge this within the lopp below, and reset afterwards. now = datetime.datetime.now() for dirpath, dirnames, filenames in os.walk(inputDirectory): for file in filenames: filePath = os.path.join(dirpath, file) fileName, fileExtension = os.path.splitext(file) + if inputCategory in noFlatten: + newDir = dirpath # find the full path + newDir = newDir.replace(inputDirectory, "") #find the extra-depth directory + outputDestination = os.path.join(outputDestinationMaster, newDir) # join this extra directory to output. + Logger.debug("MAIN: Setting outputDestination to %s to preserve folder structure", outputDestination) + targetDirectory = os.path.join(outputDestination, file) if root == 1: @@ -203,7 +210,9 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): else: Logger.debug("MAIN: Ignoring unknown filetype %s for file %s", fileExtension, filePath) continue - if not inputCategory in hpCategory: #don't flatten hp in case multi cd albums, and we need to copy this back later. + + outputDestination = outputDestinationMaster # Reset here. + if not inputCategory in hpCategory and not inputCategory in noFlatten: #don't flatten hp in case multi cd albums, and we need to copy this back later. flatten(outputDestination) # Now check if movie files exist in destination: @@ -331,6 +340,8 @@ def external_script(outputDestination): if fileExtension in user_script_mediaExtensions or "ALL" in user_script_mediaExtensions: num_files = num_files + 1 + if user_script_runOnce == 1 and num_files > 1: we have already run once, so just continue to get number of files. + continue command = [user_script] for param in user_script_param: if param == "FN": @@ -412,6 +423,7 @@ if __name__ == "__main__": useLink = config.get("Torrent", "useLink") # no | hard | sym outputDirectory = config.get("Torrent", "outputDirectory") # /abs/path/to/complete/ categories = (config.get("Torrent", "categories")).split(',') # music,music_videos,pictures,software + noFlatten = (config.get("Torrent", "noFlatten")).split(',') uTorrentWEBui = config.get("Torrent", "uTorrentWEBui") # http://localhost:8090/gui/ uTorrentUSR = config.get("Torrent", "uTorrentUSR") # mysecretusr @@ -455,6 +467,7 @@ if __name__ == "__main__": user_script_successCodes = (config.get("UserScript", "user_script_successCodes")).split(',') user_script_clean = int(config.get("UserScript", "user_script_clean")) user_delay = int(config.get("UserScript", "delay")) + user_script_runOnce = int(config.get("UserScript", "user_script_runOnce")) transcode = int(config.get("Transcoder", "transcode")) diff --git a/autoProcessMedia.cfg.sample b/autoProcessMedia.cfg.sample index fbbac8e1..f46357b3 100644 --- a/autoProcessMedia.cfg.sample +++ b/autoProcessMedia.cfg.sample @@ -84,7 +84,9 @@ useLink = hard ###### outputDirectory - Default output directory (categories will be appended as sub directory to outputDirectory) outputDirectory = /abs/path/to/complete/ ###### Other categories/labels defined for your downloader. Does not include CouchPotato, SickBeard, HeadPhones, Mylar categories. -categories = music_videos,pictures,software, +categories = music_videos,pictures,software,manual +###### A list of categories that you don't want to be flattened (i.e preserve the directory structure when copying/linking. +noFlatten = pictures,manual ###### uTorrent Hardlink solution (You must edit this if your using TorrentToMedia.py with uTorrent) uTorrentWEBui = http://localhost:8090/gui/ uTorrentUSR = your username @@ -151,6 +153,8 @@ user_script_path = /media/test/script/script.sh #for example FP,FN,DN for file path (absolute file name with path), file name, absolute directory name (with path). #So the result is /media/test/script/script.sh FP FN DN. Add other arguments as needed eg -f, -r user_script_param = FN +#Set user_script_runOnce = 0 to run for each file, or 1 to only run once (presumably on teh entire directory). +user_script_runOnce = 0 #Specify the successcodes returned by the user script as a comma separated list. Linux default is 0 user_script_successCodes = 0 #Clean after? Note that delay function is used to prevent possible mistake :) Delay is intended as seconds