added noFlatten categories and runOnce userscript. Fixes #262

This commit is contained in:
clinton-hall 2014-02-13 13:57:48 +10:30
commit 19485f4db4
2 changed files with 21 additions and 4 deletions

View file

@ -117,14 +117,21 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
delugeClient.core.pause_torrent([inputID]) delugeClient.core.pause_torrent([inputID])
time.sleep(5) # Give Torrent client some time to catch up with the change 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() now = datetime.datetime.now()
for dirpath, dirnames, filenames in os.walk(inputDirectory): for dirpath, dirnames, filenames in os.walk(inputDirectory):
for file in filenames: for file in filenames:
filePath = os.path.join(dirpath, file) filePath = os.path.join(dirpath, file)
fileName, fileExtension = os.path.splitext(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) targetDirectory = os.path.join(outputDestination, file)
if root == 1: if root == 1:
@ -203,7 +210,9 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
else: else:
Logger.debug("MAIN: Ignoring unknown filetype %s for file %s", fileExtension, filePath) Logger.debug("MAIN: Ignoring unknown filetype %s for file %s", fileExtension, filePath)
continue 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) flatten(outputDestination)
# Now check if movie files exist in destination: # 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: if fileExtension in user_script_mediaExtensions or "ALL" in user_script_mediaExtensions:
num_files = num_files + 1 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] command = [user_script]
for param in user_script_param: for param in user_script_param:
if param == "FN": if param == "FN":
@ -412,6 +423,7 @@ if __name__ == "__main__":
useLink = config.get("Torrent", "useLink") # no | hard | sym useLink = config.get("Torrent", "useLink") # no | hard | sym
outputDirectory = config.get("Torrent", "outputDirectory") # /abs/path/to/complete/ outputDirectory = config.get("Torrent", "outputDirectory") # /abs/path/to/complete/
categories = (config.get("Torrent", "categories")).split(',') # music,music_videos,pictures,software 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/ uTorrentWEBui = config.get("Torrent", "uTorrentWEBui") # http://localhost:8090/gui/
uTorrentUSR = config.get("Torrent", "uTorrentUSR") # mysecretusr 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_successCodes = (config.get("UserScript", "user_script_successCodes")).split(',')
user_script_clean = int(config.get("UserScript", "user_script_clean")) user_script_clean = int(config.get("UserScript", "user_script_clean"))
user_delay = int(config.get("UserScript", "delay")) user_delay = int(config.get("UserScript", "delay"))
user_script_runOnce = int(config.get("UserScript", "user_script_runOnce"))
transcode = int(config.get("Transcoder", "transcode")) transcode = int(config.get("Transcoder", "transcode"))

View file

@ -84,7 +84,9 @@ useLink = hard
###### outputDirectory - Default output directory (categories will be appended as sub directory to outputDirectory) ###### outputDirectory - Default output directory (categories will be appended as sub directory to outputDirectory)
outputDirectory = /abs/path/to/complete/ outputDirectory = /abs/path/to/complete/
###### Other categories/labels defined for your downloader. Does not include CouchPotato, SickBeard, HeadPhones, Mylar categories. ###### 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) ###### uTorrent Hardlink solution (You must edit this if your using TorrentToMedia.py with uTorrent)
uTorrentWEBui = http://localhost:8090/gui/ uTorrentWEBui = http://localhost:8090/gui/
uTorrentUSR = your username 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). #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 #So the result is /media/test/script/script.sh FP FN DN. Add other arguments as needed eg -f, -r
user_script_param = FN 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 #Specify the successcodes returned by the user script as a comma separated list. Linux default is 0
user_script_successCodes = 0 user_script_successCodes = 0
#Clean after? Note that delay function is used to prevent possible mistake :) Delay is intended as seconds #Clean after? Note that delay function is used to prevent possible mistake :) Delay is intended as seconds