fix: wrong symlink created.

Using absolute path instead of relative path to reduce (potential) problems
This commit is contained in:
benjamin
2020-12-21 23:50:17 +08:00
parent d29ad47f7b
commit 8b6c40375c

35
core.py
View File

@@ -1,5 +1,6 @@
import json import json
import os.path import os.path
import pathlib
import re import re
import shutil import shutil
import platform import platform
@@ -422,21 +423,21 @@ def cutImage(imagecut, path, number, c_word):
def paste_file_to_folder(filepath, path, number, c_word, conf: config.Config): # 文件路径,番号,后缀,要移动至的位置 def paste_file_to_folder(filepath, path, number, c_word, conf: config.Config): # 文件路径,番号,后缀,要移动至的位置
houzhui = str(re.search('[.](iso|ISO|AVI|RMVB|WMV|MOV|MP4|MKV|FLV|TS|WEBM|avi|rmvb|wmv|mov|mp4|mkv|flv|ts|webm)$', filepath).group()) houzhui = str(re.search('[.](iso|ISO|AVI|RMVB|WMV|MOV|MP4|MKV|FLV|TS|WEBM|avi|rmvb|wmv|mov|mp4|mkv|flv|ts|webm)$', filepath).group())
file_parent_origin_path = str(pathlib.Path(filepath).parent)
try: try:
# 如果soft_link=1 使用软链接 # 如果soft_link=1 使用软链接
if conf.soft_link(): if conf.soft_link():
os.symlink(filepath, path + '/' + number + c_word + houzhui) os.symlink(filepath, path + '/' + number + c_word + houzhui)
else: else:
os.rename(filepath, path + '/' + number + c_word + houzhui) os.rename(filepath, path + '/' + number + c_word + houzhui)
if os.path.exists(os.getcwd() + '/' + number + c_word + '.srt'): # 字幕移动 if os.path.exists(file_parent_origin_path + '/' + number + c_word + '.srt'): # 字幕移动
os.rename(os.getcwd() + '/' + number + c_word + '.srt', path + '/' + number + c_word + '.srt') os.rename(file_parent_origin_path + '/' + number + c_word + '.srt', path + '/' + number + c_word + '.srt')
print('[+]Sub moved!') print('[+]Sub moved!')
elif os.path.exists(os.getcwd() + '/' + number + c_word + '.ssa'): elif os.path.exists(file_parent_origin_path + '/' + number + c_word + '.ssa'):
os.rename(os.getcwd() + '/' + number + c_word + '.ssa', path + '/' + number + c_word + '.ssa') os.rename(file_parent_origin_path + '/' + number + c_word + '.ssa', path + '/' + number + c_word + '.ssa')
print('[+]Sub moved!') print('[+]Sub moved!')
elif os.path.exists(os.getcwd() + '/' + number + c_word + '.sub'): elif os.path.exists(file_parent_origin_path + '/' + number + c_word + '.sub'):
os.rename(os.getcwd() + '/' + number + c_word + '.sub', path + '/' + number + c_word + '.sub') os.rename(file_parent_origin_path + '/' + number + c_word + '.sub', path + '/' + number + c_word + '.sub')
print('[+]Sub moved!') print('[+]Sub moved!')
except FileExistsError: except FileExistsError:
print('[-]File Exists! Please check your movie!') print('[-]File Exists! Please check your movie!')
@@ -451,20 +452,20 @@ def paste_file_to_folder_mode2(filepath, path, multi_part, number, part, c_word,
if multi_part == 1: if multi_part == 1:
number += part # 这时number会被附加上CD1后缀 number += part # 这时number会被附加上CD1后缀
houzhui = str(re.search('[.](AVI|RMVB|WMV|MOV|MP4|MKV|FLV|TS|WEBM|avi|rmvb|wmv|mov|mp4|mkv|flv|ts|webm|iso|ISO)$', filepath).group()) houzhui = str(re.search('[.](AVI|RMVB|WMV|MOV|MP4|MKV|FLV|TS|WEBM|avi|rmvb|wmv|mov|mp4|mkv|flv|ts|webm|iso|ISO)$', filepath).group())
file_parent_origin_path = str(pathlib.Path(filepath).parent)
try: try:
if conf.soft_link(): if conf.soft_link():
os.symlink(filepath, path + '/' + number + part + c_word + houzhui) os.symlink(filepath, path + '/' + number + part + c_word + houzhui)
else: else:
os.rename(filepath, path + '/' + number + part + c_word + houzhui) os.rename(filepath, path + '/' + number + part + c_word + houzhui)
if os.path.exists(number + '.srt'): # 字幕移动 if os.path.exists(file_parent_origin_path + '/' + number + '.srt'): # 字幕移动
os.rename(number + part + c_word + '.srt', path + '/' + number + part + c_word + '.srt') os.rename(file_parent_origin_path + '/' + number + part + c_word + '.srt', path + '/' + number + part + c_word + '.srt')
print('[+]Sub moved!') print('[+]Sub moved!')
elif os.path.exists(number + part + c_word + '.ass'): elif os.path.exists(file_parent_origin_path + '/' + number + part + c_word + '.ass'):
os.rename(number + part + c_word + '.ass', path + '/' + number + part + c_word + '.ass') os.rename(file_parent_origin_path + '/' + number + part + c_word + '.ass', path + '/' + number + part + c_word + '.ass')
print('[+]Sub moved!') print('[+]Sub moved!')
elif os.path.exists(number + part + c_word + '.sub'): elif os.path.exists(file_parent_origin_path + '/' + number + part + c_word + '.sub'):
os.rename(number + part + c_word + '.sub', path + '/' + number + part + c_word + '.sub') os.rename(file_parent_origin_path + '/' + number + part + c_word + '.sub', path + '/' + number + part + c_word + '.sub')
print('[+]Sub moved!') print('[+]Sub moved!')
print('[!]Success') print('[!]Success')
except FileExistsError: except FileExistsError:
@@ -511,7 +512,9 @@ def core_main(file_path, number_th, conf: config.Config):
cn_sub = '' cn_sub = ''
liuchu = '' liuchu = ''
filepath = file_path # 影片的路径
filepath = file_path # 影片的路径 绝对路径
rootpath = str(pathlib.Path(filepath).parent)
number = number_th number = number_th
json_data = get_data_from_json(number, filepath, conf) # 定义番号 json_data = get_data_from_json(number, filepath, conf) # 定义番号
@@ -543,7 +546,7 @@ def core_main(file_path, number_th, conf: config.Config):
debug_print(json_data) debug_print(json_data)
# 创建文件夹 # 创建文件夹
path = create_folder(conf.success_folder(), json_data.get('location_rule'), json_data, conf) path = create_folder(rootpath + '/' + conf.success_folder(), json_data.get('location_rule'), json_data, conf)
# main_mode # main_mode
# 1: 刮削模式 / Scraping mode # 1: 刮削模式 / Scraping mode