Fixed issues in the nzbTo* scripts with manual runs not properly sending the categories to be processed.

Fixed issue in TorrentToMedia with noFlatten variable for HeadPhones.

Changed name of function get_categories to get_sections in nzbToMediaUtil.

Added code in get_dirnames to properly return back the directory could not find anything to process in.
This commit is contained in:
echel0n 2014-04-05 20:56:12 -07:00
commit c3410fba8f
10 changed files with 70 additions and 72 deletions

View file

@ -131,7 +131,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
Logger.debug("MAIN: Scanning files in directory: %s", inputDirectory) 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. outputDestinationMaster = outputDestination # Save the original, so we can change this within the loop below, and reset afterwards.
now = datetime.datetime.now() 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 continue # This file has not been recently moved or created, skip it
if fileExtension in mediaContainer: # If the file is a video file 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) Logger.info("MAIN: Ignoring sample file: %s ", filePath)
continue continue
else: else:
@ -209,7 +209,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
except: except:
Logger.exception("MAIN: Extraction failed for: %s", file) Logger.exception("MAIN: Extraction failed for: %s", file)
continue 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) Logger.info("MAIN: Found file %s for category %s", filePath, inputCategory)
copy_link(filePath, targetDirectory, useLink, outputDestination) copy_link(filePath, targetDirectory, useLink, outputDestination)
copy_list.append([filePath, os.path.join(outputDestination, file)]) copy_list.append([filePath, os.path.join(outputDestination, file)])
@ -223,7 +223,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
flatten(outputDestination) flatten(outputDestination)
# Now check if movie files exist in destination: # 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 dirpath, dirnames, filenames in os.walk(outputDestination):
for file in filenames: for file in filenames:
filePath = os.path.join(dirpath, file) 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): 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) Logger.info("MAIN: Processing user script %s.", user_script)
result = external_script(outputDestination,inputName,inputCategory) 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.") Logger.debug("MAIN: Calling autoProcess script for successful download.")
status = int(0) # hp, my, gz don't support failed. status = int(0) # hp, my, gz don't support failed.
else: else:
@ -435,7 +435,7 @@ if __name__ == "__main__":
minSampleSize = int(config()["Extensions"]["minSampleSize"]) # 200 (in MB) minSampleSize = int(config()["Extensions"]["minSampleSize"]) # 200 (in MB)
SampleIDs = (config()["Extensions"]["SampleIDs"]) # sample,-s. 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())) categories += list(chain.from_iterable(sections.values()))
user_script_categories = config()["UserScript"]["user_script_categories"] # NONE user_script_categories = config()["UserScript"]["user_script_categories"] # NONE

View file

@ -149,7 +149,7 @@ else:
sys.exit(-1) sys.exit(-1)
# setup sections and categories # setup sections and categories
categories = config.get_categories(["CouchPotato"]) sections = config.get_sections(["CouchPotato"])
WakeUp() WakeUp()
@ -239,13 +239,13 @@ else:
Logger.warn("MAIN: Invalid number of arguments received from client.") Logger.warn("MAIN: Invalid number of arguments received from client.")
Logger.info("MAIN: Running autoProcessMovie as a manual run...") Logger.info("MAIN: Running autoProcessMovie as a manual run...")
for section, category in categories.items(): for section, categories in sections.items():
for dirName in get_dirnames(section, category): for category in categories:
Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) dirNames = get_dirnames(section, category)
results = autoProcessMovie().process(dirName, dirName, 0) for dirName in dirNames:
if results != 0: Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName)
result = 1 results = autoProcessMovie().process(dirName, dirName, 0, inputCategory=category)
Logger.info("MAIN: A problem was reported in the autoProcessMovie script.") if results != 0:result = results
if result == 0: if result == 0:
Logger.info("MAIN: The autoProcessMovie script completed successfully.") Logger.info("MAIN: The autoProcessMovie script completed successfully.")

View file

@ -84,7 +84,7 @@ else:
sys.exit(-1) sys.exit(-1)
# gamez category # gamez category
categories = config.get_categories(['Gamez']) sections = config.get_sections(['Gamez'])
WakeUp() WakeUp()
@ -166,13 +166,13 @@ else:
Logger.warn("MAIN: Invalid number of arguments received from client. Exiting") Logger.warn("MAIN: Invalid number of arguments received from client. Exiting")
Logger.info("MAIN: Running autoProcessGames as a manual run...") Logger.info("MAIN: Running autoProcessGames as a manual run...")
for section, category in categories.items(): for section, categories in sections.items():
for dirName in get_dirnames(section, category): for category in categories:
Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) dirNames = get_dirnames(section, category)
results = autoProcessGames().process(dirName, dirName, 0) for dirName in dirNames:
if results != 0: Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName)
result = 1 results = autoProcessGames().process(dirName, dirName, 0, inputCategory=category)
Logger.info("MAIN: A problem was reported in the autoProcessGames script.") if results != 0:result = results
if result == 0: if result == 0:
Logger.info("MAIN: The autoProcessGames script completed successfully.") Logger.info("MAIN: The autoProcessGames script completed successfully.")

