From c048c03aa58b21590da45cd9621162aba9e7d970 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Wed, 23 Jul 2014 11:35:32 +0930 Subject: [PATCH] fix remote_Dri for HeadPhones. Fixes #499 Fix encoding on manual scan. --- TorrentToMedia.py | 26 ++++++++++++++--- nzbToMedia.py | 10 ++++++- nzbtomedia/autoProcess/autoProcessMusic.py | 2 +- nzbtomedia/autoProcess/autoProcessTV.py | 3 ++ nzbtomedia/nzbToMediaUtil.py | 34 +++++++++++++++++----- 5 files changed, 62 insertions(+), 13 deletions(-) diff --git a/TorrentToMedia.py b/TorrentToMedia.py index b82e3f31..f86a6b07 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -39,12 +39,17 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, inputDirectory, inputName, inputCategory, root = nzbtomedia.category_search(inputDirectory, inputName, inputCategory, root, - nzbtomedia.CATEGORIES) # Confirm the category by parsing directory structure - + nzbtomedia.CATEGORIES) # Confirm the category by parsing directory structure if inputCategory == "": inputCategory = "UNCAT" usercat = inputCategory + try: + inputName = inputName.encode(nzbtomedia.SYS_ENCODING) + except: pass + try: + inputDirectory = inputDirectory.encode(nzbtomedia.SYS_ENCODING) + except: pass logger.debug("Determined Directory: %s | Name: %s | Category: %s" % (inputDirectory, inputName, inputCategory)) @@ -98,6 +103,9 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, else: outputDestination = os.path.normpath( nzbtomedia.os.path.join(nzbtomedia.OUTPUTDIRECTORY, inputCategory)) + try: + outputDestination = outputDestination.encode(nzbtomedia.SYS_ENCODING) + except: pass logger.info("Output directory set to: %s" % (outputDestination)) @@ -129,7 +137,9 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, nzbtomedia.os.path.join(outputDestination, os.path.basename(filePath)), fullFileName) logger.debug( "Setting outputDestination to %s to preserve folder structure" % (os.path.dirname(targetFile))) - + try: + targetFile = targetFile.encode(nzbtomedia.SYS_ENCODING) + except: pass if root == 1: if not foundFile: logger.debug("Looking for %s in: %s" % (inputName, inputFile)) @@ -286,7 +296,15 @@ def main(args): if clientAgent.lower() not in nzbtomedia.TORRENT_CLIENTS and clientAgent != 'manual': continue - results = processTorrent(dirName, os.path.basename(dirName), subsection, inputHash, inputID, + try: + dirName = dirName.encode(nzbtomedia.SYS_ENCODING) + except: pass + inputName = os.path.basename(dirName) + try: + inputName = inputName.encode(nzbtomedia.SYS_ENCODING) + except: pass + + results = processTorrent(dirName, inputName, subsection, inputHash, inputID, clientAgent) if results[0] != 0: logger.error("A problem was reported when trying to perform a manual run for %s:%s." % ( diff --git a/nzbToMedia.py b/nzbToMedia.py index bb56ceed..661e383a 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -727,7 +727,15 @@ def main(args, section=None): if clientAgent.lower() not in nzbtomedia.NZB_CLIENTS and clientAgent != 'manual': continue - results = process(dirName, os.path.basename(dirName), 0, clientAgent=clientAgent, + try: + dirName = dirName.encode(nzbtomedia.SYS_ENCODING) + except: pass + inputName = os.path.basename(dirName) + try: + inputName = inputName.encode(nzbtomedia.SYS_ENCODING) + except: pass + + results = process(dirName, inputName, 0, clientAgent=clientAgent, download_id=download_id, inputCategory=subsection) if results[0] != 0: logger.error("A problem was reported when trying to perform a manual run for %s:%s." % ( diff --git a/nzbtomedia/autoProcess/autoProcessMusic.py b/nzbtomedia/autoProcess/autoProcessMusic.py index f6c4c029..5db7ed9f 100644 --- a/nzbtomedia/autoProcess/autoProcessMusic.py +++ b/nzbtomedia/autoProcess/autoProcessMusic.py @@ -94,7 +94,7 @@ class autoProcessMusic: params['dir'] = os.path.dirname(dirName) if remote_path: - params['dir'] = remoteDir(dirName) + params['dir'] = remoteDir(os.path.dirname(dirName)) release_status = self.get_status(url, apikey, dirName) if not release_status: diff --git a/nzbtomedia/autoProcess/autoProcessTV.py b/nzbtomedia/autoProcess/autoProcessTV.py index 09317723..0b715e6a 100644 --- a/nzbtomedia/autoProcess/autoProcessTV.py +++ b/nzbtomedia/autoProcess/autoProcessTV.py @@ -126,6 +126,9 @@ class autoProcessTV: logger.info('Found corrupt videos. Setting status Failed') status = 1 failed = 1 + elif clientAgent == "manual" and not listMediaFiles(dirName, media=True, audio=False, meta=False, archives=True): + logger.warning("No media files found in directory %s to manually process." % (dirName), section) + return [0, ""] # Success (as far as this script is concerned) if fork not in nzbtomedia.SICKBEARD_TORRENT or (clientAgent in ['nzbget','sabnzbd'] and nzbExtractionBy != "Destination"): if inputName: diff --git a/nzbtomedia/nzbToMediaUtil.py b/nzbtomedia/nzbToMediaUtil.py index a611abb8..ee216c0c 100644 --- a/nzbtomedia/nzbToMediaUtil.py +++ b/nzbtomedia/nzbToMediaUtil.py @@ -40,6 +40,9 @@ def sanitizeName(name): # remove leading/trailing periods and spaces name = name.strip(' .') + try: + name = name.encode(nzbtomedia.SYS_ENCODING) + except: pass return name @@ -69,6 +72,13 @@ def remoteDir(path): def category_search(inputDirectory, inputName, inputCategory, root, categories): tordir = False + try: + inputName = inputName.encode(nzbtomedia.SYS_ENCODING) + except: pass + try: + inputDirectory = inputDirectory.encode(nzbtomedia.SYS_ENCODING) + except: pass + if inputDirectory is None: # =Nothing to process here. return inputDirectory, inputName, inputCategory, root @@ -518,6 +528,10 @@ def getDirs(section, subsection): title = os.path.splitext(os.path.basename(mediafile))[0] newPath = os.path.join(path, sanitizeName(title)) + try: + newPath = newPath.encode(nzbtomedia.SYS_ENCODING) + except: pass + # Just fail-safe incase we already have afile with this clean-name (was actually a bug from earlier code, but let's be safe). if os.path.isfile(newPath): newPath2 = os.path.join(os.path.join(os.path.split(newPath)[0], 'new'), os.path.split(newPath)[1]) @@ -527,8 +541,13 @@ def getDirs(section, subsection): if not os.path.exists(newPath): makeDir(newPath) + newfile = os.path.join(newPath, sanitizeName(os.path.split(mediafile)[1])) + try: + newfile = newfile.encode(nzbtomedia.SYS_ENCODING) + except: pass + # link file to its new path - copy_link(mediafile, os.path.join(newPath, sanitizeName(os.path.split(mediafile)[1])), 'hard') + copy_link(mediafile, newfile, 'hard') except Exception as e: logger.error("Failed to move %s to its own directory: %s" % (os.path.split(mediafile)[1], e)) @@ -548,12 +567,13 @@ def getDirs(section, subsection): except Exception as e: logger.error("Failed to add directories from %s for post-processing: %s" % (nzbtomedia.CFG[section][subsection]["watch_dir"], e)) - try: - outputDirectory = os.path.join(nzbtomedia.OUTPUTDIRECTORY, subsection) - if os.path.exists(outputDirectory): - to_return.extend(processDir(outputDirectory)) - except Exception as e: - logger.error("Failed to add directories from %s for post-processing: %s" % (nzbtomedia.OUTPUTDIRECTORY, e)) + if nzbtomedia.USELINK == 'move': + try: + outputDirectory = os.path.join(nzbtomedia.OUTPUTDIRECTORY, subsection) + if os.path.exists(outputDirectory): + to_return.extend(processDir(outputDirectory)) + except Exception as e: + logger.error("Failed to add directories from %s for post-processing: %s" % (nzbtomedia.OUTPUTDIRECTORY, e)) if not to_return: logger.debug("No directories identified in %s:%s for post-processing" % (section,subsection))