Merge pull request #380 from ddtyjmyjm/ben_dev

fix some bugs on softlink mode
This commit is contained in:
Yoshiko2
2020-12-24 14:49:32 +08:00
committed by GitHub
2 changed files with 55 additions and 46 deletions

View File

@@ -5,8 +5,15 @@ import sys
from number_parser import get_number
from core import *
def check_update(local_version):
data = json.loads(get_html("https://api.github.com/repos/yoshiko2/AV_Data_Capture/releases/latest"))
try:
data = json.loads(get_html("https://api.github.com/repos/yoshiko2/AV_Data_Capture/releases/latest"))
except Exception as e:
print("[-] Failed to update! Please check new version manually:")
print("[-] https://github.com/yoshiko2/AV_Data_Capture/releases")
print("[*]======================================================")
return
remote = data["tag_name"]
local = local_version
@@ -23,19 +30,22 @@ def argparse_function(ver: str) -> [str, str, bool]:
parser = argparse.ArgumentParser()
parser.add_argument("file", default='', nargs='?', help="Single Movie file path.")
parser.add_argument("-c", "--config", default='config.ini', nargs='?', help="The config file Path.")
parser.add_argument("-n", "--number", default='', nargs='?',help="Custom file number")
parser.add_argument("-a", "--auto-exit", dest='autoexit', action="store_true", help="Auto exit after program complete")
parser.add_argument("-n", "--number", default='', nargs='?', help="Custom file number")
parser.add_argument("-a", "--auto-exit", dest='autoexit', action="store_true",
help="Auto exit after program complete")
parser.add_argument("-v", "--version", action="version", version=ver)
args = parser.parse_args()
return args.file, args.config, args.number, args.autoexit
def movie_lists(root, escape_folder):
for folder in escape_folder:
if folder in root:
return []
total = []
file_type = ['.mp4', '.avi', '.rmvb', '.wmv', '.mov', '.mkv', '.flv', '.ts', '.webm', '.MP4', '.AVI', '.RMVB', '.WMV','.MOV', '.MKV', '.FLV', '.TS', '.WEBM', '.iso','.ISO']
file_type = ['.mp4', '.avi', '.rmvb', '.wmv', '.mov', '.mkv', '.flv', '.ts', '.webm', '.MP4', '.AVI', '.RMVB',
'.WMV', '.MOV', '.MKV', '.FLV', '.TS', '.WEBM', '.iso', '.ISO']
dirs = os.listdir(root)
for entry in dirs:
f = os.path.join(root, entry)
@@ -55,19 +65,19 @@ def create_failed_folder(failed_folder):
sys.exit(0)
def CEF(path):
def rm_empty_folder(path):
try:
files = os.listdir(path) # 获取路径下的子文件(夹)列表
for file in files:
os.removedirs(path + '/' + file) # 删除这个空文件夹
os.rmdir(path + '/' + file) # 删除这个空文件夹
print('[+]Deleting empty folder', path + '/' + file)
except:
a = ''
def create_data_and_move(file_path: str, c: config.Config,debug):
def create_data_and_move(file_path: str, c: config.Config, debug):
# Normalized number, eg: 111xxx-222.mp4 -> xxx-222.mp4
n_number = get_number(debug,file_path)
n_number = get_number(debug, file_path)
if debug == True:
print("[!]Making Data for [{}], the number is [{}]".format(file_path, n_number))
@@ -98,6 +108,7 @@ def create_data_and_move(file_path: str, c: config.Config,debug):
except Exception as err:
print('[!]', err)
def create_data_and_move_with_custom_number(file_path: str, c: config.Config, custom_number=None):
try:
print("[!]Making Data for [{}], the number is [{}]".format(file_path, custom_number))
@@ -141,21 +152,21 @@ if __name__ == '__main__':
# ========== Single File ==========
if not single_file_path == '':
print('[+]==================== Single File =====================')
create_data_and_move_with_custom_number(single_file_path, conf,custom_number)
CEF(conf.success_folder())
CEF(conf.failed_folder())
create_data_and_move_with_custom_number(single_file_path, conf, custom_number)
rm_empty_folder(conf.success_folder())
rm_empty_folder(conf.failed_folder())
print("[+]All finished!!!")
input("[+][+]Press enter key exit, you can check the error messge before you exit.")
sys.exit(0)
# ========== Single File ==========
movie_list = movie_lists(".", re.split("[,]", conf.escape_folder()))
movie_list = movie_lists(os.getcwd(), re.split("[,]", conf.escape_folder()))
count = 0
count_all = str(len(movie_list))
print('[+]Find', count_all, 'movies')
if conf.debug() == True:
print('[+]'+' DEBUG MODE ON '.center(54, '-'))
print('[+]' + ' DEBUG MODE ON '.center(54, '-'))
if conf.soft_link():
print('[!] --- Soft link mode is ENABLE! ----')
for movie_path in movie_list: # 遍历电影列表 交给core处理
@@ -164,8 +175,8 @@ if __name__ == '__main__':
print('[!] - ' + percentage + ' [' + str(count) + '/' + count_all + '] -')
create_data_and_move(movie_path, conf, conf.debug())
CEF(conf.success_folder())
CEF(conf.failed_folder())
rm_empty_folder(conf.success_folder())
rm_empty_folder(conf.failed_folder())
print("[+]All finished!!!")
if conf.auto_exit():
sys.exit(0)

