generated from your-land/yl_template
67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
import os
|
|
import random
|
|
import string
|
|
import json
|
|
import shutil
|
|
|
|
# Define the number of movies to create
|
|
num_movies = 1000
|
|
|
|
# Define the range of values for the movie data
|
|
min_duration = 2
|
|
max_duration = 10
|
|
min_captionposx = 1
|
|
max_captionposx = 8
|
|
min_captionposy = 1
|
|
max_captionposy = 6
|
|
|
|
# Define the path to the template PNG file
|
|
template_path = "path/to/template.png"
|
|
|
|
# Define a function to generate a random string of letters and digits
|
|
def generate_random_string(length):
|
|
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
|
|
|
|
# Define a function to generate the data for a single movie
|
|
def generate_movie_data(movie_id):
|
|
name = generate_random_string(10)
|
|
description = generate_random_string(50)
|
|
title_texture = generate_random_string(10) + ".png"
|
|
replay = bool(random.getrandbits(1))
|
|
num_pages = random.randint(1, 10)
|
|
pages = []
|
|
for i in range(num_pages):
|
|
order = i + 1
|
|
texturename = generate_random_string(10) + ".png"
|
|
caption = generate_random_string(20)
|
|
captionposx = random.randint(min_captionposx, max_captionposx)
|
|
captionposy = random.randint(min_captionposy, max_captionposy)
|
|
duration = random.randint(min_duration, max_duration)
|
|
page = {"order": order, "texturename": texturename, "caption": caption,
|
|
"captionposx": captionposx, "captionposy": captionposy, "duration": duration}
|
|
pages.append(page)
|
|
movie_data = {"movie_id": movie_id, "name": name, "description": description,
|
|
"title_texture": title_texture, "replay": replay, "pages": pages}
|
|
return movie_data
|
|
|
|
# Create the JSON files and folders
|
|
for i in range(num_movies):
|
|
movie_id = i + 1
|
|
movie_data = generate_movie_data(movie_id)
|
|
foldername = "movie_" + str(movie_id)
|
|
os.mkdir(foldername)
|
|
texture_folder = os.path.join(foldername, "textures")
|
|
os.mkdir(texture_folder)
|
|
title_texture_path = os.path.join(texture_folder, movie_data["title_texture"])
|
|
shutil.copyfile(template_path, title_texture_path)
|
|
for page in movie_data["pages"]:
|
|
texturename_path = os.path.join(texture_folder, page["texturename"])
|
|
shutil.copyfile(template_path, texturename_path)
|
|
filename = "movie_" + str(movie_id) + ".json"
|
|
filepath = os.path.join(foldername, filename)
|
|
with open(filepath, "w") as f:
|
|
json.dump(movie_data, f)
|
|
print("Created", filepath)
|
|
|
|
print("Done!")
|