diff --git a/src/bbcode.py b/src/bbcode.py index 755cea4ca..983469c4e 100644 --- a/src/bbcode.py +++ b/src/bbcode.py @@ -198,6 +198,12 @@ def clean_unit3d_description(self, desc, site): # Remove the [img] tag and its contents from the description desc = re.sub(rf"\[img[^\]]*\]{re.escape(img_url)}\[/img\]", '', desc, flags=re.IGNORECASE) + # Now, remove matching URLs from [URL] tags + for img in imagelist: + img_url = re.escape(img['img_url']) + desc = re.sub(rf"\[URL={img_url}\]\[/URL\]", '', desc, flags=re.IGNORECASE) + desc = re.sub(rf"\[URL={img_url}\]\[img[^\]]*\]{img_url}\[/img\]\[/URL\]", '', desc, flags=re.IGNORECASE) + # Filter out bot images from imagelist bot_image_urls = [ "https://blutopia.xyz/favicon.ico", # Example bot image URL @@ -236,10 +242,10 @@ def clean_unit3d_description(self, desc, site): desc = re.sub(bot_signature_regex, "", desc, flags=re.IGNORECASE | re.VERBOSE) desc = re.sub(r"\[center\].*Created by L4G's Upload Assistant.*\[\/center\]", "", desc, flags=re.IGNORECASE) - # Ensure no dangling tags and remove extra blank lines - desc = re.sub(r'\n\s*\n', '\n', desc) # Remove multiple consecutive blank lines - desc = re.sub(r'\n\n+', '\n\n', desc) # Ensure no excessive blank lines - desc = desc.strip() # Final cleanup of trailing newlines and spaces + # Remove leftover [img] or [URL] tags in the description + desc = re.sub(r"\[img\][\s\S]*?\[\/img\]", "", desc, flags=re.IGNORECASE) + desc = re.sub(r"\[img=[\s\S]*?\]", "", desc, flags=re.IGNORECASE) + desc = re.sub(r"\[URL=[\s\S]*?\]\[\/URL\]", "", desc, flags=re.IGNORECASE) # Strip trailing whitespace and newlines: desc = desc.rstrip() diff --git a/src/prep.py b/src/prep.py index c860718c8..f93e12faa 100644 --- a/src/prep.py +++ b/src/prep.py @@ -47,6 +47,7 @@ import aiohttp from PIL import Image import io + import sys except ModuleNotFoundError: console.print(traceback.print_exc()) console.print('[bold red]Missing Module Found. Please reinstall required dependancies.') @@ -77,8 +78,7 @@ async def prompt_user_for_confirmation(self, message: str) -> bool: return True return False except EOFError: - console.print("[bold red]Input was interrupted.") - return False + sys.exit(1) async def check_images_concurrently(self, imagelist): async def check_and_collect(image_dict): @@ -294,7 +294,7 @@ async def handle_image_list(self, meta, tracker_name): approved_image_hosts = ['ptpimg', 'imgbox'] # Check if the images are already hosted on an approved image host - if all(any(host in img for host in approved_image_hosts) for img in meta['image_list']): + if all(any(host in image['raw_url'] for host in approved_image_hosts) for image in meta['image_list']): image_list = meta['image_list'] # noqa #F841 else: console.print("[red]Warning: Some images are not hosted on an MTV approved image host. MTV will fail if you keep these images.") diff --git a/src/trackers/COMMON.py b/src/trackers/COMMON.py index a9fb5f536..b9a9270d9 100644 --- a/src/trackers/COMMON.py +++ b/src/trackers/COMMON.py @@ -4,6 +4,7 @@ import re import json import click +import sys from src.bbcode import BBCODE from src.console import console @@ -163,10 +164,13 @@ async def prompt_user_for_id_selection(self, tmdb=None, imdb=None, tvdb=None, fi console.print(f"Filename: {filename}") # Ensure filename is printed if available selection = input(f"Do you want to use these IDs from {tracker_name}? (Y/n): ").strip().lower() - if selection == '' or selection == 'y' or selection == 'yes': - return True - else: - return False + try: + if selection == '' or selection == 'y' or selection == 'yes': + return True + else: + return False + except (KeyboardInterrupt, EOFError): + sys.exit(1) async def prompt_user_for_confirmation(self, message): response = input(f"{message} (Y/n): ").strip().lower() @@ -246,15 +250,18 @@ async def unit3d_torrent_info(self, tracker, torrent_url, search_url, id=None, f if tmdb or imdb or tvdb: 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 + try: + 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 + except (KeyboardInterrupt, EOFError): + sys.exit(1) if description: bbcode = BBCODE() description, imagelist = bbcode.clean_unit3d_description(description, torrent_url) console.print(f"[green]Successfully grabbed description from {tracker}") - console.print(f"[blue]Extracted description: [yellow]{description}") + console.print(f"[blue]Extracted description: [yellow]{description}", markup=False) # Allow user to edit or discard the description console.print("[cyan]Do you want to edit, discard or keep the description?[/cyan]") @@ -264,7 +271,7 @@ async def unit3d_torrent_info(self, tracker, torrent_url, search_url, id=None, f edited_description = click.edit(description) if edited_description: description = edited_description.strip() - console.print(f"[green]Final description after editing:[/green] {description}") + console.print(f"[green]Final description after editing:[/green] {description}", markup=False) elif edit_choice.lower() == 'd': description = None console.print("[yellow]Description discarded.[/yellow]")