Skip to content

Commit

Permalink
Fix PTP miniseries images
Browse files Browse the repository at this point in the history
  • Loading branch information
Audionut committed Sep 8, 2024
1 parent e49deef commit decfa5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,14 +1259,16 @@ def _is_vob_good(n, loops, num_screens):
smallest = screens
os.remove(smallest)

def screenshots(self, path, filename, folder_id, base_dir, meta, num_screens=None):
def screenshots(self, path, filename, folder_id, base_dir, meta, num_screens=None, force_screenshots=False):
# Ensure the image list is initialized and preserve existing images
if 'image_list' not in meta:
meta['image_list'] = []

# Check if there are already at least 3 image links in the image list
existing_images = [img for img in meta['image_list'] if isinstance(img, dict) and img.get('img_url', '').startswith('http')]
if len(existing_images) >= 3:

# Skip taking screenshots if there are already 3 images and force_screenshots is False
if len(existing_images) >= 3 and not force_screenshots:
console.print("[yellow]There are already at least 3 images in the image list. Skipping additional screenshots.")
return

Expand Down Expand Up @@ -1375,9 +1377,14 @@ def screenshots(self, path, filename, folder_id, base_dir, meta, num_screens=Non

# Remove the smallest image if there are more than needed
if len(meta['image_list']) > self.screens:
smallest = min(meta['image_list'], key=lambda x: os.path.getsize(x['img_url']))
os.remove(smallest['img_url'])
meta['image_list'].remove(smallest)
local_images = [img for img in meta['image_list'] if not img['img_url'].startswith('http')]

if local_images:
smallest = min(local_images, key=lambda x: os.path.getsize(x['img_url']))
os.remove(smallest['img_url'])
meta['image_list'].remove(smallest)
else:
console.print("[yellow]No local images found to remove.")

def valid_ss_time(self, ss_times, num_screens, length):
valid_time = False
Expand Down
11 changes: 9 additions & 2 deletions src/trackers/PTP.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ async def edit_desc(self, meta):
elif len(meta.get('filelist', [])) >= 1:
for i in range(len(meta['filelist'])):
file = meta['filelist'][i]

if i == 0:
# Add This line for all web-dls
if meta['type'] == 'WEBDL' and meta.get('service_longname', '') != '' and meta.get('description', None) is None and self.web_source is True:
Expand All @@ -673,24 +674,30 @@ async def edit_desc(self, meta):
else:
# Export Mediainfo
mi_dump = MediaInfo.parse(file, output="STRING", full=False, mediainfo_options={'inform_version': '1'})
# mi_dump = mi_dump.replace(file, os.path.basename(file))
with open(f"{meta['base_dir']}/tmp/{meta['uuid']}/TEMP_PTP_MEDIAINFO.txt", "w", newline="", encoding="utf-8") as f:
f.write(mi_dump)
mi_dump = open(f"{meta['base_dir']}/tmp/{meta['uuid']}/TEMP_PTP_MEDIAINFO.txt", "r", encoding="utf-8").read()

# Generate and upload screens for other files
s = multiprocessing.Process(target=prep.screenshots, args=(file, f"FILE_{i}", meta['uuid'], meta['base_dir'], meta, 2))
# Add force_screenshots=True to ensure screenshots are taken even if images exist
s = multiprocessing.Process(target=prep.screenshots, args=(file, f"FILE_{i}", meta['uuid'], meta['base_dir'], meta, 2, True))
s.start()
while s.is_alive() is True:
await asyncio.sleep(3)

# Upload new screenshots
new_screens = glob.glob1(f"{meta['base_dir']}/tmp/{meta['uuid']}", f"FILE_{i}-*.png")
images, dummy = prep.upload_screens(meta, 2, 1, 0, 2, new_screens, {})

# Write MediaInfo and screenshots to the description
desc.write(f"[mediainfo]{mi_dump}[/mediainfo]\n")

if i == 0:
base2ptp = self.convert_bbcode(base)
if base2ptp.strip() != "":
desc.write(base2ptp)
desc.write("\n\n")

if len(images) > 0:
for each in range(len(images[:int(meta['screens'])])):
raw_url = images[each]['raw_url']
Expand Down

0 comments on commit decfa5e

Please sign in to comment.