fix parsing of json data for movie id. fixes #182

This commit is contained in:
clinton-hall 2013-09-27 13:31:16 +09:30
parent be8b9c68c9
commit 12ff0c4a34
2 changed files with 31 additions and 26 deletions

View file

@ -185,12 +185,7 @@ def main(inputDirectory, inputName, inputCategory, inputHash, inputID):
if inputCategory == cpsCategory: if inputCategory == cpsCategory:
Logger.info("MAIN: Calling CouchPotatoServer to post-process: %s", inputName) Logger.info("MAIN: Calling CouchPotatoServer to post-process: %s", inputName)
if clientAgent == 'utorrent' and inputHash != '': download_id = inputHash
download_id = 'uTorrent_' + inputHash
elif clientAgent == 'transmission' and inputHash != '':
download_id = 'Transmission_' + inputHash
else:
download_id = inputHash
result = autoProcessMovie.process(outputDestination, inputName, status, clientAgent, download_id) result = autoProcessMovie.process(outputDestination, inputName, status, clientAgent, download_id)
elif inputCategory == sbCategory: elif inputCategory == sbCategory:
Logger.info("MAIN: Calling Sick-Beard to post-process: %s", inputName) Logger.info("MAIN: Calling Sick-Beard to post-process: %s", inputName)

View file

@ -56,35 +56,45 @@ def get_movie_info(baseURL, imdbid, download_id):
return "" return ""
movie_id = "" movie_id = ""
releaselist = []
try: try:
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"]]
releases = [item["releases"] for item in result["movies"]] except:
imdbid_list = [] Logger.exception("Unable to parse json data for movies")
return ""
for index in range(len(movieid)):
if not imdbid: if not imdbid:
movieindex = [index for index in range(len(movieid)) if len(releases[index]) > 0] url = baseURL + "movie.get/?id=" + str(movieid[index])
for index in movieindex: Logger.debug("Opening URL: %s", url)
releaseindex = [index2 for index2 in range(len(releases[index])) if len(releases[index][index2]) > 0 and "download_id" in releases[index][index2]["info"] and releases[index][index2]["info"]["download_id"].lower() == download_id.lower()] try:
if len(releaseindex) > 0: urlObj = urllib.urlopen(url)
imdbid_list.append(library[index]) except:
unique_imdbid_list = list(set(imdbid_list)) # convert this to a unique list to be sure we only have one imdbid Logger.exception("Unable to open URL")
if len(unique_imdbid_list) == 1: # we found it. return ""
imdbid = unique_imdbid_list[0] try:
Logger.info("Found movie id %s in database via download_id %s", imdbid, download_id) result = json.load(urlObj)
else: releaselist = [item["info"]["download_id"] for item in result["movie"]["releases"] if "download_id" in item["info"] and item["info"]["download_id"].lower() == download_id.lower()]
except:
Logger.exception("Unable to parse json data for releases")
return "" return ""
for index in range(len(movieid)): if len(releaselist) > 0:
if library[index] == imdbid:
movie_id = str(movieid[index]) movie_id = str(movieid[index])
Logger.info("Found movie id %s in CPS database for movie %s", movie_id, imdbid) Logger.info("Found movie id %s in database via download_id %s", movie_id, download_id)
break break
except: else:
if not imdbid: continue
Logger.exception("Could not parse database results to determine imdbid or movie id")
else: if library[index] == imdbid:
Logger.exception("Could not parse database results to determine movie id for imdbid: %s", imdbid) movie_id = str(movieid[index])
Logger.info("Found movie id %s in CPS database for movie %s", movie_id, imdbid)
break
if not movie_id:
Logger.exception("Could not parse database results to determine imdbid or movie id")
return movie_id return movie_id