Added a check for length of results before we decide if we need to narrow them down further by checking the download clients

This commit is contained in:
echel0n 2014-04-18 14:37:53 -07:00
commit 3db20ab072

View file

@ -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.nzbToMediaUtil import convert_to_ascii, delete, find_imdbid, find_download
from nzbtomedia import logger from nzbtomedia import logger
class autoProcessMovie: class autoProcessMovie:
def get_releases(self, baseURL, imdbid=None, download_id=None): def get_releases(self, baseURL, imdbid=None, download_id=None):
results = {} results = {}
@ -34,11 +35,11 @@ class autoProcessMovie:
if not isinstance(movies, list): if not isinstance(movies, list):
movies = [movies] movies = [movies]
for movie in movies: for movie in movies:
if movie['status'] not in ['active','done']: if movie['status'] not in ['active', 'done']:
continue continue
releases = movie['releases'] releases = movie['releases']
for release in releases: for release in releases:
if release['status'] not in ['snatched','done']: if release['status'] not in ['snatched', 'done']:
continue continue
try: try:
if download_id: if download_id:
@ -47,14 +48,17 @@ class autoProcessMovie:
id = release['_id'] id = release['_id']
results[id] = release results[id] = release
except:continue except:
continue
# Search downloads on clients for a match to try and narrow our results down to 1 # Search downloads on clients for a match to try and narrow our results down to 1
if len(results) > 1:
for id, x in results.items(): for id, x in results.items():
try: try:
if not find_download(str(x['download_info']['downloader']).lower(),x['download_info']['id']): if not find_download(str(x['download_info']['downloader']).lower(), x['download_info']['id']):
results.pop(id) results.pop(id)
except:continue except:
continue
return results 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 # auto-detect correct section
section = nzbtomedia.CFG.findsection(inputCategory) section = nzbtomedia.CFG.findsection(inputCategory)
if not section: if not section:
@ -105,7 +109,7 @@ class autoProcessMovie:
baseURL = "%s%s:%s%s/api/%s" % (protocol, host, port, web_root, apikey) 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) releases = self.get_releases(baseURL, imdbid, download_id)
# pull info from release found if available # pull info from release found if available
@ -118,7 +122,8 @@ class autoProcessMovie:
media_id = releases[release_id]['media_id'] media_id = releases[release_id]['media_id']
download_id = releases[release_id]['download_info']['id'] download_id = releases[release_id]['download_info']['id']
downloader = releases[release_id]['download_info']['downloader'] downloader = releases[release_id]['download_info']['downloader']
except:pass except:
pass
process_all_exceptions(nzbName.lower(), dirName) process_all_exceptions(nzbName.lower(), dirName)
nzbName, dirName = convert_to_ascii(nzbName, dirName) nzbName, dirName = convert_to_ascii(nzbName, dirName)
@ -127,9 +132,9 @@ class autoProcessMovie:
if nzbtomedia.TRANSCODE == 1: if nzbtomedia.TRANSCODE == 1:
result = Transcoder().Transcode_directory(dirName) result = Transcoder().Transcode_directory(dirName)
if result == 0: if result == 0:
logger.debug("Transcoding succeeded for files in %s" % (dirName),section) logger.debug("Transcoding succeeded for files in %s" % (dirName), section)
else: else:
logger.warning("Transcoding failed for files in %s" % (dirName),section) logger.warning("Transcoding failed for files in %s" % (dirName), section)
if method == "manage": if method == "manage":
command = "/manage.update" command = "/manage.update"
@ -162,7 +167,8 @@ class autoProcessMovie:
if result['success']: if result['success']:
logger.postprocess("SUCCESS: Finished %s scan for folder %s" % (method, dirName), section) logger.postprocess("SUCCESS: Finished %s scan for folder %s" % (method, dirName), section)
else: else:
logger.error("FAILED: %s scan was unable to finish for folder %s. exiting!" % (method, dirName), section) logger.error("FAILED: %s scan was unable to finish for folder %s. exiting!" % (method, dirName),
section)
return 1 # failure return 1 # failure
else: else:
@ -173,7 +179,8 @@ class autoProcessMovie:
delete(dirName) delete(dirName)
if not download_id: if not download_id:
logger.error("Could not find a downloaded movie in the database matching %s, exiting!" % nzbName, section) logger.error("Could not find a downloaded movie in the database matching %s, exiting!" % nzbName,
section)
return 1 # failure return 1 # failure
logger.postprocess("Setting failed release %s to ignored ..." % (nzbName), section) 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) logger.postprocess("SUCCESS: Snatched the next highest release ...", section)
return 0 return 0
else: 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 return 1
# we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing. # 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. if releasesDiff: # Something has changed. CPS must have processed this movie.
try: try:
release_status = releasesDiff[releasesDiff.keys()[0]]['status'] 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) logger.postprocess("SUCCESS: Release %s has now been marked with a status of [%s]" % (
nzbName, str(release_status).upper()), section)
return 0 # success return 0 # success
except:pass except:
pass
# pause and let CouchPotatoServer catch its breath # pause and let CouchPotatoServer catch its breath
time.sleep(10 * wait_for) 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. # 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) logger.warning(
"%s does not appear to have changed status after %s minutes, Please check your logs." % (nzbName, wait_for),
section)
return 1 # failure return 1 # failure