新增繁简可选输出功能
This commit is contained in:
@@ -7,6 +7,7 @@ import shutil
|
|||||||
import typing
|
import typing
|
||||||
import urllib3
|
import urllib3
|
||||||
import signal
|
import signal
|
||||||
|
import opencc
|
||||||
|
|
||||||
import config
|
import config
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
@@ -377,7 +378,7 @@ def rm_empty_folder(path):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def create_data_and_move(file_path: str, zero_op):
|
def create_data_and_move(file_path: str, zero_op, oCC):
|
||||||
# Normalized number, eg: 111xxx-222.mp4 -> xxx-222.mp4
|
# Normalized number, eg: 111xxx-222.mp4 -> xxx-222.mp4
|
||||||
debug = config.getInstance().debug()
|
debug = config.getInstance().debug()
|
||||||
n_number = get_number(debug, os.path.basename(file_path))
|
n_number = get_number(debug, os.path.basename(file_path))
|
||||||
@@ -388,7 +389,7 @@ def create_data_and_move(file_path: str, zero_op):
|
|||||||
if zero_op:
|
if zero_op:
|
||||||
return
|
return
|
||||||
if n_number:
|
if n_number:
|
||||||
core_main(file_path, n_number)
|
core_main(file_path, n_number, oCC)
|
||||||
else:
|
else:
|
||||||
print("[-] number empty ERROR")
|
print("[-] number empty ERROR")
|
||||||
moveFailedFolder(file_path)
|
moveFailedFolder(file_path)
|
||||||
@@ -413,13 +414,13 @@ def create_data_and_move(file_path: str, zero_op):
|
|||||||
print('[!]', err)
|
print('[!]', err)
|
||||||
|
|
||||||
|
|
||||||
def create_data_and_move_with_custom_number(file_path: str, custom_number):
|
def create_data_and_move_with_custom_number(file_path: str, custom_number, oCC):
|
||||||
conf = config.getInstance()
|
conf = config.getInstance()
|
||||||
file_name = os.path.basename(file_path)
|
file_name = os.path.basename(file_path)
|
||||||
try:
|
try:
|
||||||
print("[!] [{1}] As Number making data for '{0}'".format(file_path, custom_number))
|
print("[!] [{1}] As Number making data for '{0}'".format(file_path, custom_number))
|
||||||
if custom_number:
|
if custom_number:
|
||||||
core_main(file_path, custom_number)
|
core_main(file_path, custom_number, oCC)
|
||||||
else:
|
else:
|
||||||
print("[-] number empty ERROR")
|
print("[-] number empty ERROR")
|
||||||
print("[*]======================================================")
|
print("[*]======================================================")
|
||||||
@@ -488,12 +489,16 @@ def main():
|
|||||||
|
|
||||||
create_failed_folder(conf.failed_folder())
|
create_failed_folder(conf.failed_folder())
|
||||||
|
|
||||||
|
# create OpenCC converter
|
||||||
|
ccm = conf.cc_convert_mode()
|
||||||
|
oCC = None if ccm == 0 else opencc.OpenCC('t2s.json' if ccm == 1 else 's2t.json')
|
||||||
|
|
||||||
if not single_file_path == '': #Single File
|
if not single_file_path == '': #Single File
|
||||||
print('[+]==================== Single File =====================')
|
print('[+]==================== Single File =====================')
|
||||||
if custom_number == '':
|
if custom_number == '':
|
||||||
create_data_and_move_with_custom_number(single_file_path, get_number(conf.debug(), os.path.basename(single_file_path)))
|
create_data_and_move_with_custom_number(single_file_path, get_number(conf.debug(), os.path.basename(single_file_path)), oCC)
|
||||||
else:
|
else:
|
||||||
create_data_and_move_with_custom_number(single_file_path, custom_number)
|
create_data_and_move_with_custom_number(single_file_path, custom_number, oCC)
|
||||||
else:
|
else:
|
||||||
folder_path = conf.source_folder()
|
folder_path = conf.source_folder()
|
||||||
if not isinstance(folder_path, str) or folder_path == '':
|
if not isinstance(folder_path, str) or folder_path == '':
|
||||||
@@ -515,7 +520,7 @@ def main():
|
|||||||
count = count + 1
|
count = count + 1
|
||||||
percentage = str(count / int(count_all) * 100)[:4] + '%'
|
percentage = str(count / int(count_all) * 100)[:4] + '%'
|
||||||
print('[!] {:>30}{:>21}'.format('- ' + percentage + ' [' + str(count) + '/' + count_all + '] -', time.strftime("%H:%M:%S")))
|
print('[!] {:>30}{:>21}'.format('- ' + percentage + ' [' + str(count) + '/' + count_all + '] -', time.strftime("%H:%M:%S")))
|
||||||
create_data_and_move(movie_path, zero_op)
|
create_data_and_move(movie_path, zero_op, oCC)
|
||||||
if count >= stop_count:
|
if count >= stop_count:
|
||||||
print("[!]Stop counter triggered!")
|
print("[!]Stop counter triggered!")
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ def get_data_state(data: dict) -> bool: # 元数据获取失败检测
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_data_from_json(file_number): # 从JSON返回元数据
|
def get_data_from_json(file_number, oCC): # 从JSON返回元数据
|
||||||
"""
|
"""
|
||||||
iterate through all services and fetch the data
|
iterate through all services and fetch the data
|
||||||
"""
|
"""
|
||||||
@@ -290,6 +290,20 @@ def get_data_from_json(file_number): # 从JSON返回元数据
|
|||||||
if len(t):
|
if len(t):
|
||||||
json_data[translate_value] = special_characters_replacement(t)
|
json_data[translate_value] = special_characters_replacement(t)
|
||||||
|
|
||||||
|
if oCC:
|
||||||
|
cc_vars = conf.cc_convert_vars().split(",")
|
||||||
|
for cc in cc_vars:
|
||||||
|
if cc == "actor":
|
||||||
|
json_data['actor_list'] = [oCC.convert(aa) for aa in json_data['actor_list']]
|
||||||
|
json_data['actor'] = oCC.convert(json_data['actor'])
|
||||||
|
elif cc == "tag":
|
||||||
|
json_data[cc] = [oCC.convert(t) for t in json_data[cc]]
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
json_data[cc] = oCC.convert(json_data[cc])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
naming_rule=""
|
naming_rule=""
|
||||||
for i in conf.naming_rule().split("+"):
|
for i in conf.naming_rule().split("+"):
|
||||||
if i not in json_data:
|
if i not in json_data:
|
||||||
|
|||||||
@@ -104,3 +104,8 @@ uncensored_site=3:58avgo
|
|||||||
run_mode=1
|
run_mode=1
|
||||||
; show_result剧情简介调试信息 0关闭 1简略 2详细(详细部分不记入日志),剧情简介失效时可打开2查看原因
|
; show_result剧情简介调试信息 0关闭 1简略 2详细(详细部分不记入日志),剧情简介失效时可打开2查看原因
|
||||||
show_result=0
|
show_result=0
|
||||||
|
|
||||||
|
; 繁简转换 繁简转换模式mode=0:不转换 1:繁转简 2:简转繁
|
||||||
|
[cc_convert]
|
||||||
|
mode=1
|
||||||
|
vars=actor,director,label,outline,series,studio,tag,title
|
||||||
|
|||||||
19
config.py
19
config.py
@@ -284,6 +284,19 @@ class Config:
|
|||||||
except:
|
except:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
def cc_convert_mode(self) -> int:
|
||||||
|
try:
|
||||||
|
v = self.conf.getint("cc_convert", "mode")
|
||||||
|
return v if v in (0,1,2) else 2 if v > 2 else 0
|
||||||
|
except:
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def cc_convert_vars(self) -> str:
|
||||||
|
try:
|
||||||
|
return self.conf.get("cc_convert", "vars")
|
||||||
|
except:
|
||||||
|
return "actor,director,label,outline,series,studio,tag,title"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _exit(sec: str) -> None:
|
def _exit(sec: str) -> None:
|
||||||
print("[-] Read config error! Please check the {} section in config.ini", sec)
|
print("[-] Read config error! Please check the {} section in config.ini", sec)
|
||||||
@@ -386,6 +399,12 @@ class Config:
|
|||||||
conf.set(sec14, "uncensored_site", "3:58avgo")
|
conf.set(sec14, "uncensored_site", "3:58avgo")
|
||||||
conf.set(sec14, "show_result", 0)
|
conf.set(sec14, "show_result", 0)
|
||||||
conf.set(sec14, "run_mode", 1)
|
conf.set(sec14, "run_mode", 1)
|
||||||
|
conf.set(sec14, "cc_convert", 1)
|
||||||
|
|
||||||
|
sec15 = "cc_convert"
|
||||||
|
conf.add_section(sec15)
|
||||||
|
conf.set(sec15, "mode", 1)
|
||||||
|
conf.set(sec15, "vars", "actor,director,label,outline,series,studio,tag,title")
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
|
|||||||
4
core.py
4
core.py
@@ -574,7 +574,7 @@ def debug_print(data: json):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def core_main(file_path, number_th):
|
def core_main(file_path, number_th, oCC):
|
||||||
conf = config.getInstance()
|
conf = config.getInstance()
|
||||||
# =======================================================================初始化所需变量
|
# =======================================================================初始化所需变量
|
||||||
multi_part = 0
|
multi_part = 0
|
||||||
@@ -589,7 +589,7 @@ def core_main(file_path, number_th):
|
|||||||
# 下面被注释的变量不需要
|
# 下面被注释的变量不需要
|
||||||
#rootpath= os.getcwd
|
#rootpath= os.getcwd
|
||||||
number = number_th
|
number = number_th
|
||||||
json_data = get_data_from_json(number) # 定义番号
|
json_data = get_data_from_json(number, oCC) # 定义番号
|
||||||
|
|
||||||
# Return if blank dict returned (data not found)
|
# Return if blank dict returned (data not found)
|
||||||
if not json_data:
|
if not json_data:
|
||||||
|
|||||||
@@ -8,3 +8,4 @@ pysocks==1.7.1
|
|||||||
urllib3==1.24.3
|
urllib3==1.24.3
|
||||||
certifi==2020.12.5
|
certifi==2020.12.5
|
||||||
MechanicalSoup==1.1.0
|
MechanicalSoup==1.1.0
|
||||||
|
opencc==1.1.1
|
||||||
|
|||||||
Reference in New Issue
Block a user