More cleaning

This commit is contained in:
Clinton Hall 2013-03-03 22:22:47 -08:00
commit aea30191a5

View file

@ -31,11 +31,11 @@ class AuthURLOpener(urllib.FancyURLopener):
self.numTries = 0 self.numTries = 0
return urllib.FancyURLopener.open(self, url) return urllib.FancyURLopener.open(self, url)
def get_imdb(nzbName1, dirName): def get_imdb(nzbName, dirName):
a=nzbName1.find('.cp(')+4 #search for .cptt( in nzbName a=nzbName.find('.cp(')+4 #search for .cptt( in nzbName
b=nzbName1[a:].find(')')+a b=nzbName[a:].find(')')+a
imdbid=nzbName1[a:b] imdbid=nzbName[a:b]
if imdbid: if imdbid:
Logger.info("Found movie id %s in name", imdbid) Logger.info("Found movie id %s in name", imdbid)
@ -51,8 +51,7 @@ def get_imdb(nzbName1, dirName):
else: else:
Logger.warning("Could not find an imdb id in directory or name") Logger.warning("Could not find an imdb id in directory or name")
Logger.info("Postprocessing will continue, but the movie may not be identified correctly by CouchPotato") Logger.info("Postprocessing will continue, but the movie may not be identified correctly by CouchPotato")
imdbid = "" return ""
return imdbid
def get_movie_info(myOpener, baseURL, imdbid): def get_movie_info(myOpener, baseURL, imdbid):
@ -69,7 +68,6 @@ def get_movie_info(myOpener, baseURL, imdbid):
return "" return ""
movie_id = "" movie_id = ""
movie_status = ""
result = json.load(urlObj) result = json.load(urlObj)
movieid = [item["id"] for item in result["movies"]] movieid = [item["id"] for item in result["movies"]]
library = [item["library"]["identifier"] for item in result["movies"]] library = [item["library"]["identifier"] for item in result["movies"]]
@ -98,7 +96,8 @@ def get_status(myOpener, baseURL, movie_id):
movie_status = result["movie"]["status"]["identifier"] movie_status = result["movie"]["status"]["identifier"]
Logger.debug("This movie is marked as status %s in CouchPotatoServer", movie_status) Logger.debug("This movie is marked as status %s in CouchPotatoServer", movie_status)
return movie_status return movie_status
except: except e: # index out of range/doesn't exist?
Logger.error("Could not find a status for this movie due to: %s", str(e))
return "" return ""
def process(dirName, nzbName=None, status=0): def process(dirName, nzbName=None, status=0):
@ -135,9 +134,9 @@ def process(dirName, nzbName=None, status=0):
myOpener = AuthURLOpener(username, password) myOpener = AuthURLOpener(username, password)
nzbName1 = str(nzbName) nzbName = str(nzbName) # make sure it is a string
imdbid = get_imdb(nzbName1, dirName) imdbid = get_imdb(nzbName, dirName)
if ssl: if ssl:
protocol = "https://" protocol = "https://"
@ -178,17 +177,17 @@ def process(dirName, nzbName=None, status=0):
result = json.load(urlObj) result = json.load(urlObj)
Logger.info("CouchPotatoServer returned %s", result) Logger.info("CouchPotatoServer returned %s", result)
if result['success']: if result['success']:
Logger.info("%s started on CouchPotatoServer for %s", command, nzbName1) Logger.info("%s started on CouchPotatoServer for %s", command, nzbName)
else: else:
Logger.error("%s has NOT started on CouchPotatoServer for %s. Exiting", command, nzbName1) Logger.error("%s has NOT started on CouchPotatoServer for %s. Exiting", command, nzbName)
return 1 # failure return 1 # failure
else: else:
Logger.info("Download of %s has failed.", nzbName1) Logger.info("Download of %s has failed.", nzbName)
Logger.info("Trying to re-cue the next highest ranked release") Logger.info("Trying to re-cue the next highest ranked release")
if not movie_id: if not movie_id:
Logger.warning("Cound not find a movie in the database for release %s", nzbName1) Logger.warning("Cound not find a movie in the database for release %s", nzbName)
Logger.warning("Please manually ignore this release and refresh the wanted movie") Logger.warning("Please manually ignore this release and refresh the wanted movie")
Logger.error("Exiting autoProcessMovie script") Logger.error("Exiting autoProcessMovie script")
return 1 # failure return 1 # failure