Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加用户选择多文件尾部命名方式 #163

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions JavSP.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,29 @@ def generate_names(movie: Movie):
ori_title_break = split_by_punc(d['rawtitle'])
copyd = d.copy()
copyd['num'] = copyd['num'] + movie.attr_str
longest_ext = max((os.path.splitext(i)[1] for i in movie.files), key=len)
for end in range(len(ori_title_break), 0, -1):
copyd['rawtitle'] = replace_illegal_chars(''.join(ori_title_break[:end]).strip())
for sub_end in range(len(title_break), 0, -1):
copyd['title'] = replace_illegal_chars(''.join(title_break[:sub_end]).strip())
save_dir = os.path.normpath(cfg.NamingRule.save_dir.substitute(copyd)).strip()
basename = os.path.normpath(cfg.NamingRule.filename.substitute(copyd).strip())
fanart_file = os.path.join(save_dir, f'{basename}{cdx}-fanart.jpg')
remaining = get_remaining_path_len(os.path.abspath(fanart_file))
if 'universal' in cfg.NamingRule.media_servers:
long_path = os.path.join(save_dir, basename+longest_ext)
else:
long_path = os.path.join(save_dir, f'{basename}{cdx}-fanart.jpg')
remaining = get_remaining_path_len(os.path.abspath(long_path))
if remaining > 0:
movie.save_dir = save_dir
movie.basename = basename
movie.nfo_file = os.path.join(save_dir, f'{basename}{cdx}.nfo')
movie.fanart_file = fanart_file
movie.poster_file = os.path.join(save_dir, f'{basename}{cdx}-poster.jpg')
if 'universal' in cfg.NamingRule.media_servers:
movie.nfo_file = os.path.join(save_dir, 'movie.nfo')
movie.fanart_file = os.path.join(save_dir, 'fanart.jpg')
movie.poster_file = os.path.join(save_dir, 'poster.jpg')
else:
movie.nfo_file = os.path.join(save_dir, f'{basename}{cdx}.nfo')
movie.fanart_file = os.path.join(save_dir, f'{basename}{cdx}-fanart.jpg')
movie.poster_file = os.path.join(save_dir, f'{basename}{cdx}-poster.jpg')
if d['title'] != copyd['title']:
logger.info(f"自动截短标题为:\n{copyd['title']}")
if d['rawtitle'] != copyd['rawtitle']:
Expand All @@ -308,9 +317,14 @@ def generate_names(movie: Movie):
save_dir = os.path.normpath(cfg.NamingRule.save_dir.substitute(copyd)).strip()
movie.save_dir = save_dir
movie.basename = os.path.normpath(cfg.NamingRule.filename.substitute(copyd)).strip()
movie.nfo_file = os.path.join(save_dir, f'{basename}{cdx}.nfo')
movie.fanart_file = os.path.join(save_dir, f'{basename}{cdx}-fanart.jpg')
movie.poster_file = os.path.join(save_dir, f'{basename}{cdx}-poster.jpg')
if 'universal' in cfg.NamingRule.media_servers:
movie.nfo_file = os.path.join(save_dir, 'movie.nfo')
movie.fanart_file = os.path.join(save_dir, 'fanart.jpg')
movie.poster_file = os.path.join(save_dir, 'poster.jpg')
else:
movie.nfo_file = os.path.join(save_dir, f'{basename}{cdx}.nfo')
movie.fanart_file = os.path.join(save_dir, f'{basename}{cdx}-fanart.jpg')
movie.poster_file = os.path.join(save_dir, f'{basename}{cdx}-poster.jpg')
if d['title'] != copyd['title']:
logger.info(f"自动截短标题为:\n{copyd['title']}")
if d['rawtitle'] != copyd['rawtitle']:
Expand Down Expand Up @@ -452,7 +466,7 @@ def check_step(result, msg='步骤错误'):

if 'video_station' in cfg.NamingRule.media_servers:
postStep_videostation(movie)
if len(movie.files) > 1:
if len(movie.files) > 1 and 'universal' not in cfg.NamingRule.media_servers:
postStep_MultiMoviePoster(movie)

inner_bar.set_description('写入NFO')
Expand Down
4 changes: 2 additions & 2 deletions core/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ javlib = https://www.a66j.com
# save_dir, nfo_title和filename中可以使用变量来引用影片的数据,支持的变量列表见下面的地址:
# https://github.com/Yuukiy/JavSP/wiki/NamingRule-%7C-%E5%91%BD%E5%90%8D%E8%A7%84%E5%88%99
[NamingRule]
# 设置媒体服务器类型
media_servers = jellyfin
# 设置媒体服务器类型 (universal/jellyfin/video_station, 默认universal: 按兼容性最高的方式命名封面和nfo)
media_servers = universal
# 整理后的影片和封面等文件的保存位置
output_folder = #整理完成
# 存放影片、封面等文件的文件夹路径
Expand Down
2 changes: 1 addition & 1 deletion core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def norm_ignore_pattern(cfg: Config):

def validate_media_servers(cfg: Config):
"""获取媒体服务器配置并验证有效性"""
supported = set(('plex', 'emby', 'jellyfin', 'kodi', 'video_station'))
supported = set(('universal', 'plex', 'emby', 'jellyfin', 'kodi', 'video_station'))
servers = cfg.NamingRule.media_servers.lower()
items = set(re.split(r'[^\w_]+', servers, flags=re.I))
cfg.NamingRule.media_servers = items & supported
Expand Down
Loading