Skip to content

Commit

Permalink
添加无码和字幕的水印
Browse files Browse the repository at this point in the history
  • Loading branch information
todoXu committed Dec 19, 2023
1 parent 7e5042b commit 7c587d5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
44 changes: 43 additions & 1 deletion JavSP.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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'):
"""包装各种海报裁剪方法,提供统一的调用"""
Expand Down Expand Up @@ -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)
Expand Down
Binary file added image/SUB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/UNCENSORED.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion make/windows.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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=[],
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ tqdm==4.59.0
urllib3==1.25.11
pywin32==303
pywin32-ctypes==0.2.0
Pillow==10.1

0 comments on commit 7c587d5

Please sign in to comment.