View file

@ -97,7 +97,7 @@ else:
sys.exit(-1) sys.exit(-1)
# headphones category # headphones category
categories = config.get_categories(["HeadPhones"]) sections = config.get_sections(["HeadPhones"])
WakeUp() WakeUp()
@ -179,13 +179,13 @@ else:
Logger.warn("MAIN: Invalid number of arguments received from client.") Logger.warn("MAIN: Invalid number of arguments received from client.")
Logger.info("MAIN: Running autoProcessMusic as a manual run...") Logger.info("MAIN: Running autoProcessMusic as a manual run...")
for section, category in categories.items(): for section, categories in sections.items():
for dirName in get_dirnames(section, category): for category in categories:
Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) dirNames = get_dirnames(section, category)
results = autoProcessMusic().process(dirName, dirName, 0) for dirName in dirNames:
if results != 0: Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName)
result = 1 results = autoProcessMusic().process(dirName, dirName, 0, inputCategory=category)
Logger.info("MAIN: A problem was reported in the autoProcessMusic script.") if results != 0:result = results
if result == 0: if result == 0:
Logger.info("MAIN: The autoProcessMusic script completed successfully.") Logger.info("MAIN: The autoProcessMusic script completed successfully.")
@ -195,3 +195,4 @@ else:
Logger.info("MAIN: A problem was reported in the autoProcessMusic script.") Logger.info("MAIN: A problem was reported in the autoProcessMusic script.")
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
sys.exit(config.NZBGET_POSTPROCESS_ERROR) sys.exit(config.NZBGET_POSTPROCESS_ERROR)

View file

@ -362,7 +362,7 @@ else:
sys.exit(-1) sys.exit(-1)
# setup sections and categories # setup sections and categories
sections = config.get_categories(["CouchPotato","SickBeard","HeadPhones","Mylar","Gamez"]) sections = config.get_sections(["CouchPotato","SickBeard","HeadPhones","Mylar","Gamez"])
WakeUp() WakeUp()
@ -454,9 +454,11 @@ else:
Logger.warn("MAIN: Invalid number of arguments received from client.") Logger.warn("MAIN: Invalid number of arguments received from client.")
for section, categories in sections.items(): for section, categories in sections.items():
for category in categories: for category in categories:
dirnames = get_dirnames(section, category) dirNames = get_dirnames(section, category)
Logger.info("MAIN: Running " + section + ":" + category + " as a manual run...") 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 + ".") Logger.info("MAIN: A problem was reported when trying to manually run " + section + ":" + category + ".")
if result == 0: if result == 0:

View file

@ -89,7 +89,7 @@ else:
sys.exit(-1) sys.exit(-1)
# mylar category # mylar category
categories = config.get_categories(["Mylar"]) sections = config.get_sections(["Mylar"])
WakeUp() WakeUp()
@ -171,13 +171,13 @@ else:
Logger.warn("MAIN: Invalid number of arguments received from client.") Logger.warn("MAIN: Invalid number of arguments received from client.")
Logger.info("MAIN: Running autoProcessComics as a manual run...") Logger.info("MAIN: Running autoProcessComics as a manual run...")
for section, category in categories.items(): for section, categories in sections.items():
for dirName in get_dirnames(section, category): for category in categories:
Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) dirNames = get_dirnames(section, category)
results = autoProcessComics().processEpisode(dirName, dirName, 0) for dirName in dirNames:
if results != 0: Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName)
result = 1 results = autoProcessComics().processEpisode(dirName, dirName, 0, inputCategory=category)
Logger.info("MAIN: A problem was reported in the autoProcessComics script.") if results != 0:result = results
if result == 0: if result == 0:
Logger.info("MAIN: The autoProcessComics script completed successfully.") Logger.info("MAIN: The autoProcessComics script completed successfully.")

View file

@ -151,7 +151,7 @@ else:
sys.exit(-1) sys.exit(-1)
# sickbeard category # sickbeard category
categories = config.get_categories(["SickBeard"]) sections = config.get_sections(["SickBeard"])
WakeUp() WakeUp()
@ -236,13 +236,13 @@ else:
Logger.debug("MAIN: Invalid number of arguments received from client.") Logger.debug("MAIN: Invalid number of arguments received from client.")
Logger.info("MAIN: Running autoProcessTV as a manual run...") Logger.info("MAIN: Running autoProcessTV as a manual run...")
for section, category in categories.items(): for section, categories in sections.items():
for dirName in get_dirnames(section, category): for category in categories:
Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName) dirNames = get_dirnames(section, category)
results = autoProcessTV().processEpisode(dirName, dirName, 0) for dirName in dirNames:
if results != 0: Logger.info("MAIN: Calling " + section + ":" + category + " to post-process: %s", dirName)
result = 1 results = autoProcessTV().processEpisode(dirName, dirName, 0, inputCategory=category)
Logger.info("MAIN: A problem was reported in the autoProcessTV script.") if results != 0:result = results
if result == 0: if result == 0:
Logger.info("MAIN: The autoProcessTV script completed successfully.") Logger.info("MAIN: The autoProcessTV script completed successfully.")

