Skip to content

Commit

Permalink
Make multi description configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Audionut committed Oct 29, 2024
1 parent 0f598d7 commit 5de9b1f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
13 changes: 12 additions & 1 deletion data/example-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@
"screens": "6",

# Number of screenshots to use for each disc/episode in packs
# Currently PTP only
"multiScreens": "2",

# Description character count cutoff for UNIT3D sites when season packs only
# After hitting this limit, only filenames and screenshots will be used for any ADDITIONAL files
# still to be added to the description. You can set this small like 50, to only ever
# print filenames and screenshots for each file, no mediainfo will be printed.
# UNIT3D sites have a hard character limit for descriptions. A little over 17000
# worked fine in a forum post at BLU. If you are at 1 < charLimit, the next full description will be added.
"charLimit": "16000",

# How many files in a season pack will be added to the description before using an additional spoiler tag
# Any other files past this limit will be hidden/added all within a spoiler tag.
"fileLimit": "5",

# Providing the option to change the size of the thumbnails where supported, default is 350
"thumbnail_size": "350",
Expand Down
25 changes: 13 additions & 12 deletions src/trackers/COMMON.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ async def unit3d_edit_desc(self, meta, tracker, signature, comparison=False, des
from src.prep import Prep
prep = Prep(screens=meta['screens'], img_host=meta['imghost'], config=self.config)
base = open(f"{meta['base_dir']}/tmp/{meta['uuid']}/DESCRIPTION.txt", 'r', encoding='utf8').read()
multi_screens = int(self.config['DEFAULT'].get('multiScreens', 2))
char_limit = int(self.config['DEFAULT'].get('charLimit', 16000))
file_limit = int(self.config['DEFAULT'].get('fileLimit', 5))
with open(f"{meta['base_dir']}/tmp/{meta['uuid']}/[{tracker}]DESCRIPTION.txt", 'w', encoding='utf8') as descfile:
if desc_header:
descfile.write(desc_header)
Expand Down Expand Up @@ -88,7 +91,7 @@ async def unit3d_edit_desc(self, meta, tracker, signature, comparison=False, des
console.print("[yellow]Using original images from meta['image_list'] for disc_0")
images = meta['image_list']
descfile.write("[center]")
for img_index in range(min(2, len(images))):
for img_index in range(min(multi_screens, len(images))):
raw_url = images[img_index]['raw_url']
descfile.write(f"[img=300]{raw_url}[/img] ")
descfile.write("[/center]\n\n")
Expand All @@ -114,7 +117,7 @@ async def unit3d_edit_desc(self, meta, tracker, signature, comparison=False, des
console.print(f"[yellow]No new screens for {new_images_key}; creating new screenshots")
# Run prep.screenshots if no screenshots are present
use_vs = meta.get('vapoursynth', False)
s = multiprocessing.Process(target=prep.disc_screenshots, args=(f"FILE_{i}", each['bdinfo'], meta['uuid'], meta['base_dir'], use_vs, [], meta.get('ffdebug', False), 2))
s = multiprocessing.Process(target=prep.disc_screenshots, args=(f"FILE_{i}", each['bdinfo'], meta['uuid'], meta['base_dir'], use_vs, [], meta.get('ffdebug', False), multi_screens))
s.start()
while s.is_alive():
await asyncio.sleep(1)
Expand All @@ -125,7 +128,7 @@ async def unit3d_edit_desc(self, meta, tracker, signature, comparison=False, des
if new_screens:
uploaded_images, _ = prep.upload_screens(
meta,
2, 1, 0, 2,
multi_screens, 1, 0, 2,
new_screens,
{new_images_key: meta[new_images_key]}
)
Expand Down Expand Up @@ -163,7 +166,7 @@ async def unit3d_edit_desc(self, meta, tracker, signature, comparison=False, des
# Handle multiple files case
# Initialize character counter
char_count = 0
max_char_limit = 100 # Character limit
max_char_limit = char_limit # Character limit
other_files_spoiler_open = False # Track if "Other files" spoiler has been opened

# Process each file
Expand Down Expand Up @@ -201,11 +204,9 @@ async def unit3d_edit_desc(self, meta, tracker, signature, comparison=False, des

continue # Skip full MediaInfo and spoilers for remaining files

# Standard processing for files until character limit is reached
new_images_key = f'new_images_file_{i}'

if i < 5:
# Standard processing for the first five files
if i < file_limit:
if i == 0:
mi_dump = open(f"{meta['base_dir']}/tmp/{meta['uuid']}/MEDIAINFO_CLEANPATH.txt", 'r', encoding='utf-8').read()
if mi_dump:
Expand All @@ -221,7 +222,7 @@ async def unit3d_edit_desc(self, meta, tracker, signature, comparison=False, des
images = meta['image_list']
descfile.write("[center]")
char_count += len("[center]")
for img_index in range(min(2, len(images))):
for img_index in range(min(multi_screens, len(images))):
web_url = images[img_index]['web_url']
raw_url = images[img_index]['raw_url']
image_str = f"[url={web_url}][img=300]{raw_url}[/img][/url] "
Expand Down Expand Up @@ -258,14 +259,14 @@ async def unit3d_edit_desc(self, meta, tracker, signature, comparison=False, des

new_screens = glob.glob1(f"{meta['base_dir']}/tmp/{meta['uuid']}", f"FILE_{i}-*.png")
if not new_screens:
s = multiprocessing.Process(target=prep.screenshots, args=(file, f"FILE_{i}", meta['uuid'], meta['base_dir'], meta, 3, True, None))
s = multiprocessing.Process(target=prep.screenshots, args=(file, f"FILE_{i}", meta['uuid'], meta['base_dir'], meta, multi_screens + 1, True, None))
s.start()
while s.is_alive():
await asyncio.sleep(1)
new_screens = glob.glob1(f"{meta['base_dir']}/tmp/{meta['uuid']}", f"FILE_{i}-*.png")

if new_screens:
uploaded_images, _ = prep.upload_screens(meta, 2, 1, 0, 2, new_screens, {new_images_key: meta[new_images_key]})
uploaded_images, _ = prep.upload_screens(meta, multi_screens, 1, 0, 2, new_screens, {new_images_key: meta[new_images_key]})
for img in uploaded_images:
meta[new_images_key].append({
'img_url': img['img_url'],
Expand All @@ -287,13 +288,13 @@ async def unit3d_edit_desc(self, meta, tracker, signature, comparison=False, des
with open(meta_filename, 'w') as f:
json.dump(meta, f, indent=4)

elif i == 5 and not other_files_spoiler_open:
elif i == file_limit and not other_files_spoiler_open:
# Open "Other files" spoiler for the fifth file
descfile.write("[spoiler=Other files]\n")
char_count += len("[spoiler=Other files]\n")
other_files_spoiler_open = True

if i >= 5 and char_count < max_char_limit:
if i >= file_limit and char_count < max_char_limit:
mi_dump = MediaInfo.parse(file, output="STRING", full=False, mediainfo_options={'inform_version': '1'})
parsed_mediainfo = self.parser.parse_mediainfo(mi_dump)
formatted_bbcode = self.parser.format_bbcode(parsed_mediainfo)
Expand Down

0 comments on commit 5de9b1f

Please sign in to comment.