From 447c1ad50a7970a0e0dd7a65aad4a8f2465440e7 Mon Sep 17 00:00:00 2001 From: Audionut Date: Sun, 1 Sep 2024 22:18:33 +1000 Subject: [PATCH] Skip user confirmation step when using manual ID --- src/prep.py | 41 ++++++++++++++++++++++------------------- src/trackers/COMMON.py | 14 +++++++++----- src/trackers/PTP.py | 16 +++++++++++++++- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/prep.py b/src/prep.py index 304c7e333..f44918770 100644 --- a/src/prep.py +++ b/src/prep.py @@ -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]") @@ -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 @@ -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: @@ -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]") @@ -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 diff --git a/src/trackers/COMMON.py b/src/trackers/COMMON.py index 5cd5f7866..89b4022e6 100644 --- a/src/trackers/COMMON.py +++ b/src/trackers/COMMON.py @@ -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() diff --git a/src/trackers/PTP.py b/src/trackers/PTP.py index 8377c8545..253591966 100644 --- a/src/trackers/PTP.py +++ b/src/trackers/PTP.py @@ -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) @@ -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