Skip to content

Commit

Permalink
Revert "Fix #73: 添加无码和字幕的水印" since it introduces runtime error:
Browse files Browse the repository at this point in the history
`local variable 'mark_pic_path' referenced before assignment`

This reverts commit eaedc84.
  • Loading branch information
Yuukiy committed Dec 26, 2023
1 parent e33e73a commit bfeb877
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 49 deletions.
44 changes: 1 addition & 43 deletions 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 @@ -370,44 +370,6 @@ 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 @@ -487,10 +449,6 @@ 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 removed image/SUB.png
Binary file not shown.
Binary file removed image/UNCENSORED.png
Binary file not shown.
6 changes: 1 addition & 5 deletions make/windows.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ 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 @@ -27,9 +25,7 @@ a = Analysis(['../JavSP.py'],
(cloudscraper_json, 'cloudscraper/user_agent'),
("../core/config.ini", "."),
("../data/*.*", "data"),
(ico_file, "image"),
(sub_pic, "image"),
(uncensored_pic, "image")
(ico_file, "image")
],
hiddenimports=all_crawlers,
hookspath=[],
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ idna==2.10
lxml==4.9.1
packaging==20.9
pefile==2019.4.18
Pillow==10.1
Pillow==10.0.1
pretty-errors==1.2.19
pycryptodome==3.10.1
PySocks==1.7.1
Expand Down

2 comments on commit bfeb877

@jtlin1
Copy link

@jtlin1 jtlin1 commented on bfeb877 Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看不懂怎么用啊·····

@Yuukiy
Copy link
Owner Author

@Yuukiy Yuukiy commented on bfeb877 Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtlin1 这个版本会导致运行报错,暂时撤回修改了

Please sign in to comment.