This commit is contained in:
2025-05-11 18:58:43 +02:00
parent d5a73f342e
commit f3f3045ebf
48 changed files with 686 additions and 243 deletions

View File

@@ -3,25 +3,28 @@ from pathlib import Path
import shutil
from PIL import Image
from data.path_constant import ANDROID_ASSETS, DOWNLOAD_DIR, NETWORK_DIR
from data.special_list import BOMTOON
class WebtoonConverter:
def __init__(self, webtoon_path: Path):
self.webtoon_path = webtoon_path
self.webtoon_path_network = NETWORK_DIR / webtoon_path.name
self.thumbnail = ''
self.img_extensions = {'.png', '.jpg', '.jpeg', '.webp'}
def do_convert(self):
def do_convert(self):
if self.webtoon_path.is_dir() and self.has_new_episode():
print(self.webtoon_path)
self.copy_information()
self.copy_information()
for item_path in self.webtoon_path.iterdir():
if item_path.is_dir():
episode_path = item_path
if self.is_new_episode(episode_path):
if self.is_new_episode(episode_path) and self.is_not_empty(episode_path):
print(f"new episode: {episode_path}")
self.delete_over_width_image(episode_path)
if self.webtoon_path.name not in BOMTOON:
self.delete_over_width_image(episode_path)
self.concat_images(episode_path)
elif item_path.suffix.lower() in self.img_extensions:
elif item_path.name == self.thumbnail:
thumbnail_path = item_path
self.copy_thumbnail(thumbnail_path)
@@ -46,13 +49,15 @@ class WebtoonConverter:
local_information = json.load(json_file)
with open(info_path_network, "r", encoding='utf-8') as json_file:
network_information = json.load(json_file)
self.thumbnail = local_information["thumbnail"]
if (
local_information["title"] == network_information["title"] and
local_information["author"] == network_information["author"] and
local_information["tag"] == network_information["tag"] and
local_information["description"] == network_information["description"] and
local_information["thumbnail_name"] == network_information["thumbnail_name"]
local_information["thumbnail"] == network_information["thumbnail"]
):
copy_necessary = False
@@ -104,7 +109,7 @@ class WebtoonConverter:
"author": existing_information["author"],
"tag": tag,
"description": existing_information["description"],
"thumbnail_name": existing_information["thumbnail_name"]
"thumbnail": existing_information["thumbnail"]
}
with open(path, 'w', encoding='utf-8') as json_file:
@@ -121,15 +126,23 @@ class WebtoonConverter:
print(f"Source file '{thumbnail_path}' not found.")
def delete_over_width_image(self, episode_path: Path):
if self.webtoon_path.name != "地下城見聞錄[UO]":
for img_path in episode_path.iterdir():
if self._is_image_800(img_path):
img_path.unlink()
print(f"delete {img_path}")
def delete_bomtoon_000(self, episode_path: Path):
for img_path in episode_path.iterdir():
if self._is_image_800(img_path):
if img_path.name == "000.webp":
img_path.unlink()
print(f"delete {img_path}")
def _is_image_800(self, image_path: Path) -> bool:
try:
with Image.open(image_path) as img:
return img.width >= 800
return img.width >= 800 and img.width < 1080
except Exception as e:
print(f"Error opening image {image_path}: {e}")
return False
@@ -137,6 +150,9 @@ class WebtoonConverter:
def is_new_episode(self, episode_path: Path) -> bool:
episode_path_network = self.webtoon_path_network / episode_path.name
return not episode_path_network.exists()
def is_not_empty(self, episode_path: Path) -> bool:
return any(episode_path.iterdir())
def concat_images(self, episode_path: Path):
@@ -153,7 +169,7 @@ class WebtoonConverter:
with open(img_path, 'rb') as img_file:
img = Image.open(img_file)
img.load()
if total_height + img.height > 28800:
if total_height + img.height > 20000:
self.save_concatenated_image(result_images, episode_path_network, result_index)
result_index += 1
result_images = []