import os import re import random import subprocess import json import sys if len(sys.argv) < 2: print("Usage: py generate.py nama_folder") sys.exit() folder = sys.argv[1] thumb_folder = os.path.join(folder, "thumbnails") os.makedirs(thumb_folder, exist_ok=True) video_ext = (".mp4", ".mov", ".mkv", ".avi") spintax = """ {Artis|Tiktoker|Selebgram|Model|Influencer|Gadis Viral} {Cantik|Manis|Seksi|Imut|Hot|Memikat|Menawan} {Bikin Heboh|Bikin Salfok|Viral|Aduhai|Menggoda} Saat {Berpose|Berjoget|Bergoyang|Dance|Pamer Gaya} di {Tiktok|Instagram|Sosmed|Live Streaming|Reels} """ def spin(text): pattern = re.compile(r"\{([^{}]+?)\}") while True: match = pattern.search(text) if not match: break options = match.group(1).split("|") text = text[:match.start()] + random.choice(options) + text[match.end():] return " ".join(text.split()) used_titles = set() data = [] for file in os.listdir(folder): if not file.lower().endswith(video_ext): continue old_path = os.path.join(folder, file) # generate title unik title = spin(spintax) while title in used_titles: title = spin(spintax) used_titles.add(title) # rename file (underscore) slug = title.replace(" ", "_") ext = os.path.splitext(file)[1] new_filename = slug + ext new_path = os.path.join(folder, new_filename) os.rename(old_path, new_path) # generate thumbnail thumb_name = slug + ".jpg" thumb_path = os.path.join(thumb_folder, thumb_name) command = [ "ffmpeg", "-ss", "10", "-i", new_path, "-frames:v", "1", "-q:v", "2", thumb_path, "-y" ] subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # data json data.append({ "title": title, "tags": "Selebgram, Tiktoker", "videoType": "direct", "videoUrl": f"{folder}/{new_filename}", "posterUrl": f"{folder}/thumbnails/{thumb_name}" }) json_path = os.path.join(folder, "videos_import.json") with open(json_path, "w", encoding="utf-8") as f: json.dump(data, f, indent=4, ensure_ascii=False) print("Selesai!") print("Thumbnail:", thumb_folder) print("JSON:", json_path)