>>64580why not just use chatgpt to fix it for you with a python script
import os
import subprocess
import mysql.connector
# Configuration variable
board = "lounge"
# Function to connect to MySQL database
def connect_to_database():
    try:
        connection = mysql.connector.connect(
            host="localhost",
            user="dbadmin",
            password="dbpassword",
            database="wizchandb"
        )
        return connection
    except mysql.connector.Error as err:
        print("Error: ", err)
        return None
# Function to query the database
def query_database(connection, filename):
    try:
        cursor = connection.cursor()
        truncated_filename = filename[:10]
        next_truncated_filename = str(int(truncated_filename) + 1)
        query = f"SELECT * FROM posts_{board} WHERE (files LIKE %s OR files LIKE %s) AND (files NOT LIKE %s) AND (files NOT LIKE %s)"
        cursor.execute(query, (f'%{truncated_filename}%', f'%{next_truncated_filename}%', '%spoiler%', '%thumb%'))
        result = cursor.fetchone()
        cursor.close()
        return result
    except mysql.connector.Error as err:
        print("Error: ", err)
        return None
# Function to generate thumbnails
def generate_thumbnail(video_path, thumbnail_path):
    try:
        subprocess.run([
            "/usr/bin/ffmpeg",
            "-i", video_path,
            "-vf", "thumbnail,scale='if(gt(iw,ih),min(255,iw),-2):if(gt(iw,ih),-2,min(255,ih))'",
            "-frames:v", "1",
            thumbnail_path
        ], check=True)
        print(f"Thumbnail generated for {video_path}")
    except subprocess.CalledProcessError as err:
        print("Error: ", err)
# Main function
def main():
    src_directory = os.path.join("/var/www/wizchan", board, "src/")
    thumb_directory = os.path.join("/var/www/wizchan", board, "thumb/")
    
    # Connect to the database
    connection = connect_to_database()
    if not connection:
        return
    
    # Iterate through files in src directory
    for filename in os.listdir(src_directory):
        if filename.endswith(".mp4") or filename.endswith(".webm"):
            full_path = os.path.join(src_directory, filename)
            # Check if filename is in database and does not contain "spoiler"
            db_result = query_database(connection, filename)
            if db_result and "spoiler" not in db_result[1]:
                thumbnail_name = os.path.splitext(filename)[0] + ".jpg"
                thumbnail_path = os.path.join(thumb_directory, thumbnail_name)
                generate_thumbnail(full_path, thumbnail_path)
    
    # Close the database connection
    connection.close()
if __name__ == "__main__":
    main()