fixed to status check

This commit is contained in:
Clinton Hall 2013-03-03 18:57:55 -08:00
commit db56bdd966

View file

@ -48,12 +48,15 @@ def get_imdb(nzbName1, dirName):
Logger.info("Found movie id %s in directory", imdbid) Logger.info("Found movie id %s in directory", imdbid)
return imdbid return imdbid
else: else:
Logger.info("Could not find movie id in directory or name", imdbid) Logger.warning("Could not find movie id in directory or name", imdbid)
Logger.info("Postprocessing will continue, but the movie may not be identified correctly by CouchPotato")
imdbid = "" imdbid = ""
return imdbid return imdbid
def get_movie_info(baseURL, imdbid): def get_movie_info(baseURL, imdbid):
if not imdbid:
return 0, "", ""
url = baseURL + "movie.list" url = baseURL + "movie.list"
Logger.debug("Opening URL: %s", url) Logger.debug("Opening URL: %s", url)
@ -64,25 +67,23 @@ def get_movie_info(baseURL, imdbid):
Logger.error("Unable to open URL: %s", str(e)) Logger.error("Unable to open URL: %s", str(e))
return 0, "", "" return 0, "", ""
n=0
movie_id = "" movie_id = ""
movie_status = "" 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"]]
statusid = [item["status_id"] for item in result["movies"]]
library = [item["library"]["identifier"] for item in result["movies"]] library = [item["library"]["identifier"] for item in result["movies"]]
for index in range(len(movieid)): for index in range(len(movieid)):
if library[index] == imdbid: if library[index] == imdbid:
movie_id = str(movieid[index]) movie_id = str(movieid[index])
movie_status = int(statusid[index])
Logger.info("found movie id %s in CPS database for movie %s", movie_id, imdbid) Logger.info("found movie id %s in CPS database for movie %s", movie_id, imdbid)
n = n + 1
break break
return n, movie_id, movie_status return movie_id
def get_status_list(baseURL): def get_status(movie_id):
url = baseURL + "status.list" if not movie_id:
return ""
url = baseURL + "movie.get/?id=" + movie_id
Logger.debug("Opening URL: %s", url) Logger.debug("Opening URL: %s", url)
@ -90,13 +91,13 @@ def get_status_list(baseURL):
urlObj = myOpener.openit(url) urlObj = myOpener.openit(url)
except IOError, e: except IOError, e:
Logger.error("Unable to open URL: %s", str(e)) Logger.error("Unable to open URL: %s", str(e))
return [], [] return ""
result = json.load(urlObj) result = json.load(urlObj)
status = [item["identifier"] for item in result["list"]] try:
status_id = [item["id"] for item in result["list"]] movie_status = result["movie"]["status"]["identifier"]
return movie_status
return status, status_id except:
return ""
def process(dirName, nzbName=None, status=0): def process(dirName, nzbName=None, status=0):
@ -146,18 +147,12 @@ def process(dirName, nzbName=None, status=0):
baseURL = protocol + host + ":" + port + web_root + "/api/" + apikey + "/" baseURL = protocol + host + ":" + port + web_root + "/api/" + apikey + "/"
status, status_id = get_status_list(baseURL) movie_id = get_movie_info(baseURL, imdbid) # get the CPS database movie id this movie.
if not status:
return 1 # failure
n, movie_id, movie_status = get_movie_info(baseURL, imdbid) # get the initial status fo this movie.
if not movie_id: if not movie_id:
initial status = "" initial status = ""
for index in range(len(status): else:
if movie_status == status_id[index] initial_status = get_status(movie_id)
initial_status = movie_status Logger.debug("This movie is marked as status %s in CouchPotatoServer", initial_status)
Logger.debug("This movie is marked as status %s in CouchPotatoServer", status[index])
break
process_all_exceptions(nzbName.lower(), dirName) process_all_exceptions(nzbName.lower(), dirName)
@ -193,7 +188,7 @@ def process(dirName, nzbName=None, status=0):
Logger.info("download of %s has failed.", nzbName1) Logger.info("download of %s has failed.", nzbName1)
Logger.info("trying to re-cue the next highest ranked release") Logger.info("trying to re-cue the next highest ranked release")
if n == 0: 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", nzbName1)
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 postprocessing script") Logger.error("exiting postprocessing script")
@ -219,15 +214,15 @@ def process(dirName, nzbName=None, status=0):
shutil.rmtree(dirName) shutil.rmtree(dirName)
return 0 # success return 0 # success
if nzbName == "Manual Run":
return 0 # success
# 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.
start = datetime.datetime.now() # set time for timeout start = datetime.datetime.now() # set time for timeout
while (datetime.datetime.now() - start) > datetime.timedelta(minutes=2): # only wait 2 minutes, then return to TorrentToMedia while (datetime.datetime.now() - start) > datetime.timedelta(minutes=2): # only wait 2 minutes, then return to TorrentToMedia
n, movie_id, movie_status = get_movie_info(baseURL, imdbid) # get the current status fo this movie. movie_status = get_status(movie_id) # get the current status fo this movie.
if movie_status != initial_status: # Something has changed if movie_status != initial_status: # Something has changed. CPS must have processed this movie.
for index in range(len(status): Logger.info("SUCCESS: This movie is now marked as status %s in CouchPotatoServer", movie_status)
if movie_status == status_id[index]
Logger.info("SUCCESS: This movie is now marked as status %s in CouchPotatoServer", status[index])
break # leave the for loop
return 0 # success return 0 # success
time.sleep(20) # Just stop this looping infinitely and hogging resources for 2 minutes ;) time.sleep(20) # Just stop this looping infinitely and hogging resources for 2 minutes ;)
else: # The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now. else: # The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now.