Skip to content

Commit 02c0119

Browse files
committed
兼容samba路径格式 fix #31
1 parent 00a1737 commit 02c0119

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

EpisodeReName.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def resource_path(relative_path):
7777
# logger.info(sys.argv)
7878
# print(sys.argv)
7979

80+
# # 测试
81+
# if not getattr(sys, 'frozen', False) and len(sys.argv) == 1:
82+
# # 直接运行的目标路径
83+
# # sys.argv.append(r'\\DSM\DSM_share5\season1\aaa E02 AAA.mp4')
84+
# sys.argv.append(r'\\DSM\DSM_share5\season1')
85+
8086
if len(sys.argv) > 1 and not sys.argv[1].startswith('-'):
8187
# 旧版的命令解析
8288
# 简单通过判断是否有 - 来区分新旧参数
@@ -135,12 +141,10 @@ def resource_path(relative_path):
135141
if not target_path:
136142
# 没有路径参数直接退出
137143
sys.exit()
138-
# 1 / 0
139-
# 直接运行的目标路径
140-
target_path = r'E:\test\极端试验样本'
141-
target_path = r'E:\test\极端试验样本\S1'
142144

143-
target_path = target_path.replace('\\', '/').replace('//', '/')
145+
# 除samba格式的路径外 其它格式的路径斜杠统一处理
146+
if not target_path.startswith(r'\\'):
147+
target_path = target_path.replace('\\', '/').replace('//', '/')
144148

145149
# 忽略字符串, 用于处理剧集名字中带数字的文件, 提取信息时忽略这些字符串
146150
# ignore 文件必须用utf-8编码
@@ -287,10 +291,22 @@ def get_season(parent_folder_name):
287291

288292
def format_path(file_path):
289293
# 修正路径斜杠
290-
if system == 'Windows':
291-
return file_path.replace('//', '/').replace('/', '\\')
292-
return file_path.replace('\\', '/').replace('//', '/')
293294

295+
# samba路径特殊处理
296+
if file_path.startswith('//'):
297+
return '\\' + file_path.replace('//', '/').replace('/', '\\')
298+
else:
299+
if system == 'Windows':
300+
return file_path.replace('//', '/').replace('/', '\\')
301+
return file_path.replace('\\', '/').replace('//', '/')
302+
303+
def get_absolute_path(file_path):
304+
# 获取绝对路径
305+
if file_path.startswith(r'\\'):
306+
# samba 路径特殊处理
307+
return file_path.replace('\\', '/')
308+
else:
309+
return os.path.abspath(target_path.replace('\\', '/'))
294310

295311
def get_season_cascaded(full_path):
296312
# 逐级向上解析目录季数
@@ -713,8 +729,7 @@ def clean_name(s):
713729
continue
714730

715731
# 完整文件路径
716-
file_path = os.path.join(root, name).replace('\\', '/')
717-
file_path = os.path.abspath(file_path)
732+
file_path = get_absolute_path(os.path.join(root, name))
718733
parent_folder_path = os.path.dirname(file_path)
719734
season, ep = get_season_and_ep(file_path)
720735
resolution = get_resolution_in_name(name)
@@ -747,7 +762,7 @@ def clean_name(s):
747762
else:
748763
logger.info(f"{'单文件处理'}")
749764
logger.info(f'{target_path}')
750-
file_path = os.path.abspath(target_path.replace('\\', '/'))
765+
file_path = get_absolute_path(target_path)
751766
file_name, ext = get_file_name_ext(target_path)
752767
parent_folder_path = os.path.dirname(file_path)
753768
if ext.lower() in COMPOUND_EXTS:

0 commit comments

Comments
 (0)