|
|
|
import os |
|
import json |
|
|
|
def process_json_file(json_path, base_dir): |
|
try: |
|
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) |
|
|
|
|
|
cringe_filename = f"{filename}.cringe" |
|
|
|
|
|
cringe_content = f"""{{{{< blurhash |
|
src="https://huggingface.co/k4d3/yiff_toolkit6/resolve/main/static/{directory}/{filename}" |
|
blurhash="{blurhash}" |
|
width="{width}" |
|
height="{height}" |
|
alt="{caption}" |
|
grid="true" |
|
>}}}}""" |
|
|
|
|
|
output_path = os.path.join(os.path.dirname(json_path), cringe_filename) |
|
with open(output_path, 'w') as cringe_file: |
|
cringe_file.write(cringe_content) |
|
|
|
print(f"Processed: {json_path}") |
|
|
|
except Exception as e: |
|
print(f"Error processing {json_path}: {str(e)}") |
|
|
|
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) |
|
|