diff --git a/JavSP.py b/JavSP.py index 350a4984b..ae58e3a41 100644 --- a/JavSP.py +++ b/JavSP.py @@ -12,7 +12,7 @@ import pretty_errors from colorama import Fore, Style from tqdm import tqdm - +from PIL import Image pretty_errors.configure(display_link=True) @@ -364,6 +364,44 @@ def reviewMovieID(all_movies, root): logger.info(f"已更正影片番号: {','.join(relpaths)}: {id} -> {new_id}") print() +#1:字幕 2:无码 +def add_to_pic(poster_file, mark): + if mark == 1: + pngpath = "image/SUB.png" + elif mark == 2: + pngpath = "image/UNCENSORED.png" + + if hasattr(sys, '_MEIPASS') and os.path.isfile(os.path.join(getattr(sys, '_MEIPASS'), pngpath)): + mark_pic_path = os.path.join(getattr(sys, '_MEIPASS'), pngpath) + elif os.path.isfile(os.path.join(os.path.dirname(os.path.realpath(__file__)), pngpath)): + mark_pic_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), pngpath) + + poster_img_pic = Image.open(poster_file) + mark_img_subt = Image.open(mark_pic_path) + + scroll_high = int(poster_img_pic.height / 9) + scroll_wide = int(scroll_high * mark_img_subt.width / mark_img_subt.height) + mark_img_subt = mark_img_subt.resize((scroll_wide, scroll_high), Image.LANCZOS) + #r, g, b, a = mark_img_subt.split() # 获取颜色通道,保持png的透明性 + + #水印放到左上 右上 右下 左下位置 + pos = [ + {'x': 0, 'y': 0}, + {'x': poster_img_pic.width - scroll_wide, 'y': 0}, + {'x': poster_img_pic.width - scroll_wide, 'y': poster_img_pic.height - scroll_high}, + {'x': 0, 'y': poster_img_pic.height - scroll_high}, + ] + if mark == 1: + poster_img_pic.paste(mark_img_subt, (pos[2]['x'], pos[2]['y'])) + if mark == 2: + poster_img_pic.paste(mark_img_subt, (pos[3]['x'], pos[3]['y'])) + poster_img_pic.save(poster_file, quality=95) + +def add_poster_mark(poster_file, hard_sub, uncensored): + if hard_sub: + add_to_pic(poster_file, 1) + if uncensored: + add_to_pic(poster_file, 2) def crop_poster_wrapper(fanart_file, poster_file, method='normal'): """包装各种海报裁剪方法,提供统一的调用""" @@ -443,6 +481,10 @@ def check_step(result, msg='步骤错误'): method = 'normal' crop_poster_wrapper(movie.fanart_file, movie.poster_file, method) check_step(True) + + # 添加水印 + if movie.hard_sub or movie.uncensored: + add_poster_mark(movie.poster_file, movie.hard_sub, movie.uncensored) if 'video_station' in cfg.NamingRule.media_servers: postStep_videostation(movie) diff --git a/image/SUB.png b/image/SUB.png new file mode 100644 index 000000000..10a8092ff Binary files /dev/null and b/image/SUB.png differ diff --git a/image/UNCENSORED.png b/image/UNCENSORED.png new file mode 100644 index 000000000..7b15564ac Binary files /dev/null and b/image/UNCENSORED.png differ diff --git a/make/windows.spec b/make/windows.spec index c316c2eb9..580e4dbb1 100644 --- a/make/windows.spec +++ b/make/windows.spec @@ -16,6 +16,8 @@ for file in os.listdir('web'): # workaround for a bug of PyInstaller since 5.0: https://github.com/pyinstaller/pyinstaller/issues/6759 ico_file = os.path.abspath(os.path.join(SPECPATH, "../image/JavSP.ico")) +sub_pic = os.path.abspath(os.path.join(SPECPATH, "../image/SUB.png")) +uncensored_pic = os.path.abspath(os.path.join(SPECPATH, "../image/UNCENSORED.png")) # pyinstaller locates path relative to the .spec file a = Analysis(['../JavSP.py'], @@ -25,7 +27,9 @@ a = Analysis(['../JavSP.py'], (cloudscraper_json, 'cloudscraper/user_agent'), ("../core/config.ini", "."), ("../data/*.*", "data"), - (ico_file, "image") + (ico_file, "image"), + (sub_pic, "image"), + (uncensored_pic, "image") ], hiddenimports=all_crawlers, hookspath=[], diff --git a/requirements.txt b/requirements.txt index 2e9ff0460..561cd11b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,3 +18,4 @@ tqdm==4.59.0 urllib3==1.25.11 pywin32==303 pywin32-ctypes==0.2.0 +Pillow==10.1 \ No newline at end of file