This commit is contained in:
Hell13Cat
2026-06-02 00:44:02 +03:00
parent 4a88e4c491
commit 4cddd19c76
3 changed files with 38 additions and 4 deletions
+2 -1
View File
@@ -2,7 +2,8 @@
"server":{
"host":"127.0.2.1",
"port":80,
"count_page":25
"count_page":25,
"thumb_size":250
},
"gb":{
"id":"",
+4 -1
View File
@@ -1,8 +1,9 @@
from system_module import db, gelbooru, logger
from system_module import db, gelbooru, logger, image_processor
from flask import Flask, render_template, jsonify, send_from_directory, render_template_string, request
import json
import requests
from pathlib import Path
import subprocess
import traceback
import os
@@ -36,6 +37,8 @@ def find_file(filename, file_folders):
return folder_path
return None
if not image_processor.check_ffmpeg(): print("WARNING!\n\nУ вас не установлен ffmpeg. Генерация превью для видео не доступна!")
@app.route("/")
def index():
return render_template("index.html")
+32 -2
View File
@@ -1,4 +1,34 @@
import PIL
import subprocess
from PIL import Image
import os
def generate_thumb():
EXTENSIONS_IMG = ('.jpg', '.jpeg', '.png', '.gif', '.webp', '.bmp')
EXTENSIONS_VID = ('.mp4', '.webm')
VALID_EXTENSIONS = EXTENSIONS_IMG + EXTENSIONS_VID
def check_ffmpeg():
try:
if os.name == 'nt': creationflags = subprocess.CREATE_NO_WINDOW
else: creationflags = 0
subprocess.run(["ffmpeg", "-version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, creationflags=creationflags)
return True
except (FileNotFoundError, subprocess.CalledProcessError):
return False
def generate_video_thumbnail(input_path_file, output_path_file, TARGET_MIN_SIZE):
vf_scale = f"scale='if(gt(iw,ih),-1,{TARGET_MIN_SIZE})':'if(gt(iw,ih),{TARGET_MIN_SIZE},-1)'"
cmd = ["ffmpeg", "-y", "-i", input_path_file, "-ss", "00:00:00", "-vframes", "1", "-vf", vf_scale, "-q:v", "2", output_path_file]
if os.name == 'nt': creationflags = subprocess.CREATE_NO_WINDOW
else: creationflags = 0
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=creationflags)
if result.returncode != 0:
raise Exception(f"FFmpeg error: {result.stderr.decode('utf-8', errors='ignore')}")
def video_gen():
pass
def image_and_gif_gen():
pass
def generate_thumb(source_image, thumb_folder, TARGET_MIN_SIZE):
pass