From 3db20ab0727e67dbd6bad35407ea2b4613f7e387 Mon Sep 17 00:00:00 2001 From: echel0n Date: Fri, 18 Apr 2014 14:37:53 -0700 Subject: [PATCH] Added a check for length of results before we decide if we need to narrow them down further by checking the download clients --- nzbtomedia/autoProcess/autoProcessMovie.py | 62 +++++++++++++--------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/nzbtomedia/autoProcess/autoProcessMovie.py b/nzbtomedia/autoProcess/autoProcessMovie.py index 60d55341..04a162f6 100644 --- a/nzbtomedia/autoProcess/autoProcessMovie.py +++ b/nzbtomedia/autoProcess/autoProcessMovie.py @@ -7,6 +7,7 @@ from nzbtomedia.nzbToMediaSceneExceptions import process_all_exceptions from nzbtomedia.nzbToMediaUtil import convert_to_ascii, delete, find_imdbid, find_download from nzbtomedia import logger + class autoProcessMovie: def get_releases(self, baseURL, imdbid=None, download_id=None): results = {} @@ -34,27 +35,30 @@ class autoProcessMovie: if not isinstance(movies, list): movies = [movies] for movie in movies: - if movie['status'] not in ['active','done']: + if movie['status'] not in ['active', 'done']: continue releases = movie['releases'] for release in releases: - if release['status'] not in ['snatched','done']: + if release['status'] not in ['snatched', 'done']: continue try: if download_id: if download_id != release['download_info']['id']: - continue + continue id = release['_id'] results[id] = release - except:continue + except: + continue # Search downloads on clients for a match to try and narrow our results down to 1 - for id, x in results.items(): - try: - if not find_download(str(x['download_info']['downloader']).lower(),x['download_info']['id']): - results.pop(id) - except:continue + if len(results) > 1: + for id, x in results.items(): + try: + if not find_download(str(x['download_info']['downloader']).lower(), x['download_info']['id']): + results.pop(id) + except: + continue return results @@ -68,7 +72,7 @@ class autoProcessMovie: ) ]) - def process(self, dirName, nzbName=None, status=0, clientAgent = "manual", download_id = "", inputCategory=None): + def process(self, dirName, nzbName=None, status=0, clientAgent="manual", download_id="", inputCategory=None): # auto-detect correct section section = nzbtomedia.CFG.findsection(inputCategory) if not section: @@ -105,7 +109,7 @@ class autoProcessMovie: baseURL = "%s%s:%s%s/api/%s" % (protocol, host, port, web_root, apikey) - imdbid = find_imdbid(dirName,nzbName) + imdbid = find_imdbid(dirName, nzbName) releases = self.get_releases(baseURL, imdbid, download_id) # pull info from release found if available @@ -118,7 +122,8 @@ class autoProcessMovie: media_id = releases[release_id]['media_id'] download_id = releases[release_id]['download_info']['id'] downloader = releases[release_id]['download_info']['downloader'] - except:pass + except: + pass process_all_exceptions(nzbName.lower(), dirName) nzbName, dirName = convert_to_ascii(nzbName, dirName) @@ -127,9 +132,9 @@ class autoProcessMovie: if nzbtomedia.TRANSCODE == 1: result = Transcoder().Transcode_directory(dirName) if result == 0: - logger.debug("Transcoding succeeded for files in %s" % (dirName),section) + logger.debug("Transcoding succeeded for files in %s" % (dirName), section) else: - logger.warning("Transcoding failed for files in %s" % (dirName),section) + logger.warning("Transcoding failed for files in %s" % (dirName), section) if method == "manage": command = "/manage.update" @@ -156,14 +161,15 @@ class autoProcessMovie: r = requests.get(url, params=params) except requests.ConnectionError: logger.error("Unable to open URL", section) - return 1 # failure + return 1 # failure result = r.json() if result['success']: logger.postprocess("SUCCESS: Finished %s scan for folder %s" % (method, dirName), section) else: - logger.error("FAILED: %s scan was unable to finish for folder %s. exiting!" % (method, dirName), section) - return 1 # failure + logger.error("FAILED: %s scan was unable to finish for folder %s. exiting!" % (method, dirName), + section) + return 1 # failure else: logger.postprocess("FAILED DOWNLOAD DETECTED FOR %s" % (nzbName), section) @@ -173,8 +179,9 @@ class autoProcessMovie: delete(dirName) if not download_id: - logger.error("Could not find a downloaded movie in the database matching %s, exiting!" % nzbName, section) - return 1 # failure + logger.error("Could not find a downloaded movie in the database matching %s, exiting!" % nzbName, + section) + return 1 # failure logger.postprocess("Setting failed release %s to ignored ..." % (nzbName), section) @@ -209,7 +216,8 @@ class autoProcessMovie: logger.postprocess("SUCCESS: Snatched the next highest release ...", section) return 0 else: - logger.postprocess("FAILED: Unable to find a higher ranked release then %s to snatch!" % (nzbName), section) + logger.postprocess("FAILED: Unable to find a higher ranked release then %s to snatch!" % (nzbName), + section) return 1 # we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing. @@ -221,13 +229,17 @@ class autoProcessMovie: if releasesDiff: # Something has changed. CPS must have processed this movie. try: release_status = releasesDiff[releasesDiff.keys()[0]]['status'] - logger.postprocess("SUCCESS: Release %s has now been marked with a status of [%s]" % (nzbName, str(release_status).upper()), section) - return 0 # success - except:pass + logger.postprocess("SUCCESS: Release %s has now been marked with a status of [%s]" % ( + nzbName, str(release_status).upper()), section) + return 0 # success + except: + pass # pause and let CouchPotatoServer catch its breath time.sleep(10 * wait_for) # The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now. - logger.warning("%s does not appear to have changed status after %s minutes, Please check your logs." % (nzbName, wait_for), section) - return 1 # failure \ No newline at end of file + logger.warning( + "%s does not appear to have changed status after %s minutes, Please check your logs." % (nzbName, wait_for), + section) + return 1 # failure \ No newline at end of file