Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit3d searching #28

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- master
- develop
- ID-and-Description
- unit3d-searching

env:
REGISTRY: ghcr.io
Expand Down
28 changes: 28 additions & 0 deletions src/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def parse(self, args, meta):
parser.add_argument('-year', '--year', dest='manual_year', nargs='?', required=False, help="Year", type=int, default=0)
parser.add_argument('-ptp', '--ptp', nargs='*', required=False, help="PTP torrent id/permalink", type=str)
parser.add_argument('-blu', '--blu', nargs='*', required=False, help="BLU torrent id/link", type=str)
parser.add_argument('-aither', '--aither', nargs='*', required=False, help="Aither torrent id/link", type=str)
parser.add_argument('-lst', '--lst', nargs='*', required=False, help="LST torrent id/link", type=str)
parser.add_argument('-hdb', '--hdb', nargs='*', required=False, help="HDB torrent id/link", type=str)
parser.add_argument('-d', '--desc', nargs='*', required=False, help="Custom Description (string)")
parser.add_argument('-pb', '--desclink', nargs='*', required=False, help="Custom Description (link to hastebin/pastebin)")
Expand Down Expand Up @@ -136,6 +138,32 @@ def parse(self, args, meta):
console.print('[red]Continuing without --blu')
else:
meta['blu'] = value2
elif key == 'aither':
if value2.startswith('http'):
parsed = urllib.parse.urlparse(value2)
try:
aitherpath = parsed.path
if aitherpath.endswith('/'):
aitherpath = aitherpath[:-1]
meta['aither'] = aitherpath.split('/')[-1]
except Exception:
console.print('[red]Unable to parse id from url')
console.print('[red]Continuing without --aither')
else:
meta['aither'] = value2
elif key == 'lst':
if value2.startswith('http'):
parsed = urllib.parse.urlparse(value2)
try:
lstpath = parsed.path
if lstpath.endswith('/'):
lstpath = lstpath[:-1]
meta['lst'] = lstpath.split('/')[-1]
except Exception:
console.print('[red]Unable to parse id from url')
console.print('[red]Continuing without --lst')
else:
meta['lst'] = value2
elif key == 'hdb':
if value2.startswith('http'):
parsed = urllib.parse.urlparse(value2)
Expand Down
3 changes: 2 additions & 1 deletion src/bbcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ def clean_unit3d_description(self, desc, site):
Uploaded\sUsing\s\[url=https:\/\/github\.com\/HDInnovations\/UNIT3D\]UNIT3D\[\/url\]\s
Auto\sUploader\[\/b\]\s*\[img=\d+\]https:\/\/blutopia\.xyz\/favicon\.ico\[\/img\]\s*\[\/center\]|
\[center\]\s*\[b\]Uploaded\sUsing\s\[url=https:\/\/github\.com\/HDInnovations\/UNIT3D\]UNIT3D\[\/url\]
\sAuto\sUploader\[\/b\]\s*\[\/center\]
\sAuto\sUploader\[\/b\]\s*\[\/center\]|
\[center\]\[url=https:\/\/github\.com\/z-ink\/uploadrr\]\[img=\d+\]https:\/\/i\.ibb\.co\/2NVWb0c\/uploadrr\.webp\[\/img\]\[\/url\]\[\/center\]
"""
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)
Expand Down
145 changes: 72 additions & 73 deletions src/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from src.exceptions import * # noqa: F403
from src.trackers.PTP import PTP
from src.trackers.BLU import BLU
from src.trackers.AITHER import AITHER
from src.trackers.LST import LST
from src.trackers.HDB import HDB
from src.trackers.COMMON import COMMON

Expand Down Expand Up @@ -65,101 +67,83 @@ def __init__(self, screens, img_host, config):
self.img_host = img_host.lower()
tmdb.API_KEY = config['DEFAULT']['tmdb_api']

async def prompt_user_for_id_selection(self, blu_tmdb=None, blu_imdb=None, blu_tvdb=None, blu_filename=None, imdb=None):
async def prompt_user_for_id_selection(self, tmdb=None, imdb=None, tvdb=None, filename=None, tracker_name="BLU"):
if imdb:
imdb = str(imdb).zfill(7) # Convert to string and ensure IMDb ID is 7 characters long by adding leading zeros
console.print(f"[cyan]Found IMDb ID: https://www.imdb.com/title/tt{imdb}")
if blu_tmdb or blu_imdb or blu_tvdb:
if blu_imdb:
blu_imdb = str(blu_imdb).zfill(7) # Convert to string and ensure IMDb ID is 7 characters long by adding leading zeros
console.print("[cyan]Found the following IDs on BLU:")
console.print(f"TMDb ID: {blu_tmdb}")
console.print(f"IMDb ID: https://www.imdb.com/title/tt{blu_imdb}")
console.print(f"TVDb ID: {blu_tvdb}")
console.print(f"Filename: {blu_filename}")

selection = input("Do you want to use this ID? (y/n): ").strip().lower()
console.print(f"[cyan]Found IMDb ID: https://www.imdb.com/title/tt{imdb}[/cyan]")
if tmdb or imdb or tvdb:
if imdb:
imdb = str(imdb).zfill(7) # Convert to string and ensure IMDb ID is 7 characters long by adding leading zeros
console.print(f"[cyan]Found the following IDs on {tracker_name}:")
console.print(f"TMDb ID: {tmdb}")
console.print(f"IMDb ID: https://www.imdb.com/title/tt{imdb}")
console.print(f"TVDb ID: {tvdb}")
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()
return selection == 'y'

async def prompt_user_for_confirmation(self, message):
selection = input(f"{message} (y/n): ").strip().lower()
return selection == 'y'
response = input(f"{message} (Y/n): ").strip().lower()
if response == '' or response == 'y':
return True
return False

async def update_meta_with_unit3d_data(self, meta, tracker_data, tracker_name):
# Unpack the expected 9 elements, ignoring any additional ones
tmdb, imdb, tvdb, mal, desc, category, infohash, imagelist, filename, *rest = tracker_data

if tmdb not in [None, '0']:
meta['tmdb_manual'] = tmdb
if imdb not in [None, '0']:
meta['imdb'] = str(imdb).zfill(7)
if tvdb not in [None, '0']:
meta['tvdb_id'] = tvdb
if mal not in [None, '0']:
meta['mal'] = mal
if desc not in [None, '0', '']:
meta[f'{tracker_name.lower()}_desc'] = desc
if category.upper() in ['MOVIE', 'TV SHOW', 'FANRES']:
meta['category'] = 'TV' if category.upper() == 'TV SHOW' else category.upper()
if not meta.get('image_list'): # Only handle images if image_list is not already populated
if imagelist: # Ensure imagelist is not empty before setting
meta['image_list'] = imagelist
if meta.get('image_list'): # Double-check if image_list is set before handling it
await self.handle_image_list(meta, tracker_name)
if filename:
meta[f'{tracker_name.lower()}_filename'] = filename

console.print(f"[green]{tracker_name} data successfully updated in meta[/green]")

async def update_metadata_from_tracker(self, tracker_name, tracker_instance, meta, search_term, search_file_folder):
tracker_key = tracker_name.lower()
manual_key = f"{tracker_key}_manual"
found_match = False

if tracker_name == "BLU":
if tracker_name in ["BLU", "AITHER", "LST", ]: # Example for UNIT3D trackers
if meta.get(tracker_key) is not None:
console.print(f"[cyan]{tracker_name} ID found in meta, reusing existing ID: {meta[tracker_key]}[/cyan]")
blu_tmdb, blu_imdb, blu_tvdb, blu_mal, blu_desc, blu_category, meta['ext_torrenthash'], blu_imagelist, blu_filename = await COMMON(self.config).unit3d_torrent_info(
"BLU",
tracker_data = await COMMON(self.config).unit3d_torrent_info(
tracker_name,
tracker_instance.torrent_url,
tracker_instance.search_url,
id=meta[tracker_key]
)
if blu_tmdb not in [None, '0'] or blu_imdb not in [None, '0'] or blu_tvdb not in [None, '0']:
console.print(f"[green]Valid data found on {tracker_name}, setting meta values[/green]")
if blu_tmdb not in [None, '0']:
meta['tmdb_manual'] = blu_tmdb
if blu_imdb not in [None, '0']:
meta['imdb'] = str(blu_imdb).zfill(7) # Pad IMDb ID with leading zeros
if blu_tvdb not in [None, '0']:
meta['tvdb_id'] = blu_tvdb
if blu_mal not in [None, '0']:
meta['mal'] = blu_mal
if blu_desc not in [None, '0', '']:
meta['blu_desc'] = blu_desc
if blu_category.upper() in ['MOVIE', 'TV SHOW', 'FANRES']:
meta['category'] = 'TV' if blu_category.upper() == 'TV SHOW' else blu_category.upper()
if not meta.get('image_list'): # Only handle images if image_list is not already populated
if blu_imagelist: # Ensure blu_imagelist is not empty before setting
meta['image_list'] = blu_imagelist
if meta.get('image_list'): # Double-check if image_list is set before handling it
await self.handle_image_list(meta, tracker_name)
if blu_filename:
meta['blu_filename'] = blu_filename # Store the filename in meta for later use
found_match = True
console.print("[green]BLU data successfully updated in meta[/green]")
else:
console.print(f"[yellow]No valid data found on {tracker_name}[/yellow]")
else:
console.print("[yellow]No ID found in meta for BLU, searching by file name[/yellow]")
blu_tmdb, blu_imdb, blu_tvdb, blu_mal, blu_desc, blu_category, meta['ext_torrenthash'], blu_imagelist, blu_filename = await COMMON(self.config).unit3d_torrent_info(
"BLU",
console.print(f"[yellow]No ID found in meta for {tracker_name}, searching by file name[/yellow]")
tracker_data = await COMMON(self.config).unit3d_torrent_info(
tracker_name,
tracker_instance.torrent_url,
tracker_instance.search_url,
file_name=search_term
)

if blu_tmdb not in [None, '0'] or blu_imdb not in [None, '0'] or blu_tvdb not in [None, '0']:
console.print(f"[green]Valid data found on {tracker_name} using file name, setting meta values[/green]")

if blu_tmdb not in [None, '0']:
meta['tmdb_manual'] = blu_tmdb
if blu_imdb not in [None, '0']:
meta['imdb'] = str(blu_imdb).zfill(7)
if blu_tvdb not in [None, '0']:
meta['tvdb_id'] = blu_tvdb
if blu_mal not in [None, '0']:
meta['mal'] = blu_mal
if blu_desc not in [None, '0', '']:
meta['blu_desc'] = blu_desc
if blu_category.upper() in ['MOVIE', 'TV SHOW', 'FANRES']:
meta['category'] = 'TV' if blu_category.upper() == 'TV SHOW' else blu_category.upper()
if not meta.get('image_list'): # Only handle images if image_list is not already populated
if blu_imagelist: # Ensure blu_imagelist is not empty before setting
meta['image_list'] = blu_imagelist
if meta.get('image_list'): # Double-check if image_list is set before handling it
await self.handle_image_list(meta, tracker_name)
if blu_filename:
meta['blu_filename'] = blu_filename

found_match = True
console.print("[green]BLU data successfully updated in meta[/green]")
else:
console.print(f"[yellow]No valid data found on {tracker_name}[/yellow]")
if any(item not in [None, '0'] for item in tracker_data[:3]): # Check for valid tmdb, imdb, or tvdb
console.print(f"[green]Valid data found on {tracker_name}, setting meta values[/green]")
await self.update_meta_with_unit3d_data(meta, tracker_data, tracker_name)
found_match = True
else:
console.print(f"[yellow]No valid data found on {tracker_name}[/yellow]")

elif tracker_name == "PTP":
imdb_id = None # Ensure imdb_id is defined
Expand Down Expand Up @@ -247,7 +231,6 @@ async def update_metadata_from_tracker(self, tracker_name, tracker_instance, met
else:
found_match = False

# console.print(f"[cyan]Finished processing tracker: {tracker_name} with found_match: {found_match}[/cyan]")
return meta, found_match

async def handle_image_list(self, meta, tracker_name):
Expand Down Expand Up @@ -397,6 +380,10 @@ async def gather_prep(self, meta, mode):
specific_tracker = 'HDB'
elif meta.get('blu'):
specific_tracker = 'BLU'
elif meta.get('aither'):
specific_tracker = 'AITHER'
elif meta.get('lst'):
specific_tracker = 'LST'

# If a specific tracker is found, only process that one
if specific_tracker:
Expand All @@ -414,6 +401,18 @@ async def gather_prep(self, meta, mode):
if match:
found_match = True

elif specific_tracker == 'AITHER' and str(self.config['TRACKERS'].get('AITHER', {}).get('useAPI')).lower() == "true":
aither = AITHER(config=self.config)
meta, match = await self.update_metadata_from_tracker('AITHER', aither, meta, search_term, search_file_folder)
if match:
found_match = True

elif specific_tracker == 'LST' and str(self.config['TRACKERS'].get('LST', {}).get('useAPI')).lower() == "true":
lst = LST(config=self.config)
meta, match = await self.update_metadata_from_tracker('LST', lst, meta, search_term, search_file_folder)
if match:
found_match = True

elif specific_tracker == 'HDB' and str(self.config['TRACKERS'].get('HDB', {}).get('useAPI')).lower() == "true":
hdb = HDB(config=self.config)
meta, match = await self.update_metadata_from_tracker('HDB', hdb, meta, search_term, search_file_folder)
Expand Down
29 changes: 18 additions & 11 deletions src/trackers/COMMON.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,27 @@ async def unit3d_distributor_ids(self, distributor):
}.get(distributor, 0)
return distributor_id

async def prompt_user_for_id_selection(self, blu_tmdb=None, blu_imdb=None, blu_tvdb=None, blu_filename=None, imdb=None):
async def prompt_user_for_id_selection(self, tmdb=None, imdb=None, tvdb=None, filename=None, tracker_name=None):
if not tracker_name:
tracker_name = "Tracker" # Fallback if tracker_name is not provided

if imdb:
imdb = str(imdb).zfill(7) # Convert to string and ensure IMDb ID is 7 characters long by adding leading zeros
console.print(f"[cyan]Found IMDb ID: https://www.imdb.com/title/tt{imdb}[/cyan]")
if blu_tmdb or blu_imdb or blu_tvdb:
if blu_imdb:
blu_imdb = str(blu_imdb).zfill(7) # Convert to string and ensure IMDb ID is 7 characters long by adding leading zeros
console.print("[cyan]Found the following IDs on BLU:")
console.print(f"TMDb ID: {blu_tmdb}")
console.print(f"IMDb ID: https://www.imdb.com/title/tt{blu_imdb}")
console.print(f"TVDb ID: {blu_tvdb}")
console.print(f"Filename: {blu_filename}") # Ensure filename is printed if available

selection = input("Do you want to use this ID? (y/n): ").strip().lower()

if any([tmdb, imdb, tvdb]):
console.print(f"[cyan]Found the following IDs on {tracker_name}:")
if tmdb:
console.print(f"TMDb ID: {tmdb}")
if imdb:
console.print(f"IMDb ID: https://www.imdb.com/title/tt{imdb}")
if tvdb:
console.print(f"TVDb ID: {tvdb}")

if filename:
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()
return selection == 'y'

async def prompt_user_for_confirmation(self, message):
Expand Down
Loading