新增繁简可选输出功能
This commit is contained in:
@@ -7,6 +7,7 @@ import shutil
|
||||
import typing
|
||||
import urllib3
|
||||
import signal
|
||||
import opencc
|
||||
|
||||
import config
|
||||
from datetime import datetime, timedelta
|
||||
@@ -377,7 +378,7 @@ def rm_empty_folder(path):
|
||||
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
|
||||
debug = config.getInstance().debug()
|
||||
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:
|
||||
return
|
||||
if n_number:
|
||||
core_main(file_path, n_number)
|
||||
core_main(file_path, n_number, oCC)
|
||||
else:
|
||||
print("[-] number empty ERROR")
|
||||
moveFailedFolder(file_path)
|
||||
@@ -413,13 +414,13 @@ def create_data_and_move(file_path: str, zero_op):
|
||||
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()
|
||||
file_name = os.path.basename(file_path)
|
||||
try:
|
||||
print("[!] [{1}] As Number making data for '{0}'".format(file_path, custom_number))
|
||||
if custom_number:
|
||||
core_main(file_path, custom_number)
|
||||
core_main(file_path, custom_number, oCC)
|
||||
else:
|
||||
print("[-] number empty ERROR")
|
||||
print("[*]======================================================")
|
||||
@@ -488,12 +489,16 @@ def main():
|
||||
|
||||
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
|
||||
print('[+]==================== Single File =====================')
|
||||
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:
|
||||
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:
|
||||
folder_path = conf.source_folder()
|
||||
if not isinstance(folder_path, str) or folder_path == '':
|
||||
@@ -515,7 +520,7 @@ def main():
|
||||
count = count + 1
|
||||
percentage = str(count / int(count_all) * 100)[:4] + '%'
|
||||
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:
|
||||
print("[!]Stop counter triggered!")
|
||||
break
|
||||
|
||||
@@ -32,7 +32,7 @@ def get_data_state(data: dict) -> bool: # 元数据获取失败检测
|
||||
|
||||
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
|
||||
"""
|
||||
@@ -290,6 +290,20 @@ def get_data_from_json(file_number): # 从JSON返回元数据
|
||||
if len(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=""
|
||||
for i in conf.naming_rule().split("+"):
|
||||
if i not in json_data:
|
||||
|
||||
@@ -104,3 +104,8 @@ uncensored_site=3:58avgo
|
||||
run_mode=1
|
||||
; show_result剧情简介调试信息 0关闭 1简略 2详细(详细部分不记入日志),剧情简介失效时可打开2查看原因
|
||||
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:
|
||||
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
|
||||
def _exit(sec: str) -> None:
|
||||
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, "show_result", 0)
|
||||
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
|
||||
|
||||
|
||||
4
core.py
4
core.py
@@ -574,7 +574,7 @@ def debug_print(data: json):
|
||||
pass
|
||||
|
||||
|
||||
def core_main(file_path, number_th):
|
||||
def core_main(file_path, number_th, oCC):
|
||||
conf = config.getInstance()
|
||||
# =======================================================================初始化所需变量
|
||||
multi_part = 0
|
||||
@@ -589,7 +589,7 @@ def core_main(file_path, number_th):
|
||||
# 下面被注释的变量不需要
|
||||
#rootpath= os.getcwd
|
||||
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)
|
||||
if not json_data:
|
||||
|
||||
@@ -8,3 +8,4 @@ pysocks==1.7.1
|
||||
urllib3==1.24.3
|
||||
certifi==2020.12.5
|
||||
MechanicalSoup==1.1.0
|
||||
opencc==1.1.1
|
||||
|
||||
Reference in New Issue
Block a user