diff --git a/getvideotype.py b/getvideotype.py index 7687da4..b358182 100755 --- a/getvideotype.py +++ b/getvideotype.py @@ -19,6 +19,7 @@ def getdvdtype(): """ Queries OMDbapi.org for title information and parses if it's a movie or a tv series """ dvd_title = args.title + needs_new_year = "false" try: year = dvd_title[(dvd_title.rindex('(')):len(dvd_title)] @@ -37,21 +38,39 @@ def getdvdtype(): if year is None: year = "" - dvd_type = callwebservice(dvd_title, year) + dvd_type = callwebservice(dvd_title_clean, year) + # print (dvd_type) # handle failures - # first see if there is a hyphen and split it - if (dvd_title.find("-") > -1): - dvd_title_slice = dvd_title[:dvd_title.find("-")] - dvd_title_slice =cleanupstring(dvd_title_slice) - dvd_type = callwebservice(dvd_title_slice) - - # if still fail, then try slicing off the last word in a loop - while dvd_type == "fail" and dvd_title_clean.count('+') > 0: - dvd_title_clean = dvd_title_clean.rsplit('+', 1)[0] - dvd_type = callwebservice(dvd_title_clean) + # this is kind of kludgy, but it kind of work... + if (dvd_type == "fail"): - return dvd_type + # first try submitting without the year + dvd_type = callwebservice(dvd_title_clean, "") + # print (dvd_type) + + if (dvd_type != "fail"): + #that means the year is wrong. + needs_new_year = "true" + + if (dvd_type == "fail"): + # second see if there is a hyphen and split it + if (dvd_title.find("-") > -1): + dvd_title_slice = dvd_title[:dvd_title.find("-")] + dvd_title_slice =cleanupstring(dvd_title_slice) + dvd_type = callwebservice(dvd_title_slice) + + # if still fail, then try slicing off the last word in a loop + while dvd_type == "fail" and dvd_title_clean.count('+') > 0: + dvd_title_clean = dvd_title_clean.rsplit('+', 1)[0] + dvd_type = callwebservice(dvd_title_clean) + + if needs_new_year == "true": + #pass the new year back to bash to handle + global new_year + return dvd_type + "#" + new_year + else: + return dvd_type def cleanupstring(string): # clean up title string to pass to OMDbapi.org @@ -61,6 +80,8 @@ def cleanupstring(string): def callwebservice(dvd_title, year=""): """ Queries OMDbapi.org for title information and parses if it's a movie or a tv series """ + # print (dvd_title) + try: dvd_title_info_json = urllib.request.urlopen("http://www.omdbapi.com/?t={0}&y={1}&plot=short&r=json".format(dvd_title, year)).read() except: @@ -70,9 +91,11 @@ def callwebservice(dvd_title, year=""): if doc['Response'] == "False": return "fail" else: + global new_year + new_year = doc['Year'] return doc['Type'] args = entry() dvd_type = getdvdtype() -print(dvd_type) +print(dvd_type) \ No newline at end of file diff --git a/identify.sh b/identify.sh index 3796aff..fef92eb 100755 --- a/identify.sh +++ b/identify.sh @@ -70,7 +70,18 @@ if [ "$ID_FS_TYPE" == "udf" ]; then fi if [ $HAS_NICE_TITLE == true ]; then - VIDEO_TYPE=$(/opt/arm/getvideotype.py -t "${VIDEO_TITLE}" 2>&1) + VTYPE=$(/opt/arm/getvideotype.py -t "${VIDEO_TITLE}" 2>&1) + + #handle year mismath if found + if [[ $VTYPE =~ .*#.* ]]; then + VIDEO_TYPE=$(echo "$VTYPE" | cut -f1 -d#) + NEW_YEAR=$(echo "$VTYPE" | cut -f2 -d#) + echo "VIDEO_TYPE is $VIDEO_TYPE and NEW_YEAR is $NEW_YEAR" + VIDEO_TITLE="$(echo "$VIDEO_TITLE" | cut -f1 -d\()($NEW_YEAR)" + echo "Year mismatch found. New video title is $VIDEO_TITLE" + else + VIDEO_TYPE="$VTYPE" + fi else VIDEO_TYPE="unknown" fi