Skip to content

Commit

Permalink
More graceful existing
Browse files Browse the repository at this point in the history
Fix some bbcode rendering in unit3d trackers

Hopefully fix MTV warning for wrong host urls
  • Loading branch information
Audionut committed Sep 7, 2024
1 parent eb8d2bd commit b9302bb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
14 changes: 10 additions & 4 deletions src/bbcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.")
Expand Down
25 changes: 16 additions & 9 deletions src/trackers/COMMON.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import json
import click
import sys

from src.bbcode import BBCODE
from src.console import console
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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]")
Expand All @@ -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]")
Expand Down

0 comments on commit b9302bb

Please sign in to comment.