update scripts

This commit is contained in:
Waylon Walker 2025-10-12 12:48:25 -05:00
parent b1a74f24ae
commit e57ffee038

View file

@ -6,12 +6,22 @@
# "Pillow",
# ]
# ///
import os, glob, shutil
"""
Mostly done by gpt-5
"""
import os
import glob
import shutil
from rich import print
from PIL import Image
import random
base_dir = "/mnt/media/youtube"
def set_posters(base_dir: str) -> None:
"""
Set the latest thumbnail as the poster for each channel.
"""
for channel_dir in os.listdir(base_dir):
full_path = os.path.join(base_dir, channel_dir)
if not os.path.isdir(full_path):
@ -19,10 +29,10 @@ for channel_dir in os.listdir(base_dir):
# find all video thumbnails (jpg/png)
thumbs = sorted(
glob.glob(os.path.join(full_path, "**/*.jpg")) +
glob.glob(os.path.join(full_path, "**/*.png")),
glob.glob(os.path.join(full_path, "**/*.jpg"))
+ glob.glob(os.path.join(full_path, "**/*.png")),
key=os.path.getmtime,
reverse=True
reverse=True,
)
if not thumbs:
@ -32,32 +42,34 @@ for channel_dir in os.listdir(base_dir):
latest_thumb = thumbs[0]
poster_path = os.path.join(full_path, "poster.jpg")
if not os.path.exists(poster_path) or os.path.getmtime(latest_thumb) > os.path.getmtime(poster_path):
if not os.path.exists(poster_path) or os.path.getmtime(
latest_thumb
) > os.path.getmtime(poster_path):
shutil.copy2(latest_thumb, poster_path)
print(f"Set poster for {channel_dir}{os.path.basename(latest_thumb)}")
def grid_collage(base_dir: str) -> None:
## Grid collage
from PIL import Image
import glob, os, random
# base_dir = "/mnt/main/media/YouTube"
poster_path = os.path.join(base_dir, "poster.jpg")
# Collect recent thumbnails from subfolders
thumbs = []
# for root, dirs, files in os.walk(base_dir):
# for f in files:
# if f.lower().endswith((".jpg", ".png")) and "poster" not in f:
# thumbs.append(os.path.join(root, f))
# thumbs = sorted(thumbs, key=os.path.getmtime, reverse=True)[:50]
thumbs = sorted(glob.glob(os.path.join(base_dir, "**/*.jpg")) + glob.glob(os.path.join(base_dir, "**/*.png")), key=os.path.getmtime, reverse=True)[:50]
thumbs = sorted(
glob.glob(os.path.join(base_dir, "**/*.jpg"))
+ glob.glob(os.path.join(base_dir, "**/*.png")),
key=os.path.getmtime,
reverse=True,
)[:50]
random.shuffle(thumbs)
if not thumbs:
raise SystemExit("No thumbnails found")
# Make a 5x5 grid collage (adjust as desired)
rows, cols = 2, 2
rows, cols = 5, 5
tile_size = 256
grid = Image.new("RGB", (cols * tile_size, rows * tile_size))
@ -68,3 +80,14 @@ for i, thumb in enumerate(thumbs[:rows*cols]):
grid.save(poster_path, quality=85)
print(f"Created {poster_path}")
if __name__ == "__main__":
base_dirs = [
"/mnt/media/youtube/shared",
"/mnt/media/youtube/waylon",
]
for base_dir in base_dirs:
set_posters(base_dir)
grid_collage(base_dir)