View file

@ -14,6 +14,7 @@ from nzbtomedia.nzbToMediaUtil import getDirectorySize, convert_to_ascii
Logger = logging.getLogger() Logger = logging.getLogger()
class autoProcessMovie: class autoProcessMovie:
def get_imdb(self, nzbName, dirName): def get_imdb(self, nzbName, dirName):
imdbid = "" imdbid = ""
@ -41,18 +42,18 @@ class autoProcessMovie:
def get_movie_info(self, baseURL, imdbid, download_id): def get_movie_info(self, baseURL, imdbid, download_id):
movie_id = "" movie_id = None
movie_status = 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 = [] movieid = []
moviestatus = [] moviestatus = []
library = [] library = []
release = [] release = []
offset = int(0) 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: while True:
url = baseURL + "media.list/?status=active&release_status=snatched&limit_offset=50," + str(offset) 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") Logger.exception("Unable to open URL")
break break
movieid2 = []
library2 = [] library2 = []
release2 = []
moviestatus2 = []
try: try:
result = r.json() result = r.json()
movieid2 = [item["_id"] for item in result["movies"]] movieid2 = [item["_id"] for item in result["movies"]]
@ -78,7 +76,7 @@ class autoProcessMovie:
library2.append(item["identifiers"]["imdb"]) library2.append(item["identifiers"]["imdb"])
release2 = [item["releases"] for item in result["movies"]] release2 = [item["releases"] for item in result["movies"]]
moviestatus2 = [item["status"] 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") Logger.exception("Unable to parse json data for movies")
break break
@ -86,11 +84,11 @@ class autoProcessMovie:
moviestatus.extend(moviestatus2) moviestatus.extend(moviestatus2)
library.extend(library2) library.extend(library2)
release.extend(release2) release.extend(release2)
if len(movieid2) < int(50): # finished parsing list of movies. Time to break. if len(movieid2) < int(50): # finished parsing list of movies. Time to break.
break break
offset = offset + 50 offset = offset + 50
result = None # reset
for index in range(len(movieid)): for index in range(len(movieid)):
releaselist1 = [item for item in release[index] if item["status"] == "snatched" and "download_info" in item] releaselist1 = [item for item in release[index] if item["status"] == "snatched" and "download_info" in item]
if download_id: if download_id:

View file

@ -47,7 +47,7 @@ class config(object):
return return
@staticmethod @staticmethod
def get_categories(section): def get_sections(section):
sections = {} sections = {}
# check and return categories if section does exist # check and return categories if section does exist
@ -57,9 +57,4 @@ class config(object):
for x in section: for x in section:
if config().has_key(x): if config().has_key(x):
sections.update({x: config()[x].sections}) sections.update({x: config()[x].sections})
return sections return sections
@staticmethod
def gather_subsection(section, key):
if section.depth > 1:
return section.name

View file

@ -451,13 +451,13 @@ def parse_args(clientAgent):
return clients[clientAgent](sys.argv) return clients[clientAgent](sys.argv)
def get_dirnames(section, category): def get_dirnames(section, inputCategory):
try: try:
watch_dir = config()[section][inputCategory]["watch_dir"] watch_dir = config()[section][inputCategory]["watch_dir"]
except: except:
watch_dir = "" watch_dir = ""
try: try:
outputDirectory = os.path.join(config()["Torrent"]["outputDirectory"], category) outputDirectory = os.path.join(config()["Torrent"]["outputDirectory"], inputCategory)
except: except:
outputDirectory = "" outputDirectory = ""
@ -467,13 +467,15 @@ def get_dirnames(section, category):
if os.path.exists(watch_dir): if os.path.exists(watch_dir):
dirNames.extend([os.path.join(watch_dir, o) for o in os.listdir(watch_dir) if 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))]) 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 outputDirectory != "":
if os.path.exists(outputDirectory): if os.path.exists(outputDirectory):
dirNames.extend([os.path.join(outputDirectory, o) for o in os.listdir(outputDirectory) if dirNames.extend([os.path.join(outputDirectory, o) for o in os.listdir(outputDirectory) if
os.path.isdir(os.path.join(outputDirectory, o))]) os.path.isdir(os.path.join(outputDirectory, o))])
if not dirNames:
if not dirNames: Logger.warn("No Directories identified to Scan inside " + outputDirectory)
Logger.warn("No Directories identified to Scan.")
return dirNames return dirNames