fix: recursively check all returned pages for correct movie
fixes assumption of getting the first result back especially for items that are very generic. Such as 2012 added new verbose mode and cleaned up some of the output
This commit is contained in:
parent
8d1f836ce2
commit
b1a70c2145
76
bhdupload.py
76
bhdupload.py
|
@ -52,6 +52,7 @@ def getArgs():
|
|||
help='Do not Create Torrent File')
|
||||
parser.add_argument('-l', dest='live', action='store_true', help='Upload instead of going to drafts')
|
||||
parser.add_argument('-a', dest='anon', action='store_true', help='Set an Anonymous upload')
|
||||
parser.add_argument('-v', dest='debug', action='store_true', help='Enable extra debug mode')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
|
@ -193,22 +194,44 @@ def mediainfo(directory, tempdir):
|
|||
return f"{tempdir}/mediainfo.txt"
|
||||
|
||||
|
||||
def find_info(name):
|
||||
def find_info(name, page=1):
|
||||
torrent_name = str(name)
|
||||
print(f"Searching for {torrent_name}...")
|
||||
# first search on name
|
||||
r = SESS.post(BHD_SEARCH, data={'action': 'search', 'search': torrent_name})
|
||||
if page == 1:
|
||||
r = SESS.post(BHD_SEARCH, data={'action': 'search', 'search': torrent_name})
|
||||
else:
|
||||
r = SESS.post(BHD_SEARCH, data={'action': 'search', 'search': torrent_name, 'page': page})
|
||||
try:
|
||||
if r.status_code == 200:
|
||||
json = r.json()
|
||||
if json['total_results'] >= 1:
|
||||
result = json['results'][0]
|
||||
imdb = result["imdb_id"]
|
||||
tmdb = result["tmdb_id"]
|
||||
category = result["category"]
|
||||
pack = result["tv_pack"]
|
||||
print(f"Found it: IMDB: {imdb}, TMDB: {tmdb}, Category: {category}, TV?: {pack} ")
|
||||
return imdb, tmdb, category, pack
|
||||
if json["total_results"] >= 1:
|
||||
if args.debug:
|
||||
print(f"Total Results: {json['total_results']}")
|
||||
print(f"Current Page: {page} of {json['total_pages']}")
|
||||
for item in json["results"]:
|
||||
guess = dict(guessit.guessit(item['name']))
|
||||
title = (guess['title'])
|
||||
if args.debug:
|
||||
print(f"Current Item: Title: {title} - {torrent_name}")
|
||||
if title == torrent_name:
|
||||
# We found an exact match
|
||||
imdb = item["imdb_id"]
|
||||
tmdb = item["tmdb_id"]
|
||||
category = item["category"]
|
||||
pack = item["tv_pack"]
|
||||
print(f"Found: {torrent_name} IMDB: {imdb}, TMDB: {tmdb}, Category: {category}, TV?: {pack} ")
|
||||
return imdb, tmdb, category, pack
|
||||
# If we get to the end of a page we need to check there are not more pages
|
||||
while page != json["total_pages"]:
|
||||
next_page = page + 1
|
||||
imdb, tmdb, category, pack = find_info(name, next_page)
|
||||
return imdb, tmdb, category, pack
|
||||
# If we get to here we've never found {torrent_name}
|
||||
print(f"Failed to find {torrent_name}")
|
||||
return False, False, False, False
|
||||
return imdb, tmdb, category, pack
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error finding torrent information: {e}")
|
||||
print(f"{json}")
|
||||
|
@ -345,16 +368,7 @@ if args.torrent:
|
|||
source = "Blu-ray"
|
||||
|
||||
# Find the required info before we upload (hopefully BHD already has it uploaded)
|
||||
# Split on the Resolution, that way we search just for the name of the file
|
||||
search_name = file_name.split(reso)
|
||||
imdbid, tmdbid, category, pack = find_info(search_name[0])
|
||||
|
||||
# Generate MediaInfo
|
||||
print("Creating mediainfo...")
|
||||
mediainfo_file = mediainfo(args.input, tempdir)
|
||||
# Generate TorrentFile
|
||||
print("Creating torrent...")
|
||||
torrent_file = mktorrent(BHD_PASSKEY, args.input, tempdir)
|
||||
imdbid, tmdbid, category, pack = find_info(searchterm)
|
||||
|
||||
live = 0
|
||||
anon = 0
|
||||
|
@ -378,9 +392,25 @@ if args.torrent:
|
|||
'live': live,
|
||||
'anon': anon}
|
||||
|
||||
print("")
|
||||
print(f"Debug: We are about to submit the following: {payload}")
|
||||
print("")
|
||||
# Notify if it failed to be found
|
||||
if imdbid is False or tmdbid is False or category is False:
|
||||
print(f"Failed to find {searchterm} already on BHD - You might be the first!",
|
||||
"You will need to edit it in drafts before uploading")
|
||||
if live == 1:
|
||||
print(f"We are sending {searchterm} to drafts instead of live. Fix it up!")
|
||||
live = 0
|
||||
|
||||
# Generate MediaInfo
|
||||
print("Creating mediainfo...")
|
||||
mediainfo_file = mediainfo(args.input, tempdir)
|
||||
# Generate TorrentFile
|
||||
print("Creating torrent...")
|
||||
torrent_file = mktorrent(BHD_PASSKEY, args.input, tempdir)
|
||||
|
||||
if args.debug:
|
||||
print("")
|
||||
print(f"Debug: We are about to submit the following: {payload}")
|
||||
print("")
|
||||
torrentfile = f"{torrent_file}"
|
||||
mediainfofile = f"{mediainfo_file}"
|
||||
files = {'file': open(torrentfile, 'rb'), 'mediainfo': open(mediainfofile, 'rb')}
|
||||
|
|
Loading…
Reference in a new issue