This commit is contained in:
Hell13Cat
2026-06-02 01:17:25 +03:00
parent 800c9cb651
commit 7b86090b75
4 changed files with 14 additions and 11 deletions
+3 -1
View File
@@ -84,7 +84,9 @@ def dw_api():
for chunk in r.iter_content(chunk_size=8192): for chunk in r.iter_content(chunk_size=8192):
f.write(chunk) f.write(chunk)
database.add_raw(data_get) database.add_raw(data_get)
image_processor.generate_thumb(FILE_DW_FOLDERS+"/"+file_name, THUMB_FOLDER, TARGET_MIN_SIZE) res_data = image_processor.generate_thumb(FILE_DW_FOLDERS+"/"+file_name, THUMB_FOLDER, TARGET_MIN_SIZE)
if not res_data["status"]:
print(res_data["message"])
return jsonify({'status': 'success'}) return jsonify({'status': 'success'})
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
error_message = f"Network error {image_id}: {e}" error_message = f"Network error {image_id}: {e}"
+6 -1
View File
@@ -29,7 +29,12 @@ class GB:
return response.json()["post"][0], url_file, file_name return response.json()["post"][0], url_file, file_name
def get_from_md5(self, md5): def get_from_md5(self, md5):
pass params = {"page": "dapi", "s": "post", "q": "index", "json": 1, "tags":"md5:"+md5, "api_key":self.api_hash, "user_id":self.api_id}
response = requests.get(self.root_url, params=params, headers=self.HEADERS, timeout=15)
print(response.url)
url_file = response.json()["post"][0]["file_url"]
file_name = response.json()["post"][0]["image"]
return response.json()["post"][0], url_file, file_name
def get_binary_file(self, id_post): def get_binary_file(self, id_post):
pass pass
+3 -9
View File
@@ -2,8 +2,8 @@ import subprocess
from PIL import Image from PIL import Image
import os import os
EXTENSIONS_IMG = ('.jpg', '.jpeg', '.png', '.gif', '.webp', '.bmp') EXTENSIONS_IMG = ('jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp')
EXTENSIONS_VID = ('.mp4', '.webm') EXTENSIONS_VID = ('mp4', 'webm')
VALID_EXTENSIONS = EXTENSIONS_IMG + EXTENSIONS_VID VALID_EXTENSIONS = EXTENSIONS_IMG + EXTENSIONS_VID
def check_ffmpeg(): def check_ffmpeg():
@@ -27,15 +27,10 @@ def video_gen(input_path_file, output_path_file, TARGET_MIN_SIZE):
def image_and_gif_gen(input_path_file, output_path_file, TARGET_MIN_SIZE): def image_and_gif_gen(input_path_file, output_path_file, TARGET_MIN_SIZE):
with Image.open(input_path_file) as img: with Image.open(input_path_file) as img:
img_rgba = img.convert("RGBA") img_rgba = img.convert("RGBA")
background = Image.new("RGB", img_rgba.size, (255, 255, 255)) background = Image.new("RGB", img_rgba.size, (255, 255, 255))
background.paste(img_rgba, mask=img_rgba) background.paste(img_rgba, mask=img_rgba)
final_img = background final_img = background
width, height = final_img.size width, height = final_img.size
if width <= TARGET_MIN_SIZE and height <= TARGET_MIN_SIZE: if width <= TARGET_MIN_SIZE and height <= TARGET_MIN_SIZE:
final_img.save(output_path_file, "JPEG", quality=90) final_img.save(output_path_file, "JPEG", quality=90)
else: else:
@@ -45,7 +40,6 @@ def image_and_gif_gen(input_path_file, output_path_file, TARGET_MIN_SIZE):
else: else:
new_height = TARGET_MIN_SIZE new_height = TARGET_MIN_SIZE
new_width = int(TARGET_MIN_SIZE * (width / height)) new_width = int(TARGET_MIN_SIZE * (width / height))
resized_img = final_img.resize((new_width, new_height), Image.Resampling.LANCZOS) resized_img = final_img.resize((new_width, new_height), Image.Resampling.LANCZOS)
resized_img.save(output_path_file, "JPEG", quality=85) resized_img.save(output_path_file, "JPEG", quality=85)
@@ -53,7 +47,7 @@ def generate_thumb(input_path_file, THUMB_FOLDER, TARGET_MIN_SIZE):
ext_file = input_path_file.split(".")[-1] ext_file = input_path_file.split(".")[-1]
if ext_file not in VALID_EXTENSIONS: if ext_file not in VALID_EXTENSIONS:
return {"status":False, "message":"Расширение не поддерживаеться!"} return {"status":False, "message":"Расширение не поддерживаеться!"}
thumb_filename = f"{input_path_file.split(".")[-2]}.jpg" thumb_filename = f"{os.path.basename(input_path_file).split(".")[-2]}.jpg"
output_path_file = os.path.join(THUMB_FOLDER, thumb_filename) output_path_file = os.path.join(THUMB_FOLDER, thumb_filename)
if ext_file in EXTENSIONS_IMG: if ext_file in EXTENSIONS_IMG:
image_and_gif_gen(input_path_file, output_path_file, TARGET_MIN_SIZE) image_and_gif_gen(input_path_file, output_path_file, TARGET_MIN_SIZE)
+2
View File
@@ -63,7 +63,9 @@
<header> <header>
<a href="/" class="logo">LocalBooru</a> <a href="/" class="logo">LocalBooru</a>
<!--
<a class="analytics" href="/analytics">📊 Analytics</a> <a class="analytics" href="/analytics">📊 Analytics</a>
-->
<div class="search-wrapper"> <div class="search-wrapper">
<input type="text" id="searchInput" placeholder="Search tags..."> <input type="text" id="searchInput" placeholder="Search tags...">
<ul id="autocompleteList" class="autocomplete-list"></ul> <ul id="autocompleteList" class="autocomplete-list"></ul>