Skip to content

Commit

Permalink
Skip user confirmation step when using manual ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Audionut committed Sep 1, 2024
1 parent bbea2f3 commit 447c1ad
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
41 changes: 22 additions & 19 deletions src/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ async def update_metadata_from_tracker(self, tracker_name, tracker_instance, met
if ptp_torrent_id:
meta['ptp'] = ptp_torrent_id
meta['imdb'] = str(imdb_id).zfill(7) if imdb_id else None

if meta.get('imdb') and await self.prompt_user_for_id_selection(imdb=meta['imdb']):
console.print(f"[green]{tracker_name} IMDb ID found: tt{meta['imdb']}[/green]")
found_match = True

else:
ptp_torrent_id = meta['ptp']
console.print(f"[cyan]PTP ID found in meta: {ptp_torrent_id}, using it to get IMDb ID[/cyan]")
Expand All @@ -180,10 +185,7 @@ async def update_metadata_from_tracker(self, tracker_name, tracker_instance, met
else:
console.print(f"[yellow]Could not find IMDb ID using PTP ID: {ptp_torrent_id}[/yellow]")

if meta.get('imdb') and await self.prompt_user_for_id_selection(imdb=meta['imdb']):
console.print(f"[green]{tracker_name} IMDb ID found: tt{meta['imdb']}[/green]")
found_match = True

# Retrieve PTP description and image list
ptp_desc, ptp_imagelist = await tracker_instance.get_ptp_description(meta['ptp'], meta.get('is_disc', False))
if ptp_desc.strip():
meta['description'] = ptp_desc
Expand All @@ -201,9 +203,9 @@ async def update_metadata_from_tracker(self, tracker_name, tracker_instance, met
console.print("[yellow]Description discarded from PTP[/yellow]")
meta['skip_gen_desc'] = True
meta['description'] = None
else:
console.print(f"[yellow]Skipped {tracker_name}, moving to the next site.[/yellow]")
meta['skip_gen_desc'] = True

console.print(f"[yellow]Skipped {tracker_name}, moving to the next site.[/yellow]")
meta['skip_gen_desc'] = True

elif tracker_name == "HDB":
if meta.get('hdb') is not None:
Expand All @@ -217,6 +219,8 @@ async def update_metadata_from_tracker(self, tracker_name, tracker_instance, met
meta['hdb_name'] = hdb_name
found_match = True

# Skip user confirmation if searching by ID
console.print(f"[green]{tracker_name} data found: IMDb ID: {imdb}, TVDb ID: {meta['tvdb_id']}, HDB Name: {meta['hdb_name']}[/green]")
else:
console.print("[yellow]No ID found in meta for HDB, searching by file name[/yellow]")

Expand All @@ -229,20 +233,19 @@ async def update_metadata_from_tracker(self, tracker_name, tracker_instance, met
meta[tracker_key] = tracker_id
found_match = True

if found_match:
if imdb or tvdb_id or hdb_name:
console.print(f"[green]{tracker_name} data found: IMDb ID: {imdb}, TVDb ID: {meta['tvdb_id']}, HDB Name: {meta['hdb_name']}[/green]")
if await self.prompt_user_for_confirmation(f"Do you want to use the ID's found on {tracker_name}?"):
console.print(f"[green]{tracker_name} data retained.[/green]")
if found_match:
if imdb or tvdb_id or hdb_name:
console.print(f"[green]{tracker_name} data found: IMDb ID: {imdb}, TVDb ID: {meta['tvdb_id']}, HDB Name: {meta['hdb_name']}[/green]")
if await self.prompt_user_for_confirmation(f"Do you want to use the ID's found on {tracker_name}?"):
console.print(f"[green]{tracker_name} data retained.[/green]")
else:
console.print(f"[yellow]{tracker_name} data discarded.[/yellow]")
meta[tracker_key] = None
meta['tvdb_id'] = None
meta['hdb_name'] = None
found_match = False
else:
console.print(f"[yellow]{tracker_name} data discarded.[/yellow]")
meta[tracker_key] = None
meta['tvdb_id'] = None
meta['hdb_name'] = None
found_match = False
else:
# console.print(f"[yellow]Could not find a matching release on {tracker_name}.[/yellow]")
found_match = False

# console.print(f"[cyan]Finished processing tracker: {tracker_name} with found_match: {found_match}[/cyan]")
return meta, found_match
Expand Down
14 changes: 9 additions & 5 deletions src/trackers/COMMON.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,17 @@ async def unit3d_torrent_info(self, tracker, torrent_url, search_url, id=None, f
else:
file_name = [file['name'] for file in files[:5]] # Return up to 5 filenames

console.print(f"[blue]Extracted filename(s): {file_name}[/blue]") # Print the extracted filename(s)
console.print(f"[blue]Extracted filename(s): {file_name}[/blue]") # Print the extracted filename(s)

# Skip the ID selection prompt if searching by ID
console.print(f"[green]Valid IDs found: TMDb: {tmdb}, IMDb: {imdb}, TVDb: {tvdb}[/green]")

if tmdb or imdb or tvdb:
console.print(f"[green]Valid IDs found: TMDb: {tmdb}, IMDb: {imdb}, TVDb: {tvdb}[/green]")
if not await self.prompt_user_for_id_selection(tmdb, imdb, tvdb, file_name):
console.print("[yellow]User chose to skip based on IDs.[/yellow]")
return None, None, None, None, None, None, None, None, None
if not id:
# Only prompt the user for ID selection if not searching by ID
if not await self.prompt_user_for_id_selection(tmdb, imdb, tvdb, file_name):
console.print("[yellow]User chose to skip based on IDs.[/yellow]")
return None, None, None, None, None, None, None, None, None

if description:
bbcode = BBCODE()
Expand Down
16 changes: 15 additions & 1 deletion src/trackers/PTP.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ async def get_ptp_id_imdb(self, search_term, search_file_folder, meta):
for movie in response['Movies']:
if len(movie['Torrents']) >= 1:
for torrent in movie['Torrents']:
# First, try matching in filelist > path
for file in torrent['FileList']:
if file['Path'] == filename:
if file.get('Path') == filename:
imdb_id = movie['ImdbId']
ptp_torrent_id = torrent['Id']
dummy, ptp_torrent_hash, *_ = await self.get_imdb_from_torrent_id(ptp_torrent_id)
Expand All @@ -118,6 +119,19 @@ async def get_ptp_id_imdb(self, search_term, search_file_folder, meta):
console.print(f"[cyan]Torrent Info: {tinfo}[/cyan]")

return imdb_id, ptp_torrent_id, ptp_torrent_hash

# If no match in filelist > path, check directly in filepath
if torrent.get('FilePath') == filename:
imdb_id = movie['ImdbId']
ptp_torrent_id = torrent['Id']
dummy, ptp_torrent_hash, *_ = await self.get_imdb_from_torrent_id(ptp_torrent_id)
console.print(f'[bold green]Matched release with PTP ID: [yellow]{ptp_torrent_id}[/yellow][/bold green]')

# Call get_torrent_info and print the results
tinfo = await self.get_torrent_info(imdb_id, meta)
console.print(f"[cyan]Torrent Info: {tinfo}[/cyan]")

return imdb_id, ptp_torrent_id, ptp_torrent_hash

console.print(f'[yellow]Could not find any release matching [bold yellow]{filename}[/bold yellow] on PTP')
return None, None, None
Expand Down

0 comments on commit 447c1ad

Please sign in to comment.