Calling core.py asynchronously. Allow to specify input and output paths.
This commit is contained in:
parent
1086447369
commit
00db4741bc
@ -8,12 +8,16 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
from ADC_function import *
|
from ADC_function import *
|
||||||
import json
|
import json
|
||||||
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
version='0.11.6'
|
version='0.11.6'
|
||||||
os.chdir(os.getcwd())
|
os.chdir(os.getcwd())
|
||||||
|
|
||||||
|
input_dir='.' # 电影的读取与输出路径, 默认为当前路径
|
||||||
|
output_dir='.'
|
||||||
|
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
config.read(config_file, encoding='UTF-8')
|
config.read(config_file, encoding='UTF-8')
|
||||||
|
|
||||||
@ -29,36 +33,50 @@ def UpdateCheck():
|
|||||||
print('[*]=====================================')
|
print('[*]=====================================')
|
||||||
else:
|
else:
|
||||||
print('[+]Update Check disabled!')
|
print('[+]Update Check disabled!')
|
||||||
|
|
||||||
|
def set_directory(): # 设置读取与存放路径
|
||||||
|
global input_dir
|
||||||
|
global output_dir
|
||||||
|
# 配置项switch为1且定义了新的路径时, 更改默认存取路径
|
||||||
|
if config['directory_capture']['switch'] == '1':
|
||||||
|
custom_input = config['directory_capture']['input_directory']
|
||||||
|
custom_output = config['directory_capture']['output_directory']
|
||||||
|
if custom_input != '': # 自定义了输入路径
|
||||||
|
input_dir = format_path(custom_input)
|
||||||
|
# 若自定义了输入路径, 输出路径默认在输入路径下
|
||||||
|
output_dir = input_dir
|
||||||
|
output_dir = format_path(custom_output) if custom_output != '' else output_dir # 自定义了输出路径
|
||||||
|
CreatFolder(output_dir)
|
||||||
|
CreatFolder(input_dir)
|
||||||
|
print('[+]Working directory is "' + os.getcwd() + '".')
|
||||||
|
print('[+]Using "' + input_dir + '" as input directory.')
|
||||||
|
print('[+]Using "' + output_dir + '" as output directory.')
|
||||||
|
|
||||||
|
def format_path(path): # 使路径兼容Linux与MacOS
|
||||||
|
if path.find('\\'): # 是仅兼容Windows的路径格式
|
||||||
|
path_list=path.split('\\')
|
||||||
|
path='/'.join(path_list) # 转换为可移植的路径格式
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
def movie_lists():
|
def movie_lists():
|
||||||
if config['directory_capture']['switch'] == '0' or config['directory_capture']['switch'] == '':
|
a2 = glob.glob( input_dir + "/*.mp4")
|
||||||
a2 = glob.glob(r'./*.mp4') # 使用 '/' 可以同时兼容Linux
|
b2 = glob.glob( input_dir + "/*.avi")
|
||||||
b2 = glob.glob(r'./*.avi')
|
c2 = glob.glob( input_dir + "/*.rmvb")
|
||||||
c2 = glob.glob(r'./*.rmvb')
|
d2 = glob.glob( input_dir + "/*.wmv")
|
||||||
d2 = glob.glob(r'./*.wmv')
|
e2 = glob.glob( input_dir + "/*.mov")
|
||||||
e2 = glob.glob(r'./*.mov')
|
f2 = glob.glob( input_dir + "/*.mkv")
|
||||||
f2 = glob.glob(r'./*.mkv')
|
g2 = glob.glob( input_dir + "/*.flv")
|
||||||
g2 = glob.glob(r'./*.flv')
|
h2 = glob.glob( input_dir + "/*.ts")
|
||||||
h2 = glob.glob(r'./*.ts')
|
total = a2 + b2 + c2 + d2 + e2 + f2 + g2 + h2
|
||||||
total = a2 + b2 + c2 + d2 + e2 + f2 + g2 + h2
|
return total
|
||||||
return total
|
def CreatFolder(folder_path):
|
||||||
elif config['directory_capture']['switch'] == '1':
|
if not os.path.exists(folder_path): # 新建文件夹
|
||||||
directory = config['directory_capture']['directory']
|
|
||||||
a2 = glob.glob(r"./" + directory + "/*.mp4")
|
|
||||||
b2 = glob.glob(r"./" + directory + "/*.avi")
|
|
||||||
c2 = glob.glob(r"./" + directory + "/*.rmvb")
|
|
||||||
d2 = glob.glob(r"./" + directory + "/*.wmv")
|
|
||||||
e2 = glob.glob(r"./" + directory + "/*.mov")
|
|
||||||
f2 = glob.glob(r"./" + directory + "/*.mkv")
|
|
||||||
g2 = glob.glob(r"./" + directory + "/*.flv")
|
|
||||||
h2 = glob.glob(r"./" + directory + "/*.ts")
|
|
||||||
total = a2 + b2 + c2 + d2 + e2 + f2 + g2 + h2
|
|
||||||
return total
|
|
||||||
def CreatFailedFolder():
|
|
||||||
if not os.path.exists('failed/'): # 新建failed文件夹
|
|
||||||
try:
|
try:
|
||||||
os.makedirs('failed/')
|
print('[+]Creating ' + folder_path)
|
||||||
|
os.makedirs(folder_path)
|
||||||
except:
|
except:
|
||||||
print("[-]failed!can not be make folder 'failed'\n[-](Please run as Administrator)")
|
print("[-]failed!can not be make folder '"+folder_path+"'\n[-](Please run as Administrator)")
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
def lists_from_test(custom_nuber): #电影列表
|
def lists_from_test(custom_nuber): #电影列表
|
||||||
a=[]
|
a=[]
|
||||||
@ -112,40 +130,50 @@ def getNumber(filepath):
|
|||||||
print('[-]' + str(os.path.basename(filepath)) + ' Cannot catch the number :')
|
print('[-]' + str(os.path.basename(filepath)) + ' Cannot catch the number :')
|
||||||
print('[-]' + str(os.path.basename(filepath)) + ' :', e)
|
print('[-]' + str(os.path.basename(filepath)) + ' :', e)
|
||||||
print('[-]Move ' + os.path.basename(filepath) + ' to failed folder')
|
print('[-]Move ' + os.path.basename(filepath) + ' to failed folder')
|
||||||
|
shutil.move(filepath, output_dir + '/failed/')
|
||||||
shutil.move(filepath, str(os.getcwd()) + '/' + 'failed/')
|
|
||||||
except IOError as e2:
|
except IOError as e2:
|
||||||
print('[-]' + str(os.path.basename(filepath)) + ' Cannot catch the number :')
|
print('[-]' + str(os.path.basename(filepath)) + ' Cannot catch the number :')
|
||||||
print('[-]' + str(os.path.basename(filepath)) + ' :', e2)
|
print('[-]' + str(os.path.basename(filepath)) + ' :', e2)
|
||||||
print('[-]Move ' + os.path.basename(filepath) + ' to failed folder')
|
print('[-]Move ' + os.path.basename(filepath) + ' to failed folder')
|
||||||
shutil.move(filepath, str(os.getcwd()) + '/' + 'failed/')
|
shutil.move(filepath, output_dir + '/failed/')
|
||||||
|
|
||||||
def RunCore():
|
def RunCore(movie):
|
||||||
|
# 异步调用core.py, core.py作为子线程执行, 本程序继续执行.
|
||||||
if os.path.exists('core.py'):
|
if os.path.exists('core.py'):
|
||||||
os.popen(sys.executable + ' core.py' + ' "' + i + '" --number "'+getNumber(i)+'"') #从py文件启动(用于源码py)
|
cmd_arg=[sys.executable,'core.py',movie,'--number',getNumber(movie),'--output',output_dir] #从py文件启动(用于源码py)
|
||||||
elif os.path.exists('core.exe'):
|
elif os.path.exists('core.exe'):
|
||||||
os.popen('core.exe' + ' "' + i + '" --number "'+getNumber(i)+'"') #从exe启动(用于EXE版程序)
|
cmd_arg=['core.exe',movie,'--number',getNumber(movie),'--output',output_dir] #从exe启动(用于EXE版程序)
|
||||||
elif os.path.exists('core.py') and os.path.exists('core.exe'):
|
elif os.path.exists('core.py') and os.path.exists('core.exe'):
|
||||||
os.popen(sys.executable + ' core.py' + ' "' + i + '" --number "' + getNumber(i) + '"') #从py文件启动(用于源码py)
|
cmd_arg=[sys.executable,'core.py',movie,'--number',getNumber(movie),'--output',output_dir] #从py文件启动(用于源码py)
|
||||||
|
process=subprocess.Popen(cmd_arg)
|
||||||
|
return process
|
||||||
|
|
||||||
if __name__ =='__main__':
|
if __name__ =='__main__':
|
||||||
print('[*]===========AV Data Capture===========')
|
print('[*]===========AV Data Capture===========')
|
||||||
print('[*] Version '+version)
|
print('[*] Version '+version)
|
||||||
print('[*]=====================================')
|
print('[*]=====================================')
|
||||||
CreatFailedFolder()
|
|
||||||
UpdateCheck()
|
UpdateCheck()
|
||||||
os.chdir(os.getcwd())
|
os.chdir(os.getcwd())
|
||||||
|
set_directory()
|
||||||
|
CreatFolder(output_dir+'/failed')
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
count_all = str(len(movie_lists()))
|
movies = movie_lists()
|
||||||
for i in movie_lists(): #遍历电影列表 交给core处理
|
count_all = str(len(movies))
|
||||||
count = count + 1
|
print('[+]Find ' + str(len(movies)) + ' movies.')
|
||||||
percentage = str(count/int(count_all)*100)[:4]+'%'
|
process_list=[]
|
||||||
|
for movie in movies: #遍历电影列表 交给core处理
|
||||||
|
print("[!]Making Data for [" + movie + "], the number is [" + getNumber(movie) + "]")
|
||||||
|
process=RunCore(movie)
|
||||||
|
process_list.append(process)
|
||||||
|
print("[*]=====================================")
|
||||||
|
for i in range(len(movies)):
|
||||||
|
process_list[i].communicate()
|
||||||
|
percentage = str((i+1)/int(count_all)*100)[:4]+'%'
|
||||||
print('[!] - '+percentage+' ['+str(count)+'/'+count_all+'] -')
|
print('[!] - '+percentage+' ['+str(count)+'/'+count_all+'] -')
|
||||||
print("[!]Making Data for [" + i + "], the number is [" + getNumber(i) + "]")
|
print("[!]The [" + getNumber(movies[i]) + "] process is done.")
|
||||||
RunCore()
|
print("[*]=====================================")
|
||||||
print("[*]=====================================")
|
|
||||||
|
CEF(input_dir)
|
||||||
CEF('JAV_output')
|
|
||||||
print("[+]All finished!!!")
|
print("[+]All finished!!!")
|
||||||
input("[+][+]Press enter key exit, you can check the error messge before you exit.\n[+][+]按回车键结束,你可以在结束之前查看和错误信息。")
|
input("[+][+]Press enter key exit, you can check the error messge before you exit.\n[+][+]按回车键结束,你可以在结束之前查看和错误信息。")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[proxy]
|
[proxy]
|
||||||
proxy=127.0.0.1:1080
|
proxy=127.0.0.1:8001
|
||||||
timeout=10
|
timeout=10
|
||||||
retry=3
|
retry=3
|
||||||
|
|
||||||
@ -16,7 +16,8 @@ media_warehouse=emby
|
|||||||
#plex only test!
|
#plex only test!
|
||||||
|
|
||||||
[directory_capture]
|
[directory_capture]
|
||||||
switch=0
|
switch=1
|
||||||
directory=
|
input_directory=
|
||||||
|
output_directory=
|
||||||
|
|
||||||
#everyone switch:1=on, 0=off
|
#everyone switch:1=on, 0=off
|
||||||
|
17
core.py
17
core.py
@ -32,6 +32,7 @@ imagecut=''
|
|||||||
tag=[]
|
tag=[]
|
||||||
cn_sub=''
|
cn_sub=''
|
||||||
path=''
|
path=''
|
||||||
|
output_dir=''
|
||||||
houzhui=''
|
houzhui=''
|
||||||
website=''
|
website=''
|
||||||
json_data={}
|
json_data={}
|
||||||
@ -50,18 +51,19 @@ except:
|
|||||||
def moveFailedFolder():
|
def moveFailedFolder():
|
||||||
global filepath
|
global filepath
|
||||||
print('[-]Move to "failed"')
|
print('[-]Move to "failed"')
|
||||||
shutil.move(filepath, str(os.getcwd()) + '/' + 'failed/')
|
shutil.move(filepath, output_dir + '/failed/')
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
def argparse_get_file():
|
def argparse_get_file():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--number", help="Enter Number on here", default='')
|
|
||||||
parser.add_argument("file", help="Write the file path on here")
|
parser.add_argument("file", help="Write the file path on here")
|
||||||
|
parser.add_argument("--number", help="Enter Number on here", default='')
|
||||||
|
parser.add_argument("--output", help="Enter Output directory here", default='')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
return (args.file, args.number)
|
return (args.file, args.number, args.output)
|
||||||
def CreatFailedFolder():
|
def CreatFailedFolder():
|
||||||
if not os.path.exists('failed/'): # 新建failed文件夹
|
if not os.path.exists(output_dir+'/failed/'): # 新建failed文件夹
|
||||||
try:
|
try:
|
||||||
os.makedirs('failed/')
|
os.makedirs(output_dir+'/failed/')
|
||||||
except:
|
except:
|
||||||
print("[-]failed!can not be make folder 'failed'\n[-](Please run as Administrator)")
|
print("[-]failed!can not be make folder 'failed'\n[-](Please run as Administrator)")
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
@ -155,10 +157,10 @@ def creatFolder(): #创建文件夹
|
|||||||
global actor
|
global actor
|
||||||
global path
|
global path
|
||||||
if len(actor) > 240: #新建成功输出文件夹
|
if len(actor) > 240: #新建成功输出文件夹
|
||||||
path = location_rule.replace("'actor'","'超多人'",3).replace("actor","'超多人'",3) #path为影片+元数据所在目录
|
path = output_dir + '/' + location_rule.replace("'actor'","'超多人'",3).replace("actor","'超多人'",3) #path为影片+元数据所在目录
|
||||||
#print(path)
|
#print(path)
|
||||||
else:
|
else:
|
||||||
path = location_rule
|
path = output_dir + '/' + location_rule
|
||||||
#print(path)
|
#print(path)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
try:
|
try:
|
||||||
@ -408,6 +410,7 @@ if __name__ == '__main__':
|
|||||||
moveFailedFolder()
|
moveFailedFolder()
|
||||||
else:
|
else:
|
||||||
number = argparse_get_file()[1]
|
number = argparse_get_file()[1]
|
||||||
|
output_dir = argparse_get_file()[2]
|
||||||
CreatFailedFolder()
|
CreatFailedFolder()
|
||||||
getDataFromJSON(number) # 定义番号
|
getDataFromJSON(number) # 定义番号
|
||||||
creatFolder() # 创建文件夹
|
creatFolder() # 创建文件夹
|
||||||
|
Loading…
Reference in New Issue
Block a user