-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBatch_Command.py
64 lines (54 loc) · 2.31 KB
/
Batch_Command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import numpy as np
import pandas as pd
import re
import sys
# RE pattern
m4a_pattern = '.*.m4a'
mp4_pattern = '.*.mp4'
def create_file():
global command_line_file
command_line_file = open(os.path.join(os.path.curdir, 'command.sh'),'w+',encoding='utf8')
print('Finish creating the command file under current dir!')
command_line_file.write("#!/bin/bash \n")
def write_command():
# Open the excel file using pandas
excel_df = pd.read_excel(excel_path)
for filename in os.listdir(folder_path):
if re.search(mp4_pattern,filename):
# Deal with only m4a file to avoid repetition
filename_split = filename.split('_')
re_name = filename_split[0]+'_'+filename_split[1]
for index, row in excel_df.iterrows():
row_split = row['文件名'].split('_')
row_re_name = row_split[0]+'_'+row_split[1]
if row_re_name == re_name:
start_time = row['开始录制时间']
for find_mp4 in os.listdir(folder_path):
if re.search(row_re_name,find_mp4) and re.search(m4a_pattern,find_mp4):
out_put_file_name = row_re_name+'_人声'+'.wav'
command_string = './extra '+ os.path.join(ugc_m4a_path,filename)+' '+\
os.path.join(ugc_m4a_path,find_mp4)+' '+str(start_time) +' '+\
os.path.join(out_put_path,out_put_file_name)
command_line_file.write(command_string+'\n')
command_line_file.write('\n')
if __name__ == "__main__":
if len(sys.argv) < 3:
print('Please enter right arguements!')
excel_path = sys.argv[1]
folder_path = sys.argv[2]
ugc_m4a_path = folder_path
try:
os.mkdir(os.path.join(os.path.curdir,'Extract_Result'))
except OSError:
print ("Creation of the directory Extract_Result failed")
sys.exit()
else:
print ("Successfully created the directory Extract_Result")
out_put_path = os.path.join(os.path.curdir,'Extract_Result')
create_file()
write_command()
print('Finish writing the command line file!')
# Finish writing and close the file
command_line_file.close()
print('Finish closing the file!')