58
core.py
View File

@@ -1,5 +1,6 @@
import json
import os.path
import pathlib
import re
import shutil
import platform
@@ -30,20 +31,18 @@ def escape_path(path, escape_literals: str): # Remove escape literals
def moveFailedFolder(filepath, failed_folder):
if config.Config().failed_move():
print('[-]Move to Failed output folder')
shutil.move(filepath, str(os.getcwd()) + '/' + failed_folder + '/')
root_path = str(pathlib.Path(filepath).parent)
file_name = pathlib.Path(filepath).name
destination_path = root_path + '/' + failed_folder + '/'
if config.Config.soft_link():
print('[-]Create symlink to Failed output folder')
os.symlink(filepath, destination_path + '/' + file_name)
else:
print('[-]Move to Failed output folder')
shutil.move(filepath, destination_path)
return
def CreatFailedFolder(failed_folder):
if not os.path.exists(failed_folder + '/'): # 新建failed文件夹
try:
os.makedirs(failed_folder + '/')
except:
print("[-]failed!can not be make Failed output folder\n[-](Please run as Administrator)")
return
def get_data_from_json(file_number, filepath, conf: config.Config): # 从JSON返回元数据
"""
iterate through all services and fetch the data
@@ -432,21 +431,21 @@ def cutImage(imagecut, path, number, c_word):
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())
file_parent_origin_path = str(pathlib.Path(filepath).parent)
try:
# 如果soft_link=1 使用软链接
if conf.soft_link():
os.symlink(filepath, path + '/' + number + c_word + houzhui)
else:
os.rename(filepath, path + '/' + number + c_word + houzhui)
if os.path.exists(os.getcwd() + '/' + number + c_word + '.srt'): # 字幕移动
os.rename(os.getcwd() + '/' + number + c_word + '.srt', path + '/' + number + c_word + '.srt')
if os.path.exists(file_parent_origin_path + '/' + number + c_word + '.srt'): # 字幕移动
os.rename(file_parent_origin_path + '/' + number + c_word + '.srt', path + '/' + number + c_word + '.srt')
print('[+]Sub moved!')
elif os.path.exists(os.getcwd() + '/' + number + c_word + '.ssa'):
os.rename(os.getcwd() + '/' + number + c_word + '.ssa', path + '/' + number + c_word + '.ssa')
elif os.path.exists(file_parent_origin_path + '/' + number + c_word + '.ssa'):
os.rename(file_parent_origin_path + '/' + number + c_word + '.ssa', path + '/' + number + c_word + '.ssa')
print('[+]Sub moved!')
elif os.path.exists(os.getcwd() + '/' + number + c_word + '.sub'):
os.rename(os.getcwd() + '/' + number + c_word + '.sub', path + '/' + number + c_word + '.sub')
elif os.path.exists(file_parent_origin_path + '/' + number + c_word + '.sub'):
os.rename(file_parent_origin_path + '/' + number + c_word + '.sub', path + '/' + number + c_word + '.sub')
print('[+]Sub moved!')
except FileExistsError:
print('[-]File Exists! Please check your movie!')
@@ -461,20 +460,20 @@ def paste_file_to_folder_mode2(filepath, path, multi_part, number, part, c_word,
if multi_part == 1:
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())
file_parent_origin_path = str(pathlib.Path(filepath).parent)
try:
if conf.soft_link():
os.symlink(filepath, path + '/' + number + part + c_word + houzhui)
else:
os.rename(filepath, path + '/' + number + part + c_word + houzhui)
if os.path.exists(number + '.srt'): # 字幕移动
os.rename(number + part + c_word + '.srt', path + '/' + number + part + c_word + '.srt')
if os.path.exists(file_parent_origin_path + '/' + number + '.srt'): # 字幕移动
os.rename(file_parent_origin_path + '/' + number + part + c_word + '.srt', path + '/' + number + part + c_word + '.srt')
print('[+]Sub moved!')
elif os.path.exists(number + part + c_word + '.ass'):
os.rename(number + part + c_word + '.ass', path + '/' + number + part + c_word + '.ass')
elif os.path.exists(file_parent_origin_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!')
elif os.path.exists(number + part + c_word + '.sub'):
os.rename(number + part + c_word + '.sub', path + '/' + number + part + c_word + '.sub')
elif os.path.exists(file_parent_origin_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('[!]Success')
except FileExistsError:
@@ -521,7 +520,9 @@ def core_main(file_path, number_th, conf: config.Config):
cn_sub = ''
liuchu = ''
filepath = file_path # 影片的路径
filepath = file_path # 影片的路径 绝对路径
rootpath = str(pathlib.Path(filepath).parent)
number = number_th
json_data = get_data_from_json(number, filepath, conf) # 定义番号
@@ -548,15 +549,12 @@ def core_main(file_path, number_th, conf: config.Config):
if '流出' in filepath:
liuchu = '流出'
# 创建输出失败目录
CreatFailedFolder(conf.failed_folder())
# 调试模式检测
if conf.debug():
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
# 1: 刮削模式 / Scraping mode