diff --git a/TorrentToMedia.py b/TorrentToMedia.py index f22c40c6..bc03ddf5 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -131,7 +131,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): Logger.debug("MAIN: Scanning files in directory: %s", inputDirectory) - noFlatten.extend(config.get_categories(["HeadPhones"]).values()) # Make sure we preserve folder structure for HeadPhones. + noFlatten.extend(list(chain.from_iterable(config.get_sections(["HeadPhones"]).values()))) # Make sure we preserve folder structure for HeadPhones. outputDestinationMaster = outputDestination # Save the original, so we can change this within the loop below, and reset afterwards. now = datetime.datetime.now() @@ -173,7 +173,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): continue # This file has not been recently moved or created, skip it if fileExtension in mediaContainer: # If the file is a video file - if is_sample(filePath, inputName, minSampleSize, SampleIDs) and not inputCategory in config.get_categories(["HeadPhones"]).values(): # Ignore samples + if is_sample(filePath, inputName, minSampleSize, SampleIDs) and not inputCategory in config.get_sections(["HeadPhones"]).values(): # Ignore samples Logger.info("MAIN: Ignoring sample file: %s ", filePath) continue else: @@ -209,7 +209,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): except: Logger.exception("MAIN: Extraction failed for: %s", file) continue - elif not inputCategory in list(chain.from_iterable(config.get_categories(['CouchPotato','SickBeard']).values())): #process all for non-video categories. + elif not inputCategory in list(chain.from_iterable(config.get_sections(['CouchPotato','SickBeard']).values())): #process all for non-video categories. Logger.info("MAIN: Found file %s for category %s", filePath, inputCategory) copy_link(filePath, targetDirectory, useLink, outputDestination) copy_list.append([filePath, os.path.join(outputDestination, file)]) @@ -223,7 +223,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): flatten(outputDestination) # Now check if movie files exist in destination: - if inputCategory in list(chain.from_iterable(config.get_categories(['CouchPotato','SickBeard']).values())): + if inputCategory in list(chain.from_iterable(config.get_sections(['CouchPotato','SickBeard']).values())): for dirpath, dirnames, filenames in os.walk(outputDestination): for file in filenames: filePath = os.path.join(dirpath, file) @@ -248,7 +248,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID): if (inputCategory in user_script_categories and not "NONE" in user_script_categories) or ("ALL" in user_script_categories and not inputCategory in processCategories): Logger.info("MAIN: Processing user script %s.", user_script) result = external_script(outputDestination,inputName,inputCategory) - elif status == int(0) or (inputCategory in list(chain.from_iterable(config.get_categories(['HeadPhones','Mylar','Gamez']).values()))): # if movies linked/extracted or for other categories. + elif status == int(0) or (inputCategory in list(chain.from_iterable(config.get_sections(['HeadPhones','Mylar','Gamez']).values()))): # if movies linked/extracted or for other categories. Logger.debug("MAIN: Calling autoProcess script for successful download.") status = int(0) # hp, my, gz don't support failed. else: @@ -435,7 +435,7 @@ if __name__ == "__main__": minSampleSize = int(config()["Extensions"]["minSampleSize"]) # 200 (in MB) SampleIDs = (config()["Extensions"]["SampleIDs"]) # sample,-s. - sections = config.get_categories(["CouchPotato", "SickBeard", "HeadPhones", "Mylar", "Gamez"]) + sections = config.get_sections(["CouchPotato", "SickBeard", "HeadPhones", "Mylar", "Gamez"]) categories += list(chain.from_iterable(sections.values())) user_script_categories = config()["UserScript"]["user_script_categories"] # NONE diff --git a/nzbToCouchPotato.py b/nzbToCouchPotato.py index 691205cb..08818246 100755 --- a/nzbToCouchPotato.py +++ b/nzbToCouchPotato.py @@ -149,7 +149,7 @@ else: sys.exit(-1) # setup sections and categories -categories = config.get_categories(["CouchPotato"]) +sections = config.get_sections(["CouchPotato"]) WakeUp() @@ -239,13 +239,13 @@ else: Logger.warn("MAIN: Invalid number of arguments received from client.") Logger.info("MAIN: Running autoProcessMovie as a manual run...") - for section, category in categories.items(): - for dirName in get_dirnames(section, category): - Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) - results = autoProcessMovie().process(dirName, dirName, 0) - if results != 0: - result = 1 - Logger.info("MAIN: A problem was reported in the autoProcessMovie script.") + for section, categories in sections.items(): + for category in categories: + dirNames = get_dirnames(section, category) + for dirName in dirNames: + Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) + results = autoProcessMovie().process(dirName, dirName, 0, inputCategory=category) + if results != 0:result = results if result == 0: Logger.info("MAIN: The autoProcessMovie script completed successfully.") diff --git a/nzbToGamez.py b/nzbToGamez.py index 75654e61..7ecc6d82 100755 --- a/nzbToGamez.py +++ b/nzbToGamez.py @@ -84,7 +84,7 @@ else: sys.exit(-1) # gamez category -categories = config.get_categories(['Gamez']) +sections = config.get_sections(['Gamez']) WakeUp() @@ -166,13 +166,13 @@ else: Logger.warn("MAIN: Invalid number of arguments received from client. Exiting") Logger.info("MAIN: Running autoProcessGames as a manual run...") - for section, category in categories.items(): - for dirName in get_dirnames(section, category): - Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) - results = autoProcessGames().process(dirName, dirName, 0) - if results != 0: - result = 1 - Logger.info("MAIN: A problem was reported in the autoProcessGames script.") + for section, categories in sections.items(): + for category in categories: + dirNames = get_dirnames(section, category) + for dirName in dirNames: + Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) + results = autoProcessGames().process(dirName, dirName, 0, inputCategory=category) + if results != 0:result = results if result == 0: Logger.info("MAIN: The autoProcessGames script completed successfully.") diff --git a/nzbToHeadPhones.py b/nzbToHeadPhones.py index 9b4d47a9..94708a5c 100755 --- a/nzbToHeadPhones.py +++ b/nzbToHeadPhones.py @@ -97,7 +97,7 @@ else: sys.exit(-1) # headphones category -categories = config.get_categories(["HeadPhones"]) +sections = config.get_sections(["HeadPhones"]) WakeUp() @@ -179,13 +179,13 @@ else: Logger.warn("MAIN: Invalid number of arguments received from client.") Logger.info("MAIN: Running autoProcessMusic as a manual run...") - for section, category in categories.items(): - for dirName in get_dirnames(section, category): - Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) - results = autoProcessMusic().process(dirName, dirName, 0) - if results != 0: - result = 1 - Logger.info("MAIN: A problem was reported in the autoProcessMusic script.") + for section, categories in sections.items(): + for category in categories: + dirNames = get_dirnames(section, category) + for dirName in dirNames: + Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) + results = autoProcessMusic().process(dirName, dirName, 0, inputCategory=category) + if results != 0:result = results if result == 0: Logger.info("MAIN: The autoProcessMusic script completed successfully.") @@ -195,3 +195,4 @@ else: Logger.info("MAIN: A problem was reported in the autoProcessMusic script.") if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 sys.exit(config.NZBGET_POSTPROCESS_ERROR) + diff --git a/nzbToMedia.py b/nzbToMedia.py index bf2a9de9..ce4b6045 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -362,7 +362,7 @@ else: sys.exit(-1) # setup sections and categories -sections = config.get_categories(["CouchPotato","SickBeard","HeadPhones","Mylar","Gamez"]) +sections = config.get_sections(["CouchPotato","SickBeard","HeadPhones","Mylar","Gamez"]) WakeUp() @@ -454,9 +454,11 @@ else: Logger.warn("MAIN: Invalid number of arguments received from client.") for section, categories in sections.items(): for category in categories: - dirnames = get_dirnames(section, category) + dirNames = get_dirnames(section, category) Logger.info("MAIN: Running " + section + ":" + category + " as a manual run...") - if process(dirnames, inputName=dirnames, status=0, inputCategory=category, clientAgent = "manual") != 0: + results = process(dirNames, inputName=dirNames, status=0, inputCategory=category, clientAgent = "manual") + if results != 0: + result = results Logger.info("MAIN: A problem was reported when trying to manually run " + section + ":" + category + ".") if result == 0: diff --git a/nzbToMylar.py b/nzbToMylar.py index 29e1a4a8..ac48d837 100755 --- a/nzbToMylar.py +++ b/nzbToMylar.py @@ -89,7 +89,7 @@ else: sys.exit(-1) # mylar category -categories = config.get_categories(["Mylar"]) +sections = config.get_sections(["Mylar"]) WakeUp() @@ -171,13 +171,13 @@ else: Logger.warn("MAIN: Invalid number of arguments received from client.") Logger.info("MAIN: Running autoProcessComics as a manual run...") - for section, category in categories.items(): - for dirName in get_dirnames(section, category): - Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) - results = autoProcessComics().processEpisode(dirName, dirName, 0) - if results != 0: - result = 1 - Logger.info("MAIN: A problem was reported in the autoProcessComics script.") + for section, categories in sections.items(): + for category in categories: + dirNames = get_dirnames(section, category) + for dirName in dirNames: + Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) + results = autoProcessComics().processEpisode(dirName, dirName, 0, inputCategory=category) + if results != 0:result = results if result == 0: Logger.info("MAIN: The autoProcessComics script completed successfully.") diff --git a/nzbToSickBeard.py b/nzbToSickBeard.py index 7c759fd9..584eea37 100755 --- a/nzbToSickBeard.py +++ b/nzbToSickBeard.py @@ -151,7 +151,7 @@ else: sys.exit(-1) # sickbeard category -categories = config.get_categories(["SickBeard"]) +sections = config.get_sections(["SickBeard"]) WakeUp() @@ -236,13 +236,13 @@ else: Logger.debug("MAIN: Invalid number of arguments received from client.") Logger.info("MAIN: Running autoProcessTV as a manual run...") - for section, category in categories.items(): - for dirName in get_dirnames(section, category): - Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) - results = autoProcessTV().processEpisode(dirName, dirName, 0) - if results != 0: - result = 1 - Logger.info("MAIN: A problem was reported in the autoProcessTV script.") + for section, categories in sections.items(): + for category in categories: + dirNames = get_dirnames(section, category) + for dirName in dirNames: + Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) + results = autoProcessTV().processEpisode(dirName, dirName, 0, inputCategory=category) + if results != 0:result = results if result == 0: Logger.info("MAIN: The autoProcessTV script completed successfully.") diff --git a/nzbtomedia/autoProcess/autoProcessMovie.py b/nzbtomedia/autoProcess/autoProcessMovie.py index a2a02e07..186f9456 100644 --- a/nzbtomedia/autoProcess/autoProcessMovie.py +++ b/nzbtomedia/autoProcess/autoProcessMovie.py @@ -14,6 +14,7 @@ from nzbtomedia.nzbToMediaUtil import getDirectorySize, convert_to_ascii Logger = logging.getLogger() class autoProcessMovie: + def get_imdb(self, nzbName, dirName): imdbid = "" @@ -41,18 +42,18 @@ class autoProcessMovie: def get_movie_info(self, baseURL, imdbid, download_id): - movie_id = "" + movie_id = None movie_status = None - release_status = None - if not imdbid and not download_id: - return movie_id, imdbid, download_id, movie_status, release_status - - releaselist = [] movieid = [] moviestatus = [] library = [] release = [] offset = int(0) + release_status = None + + if not imdbid and not download_id: + return movie_id, imdbid, download_id, movie_status, release_status + while True: url = baseURL + "media.list/?status=active&release_status=snatched&limit_offset=50," + str(offset) @@ -64,10 +65,7 @@ class autoProcessMovie: Logger.exception("Unable to open URL") break - movieid2 = [] library2 = [] - release2 = [] - moviestatus2 = [] try: result = r.json() movieid2 = [item["_id"] for item in result["movies"]] @@ -78,7 +76,7 @@ class autoProcessMovie: library2.append(item["identifiers"]["imdb"]) release2 = [item["releases"] for item in result["movies"]] moviestatus2 = [item["status"] for item in result["movies"]] - except: + except Exception, e: Logger.exception("Unable to parse json data for movies") break @@ -86,11 +84,11 @@ class autoProcessMovie: moviestatus.extend(moviestatus2) library.extend(library2) release.extend(release2) + if len(movieid2) < int(50): # finished parsing list of movies. Time to break. break offset = offset + 50 - result = None # reset for index in range(len(movieid)): releaselist1 = [item for item in release[index] if item["status"] == "snatched" and "download_info" in item] if download_id: diff --git a/nzbtomedia/nzbToMediaConfig.py b/nzbtomedia/nzbToMediaConfig.py index dece6496..bc6d0004 100644 --- a/nzbtomedia/nzbToMediaConfig.py +++ b/nzbtomedia/nzbToMediaConfig.py @@ -47,7 +47,7 @@ class config(object): return @staticmethod - def get_categories(section): + def get_sections(section): sections = {} # check and return categories if section does exist @@ -57,9 +57,4 @@ class config(object): for x in section: if config().has_key(x): sections.update({x: config()[x].sections}) - return sections - - @staticmethod - def gather_subsection(section, key): - if section.depth > 1: - return section.name \ No newline at end of file + return sections \ No newline at end of file diff --git a/nzbtomedia/nzbToMediaUtil.py b/nzbtomedia/nzbToMediaUtil.py index 47c0a6ef..a0d80924 100644 --- a/nzbtomedia/nzbToMediaUtil.py +++ b/nzbtomedia/nzbToMediaUtil.py @@ -451,13 +451,13 @@ def parse_args(clientAgent): return clients[clientAgent](sys.argv) -def get_dirnames(section, category): +def get_dirnames(section, inputCategory): try: watch_dir = config()[section][inputCategory]["watch_dir"] except: watch_dir = "" try: - outputDirectory = os.path.join(config()["Torrent"]["outputDirectory"], category) + outputDirectory = os.path.join(config()["Torrent"]["outputDirectory"], inputCategory) except: outputDirectory = "" @@ -467,13 +467,15 @@ def get_dirnames(section, category): if os.path.exists(watch_dir): dirNames.extend([os.path.join(watch_dir, o) for o in os.listdir(watch_dir) if os.path.isdir(os.path.join(watch_dir, o))]) + if not dirNames: + Logger.warn("No Directories identified to Scan inside " + watch_dir) + if outputDirectory != "": if os.path.exists(outputDirectory): dirNames.extend([os.path.join(outputDirectory, o) for o in os.listdir(outputDirectory) if os.path.isdir(os.path.join(outputDirectory, o))]) - - if not dirNames: - Logger.warn("No Directories identified to Scan.") + if not dirNames: + Logger.warn("No Directories identified to Scan inside " + outputDirectory) return dirNames