|
#!/usr/bin/env python |
|
|
|
import os |
|
import json |
|
|
|
def process_json_file(json_path, base_dir): |
|
with open(json_path, 'r') as file: |
|
data = json.load(file) |
|
filename = data['filename'] |
|
width = data['width'] |
|
height = data['height'] |
|
blurhash = data['blurhash'] |
|
caption = data['caption'] |
|
|
|
image_filename, image_fileextension = os.path.splitext(filename) |
|
image_fileextension = image_fileextension.lstrip('.') |
|
|
|
directory = os.path.relpath(os.path.dirname(json_path), base_dir) |
|
directory = directory.replace('static/', '', 1) # Remove the first occurrence of 'static/' |
|
|
|
cringe_filename = f"{image_filename}.{image_fileextension}.cringe" |
|
cringe_content = f"" |
|
src="https://huggingface.co/k4d3/yiff_toolkit/resolve/main/static/{directory}/{filename}" |
|
blurhash="{blurhash}" |
|
width="{width}" |
|
height="{height}" |
|
alt="{caption}" |
|
grid="true" |
|
>}}}}"" |
|
|
|
with open(os.path.join(os.path.dirname(json_path), cringe_filename), 'w') as cringe_file: |
|
cringe_file.write(cringe_content) |
|
|
|
def recurse_directories(base_dir): |
|
for root, _, files in os.walk(base_dir): |
|
for file in files: |
|
if file.endswith('.json'): |
|
process_json_file(os.path.join(root, file), base_dir) |
|
|
|
if __name__ == "__main__": |
|
base_directory = os.path.join(os.getcwd(), 'yiff_toolkit6') |
|
recurse_directories(base_directory) |
|
|
|
|