-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster_positive.py
More file actions
134 lines (113 loc) · 3.35 KB
/
Copy pathmaster_positive.py
File metadata and controls
134 lines (113 loc) · 3.35 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""
master
watch MKV file, then upload to ftp server
need curl, alternative ftp or rsync
"""
import os
import json
import hashlib
from icecream import ic
from loguru import logger
SRC = None
DIST = None
CURL_cmd = None
FILE_list = []
CONFIG_list = []
def load():
global SRC
global DIST
global CURL_cmd
global CONFIG_list
data = None
with open("info.json", 'r', encoding='utf-8') as f:
data = json.load(f)
SRC = data["src"]
DIST = data["dist"]
CURL_cmd = data["curlCmd"]
CONFIG_list = data["infoArr"]
def launch():
global SRC
global FILE_list
global CONFIG_list
ls_list = os.listdir(SRC)
for filename in ls_list:
if "." not in filename:
continue
(basename, extname) = filename.rsplit('.',1) # basename.mkv in the end
if extname == "mkv":
FILE_list.append(filename)
ic(FILE_list)
for item in FILE_list:
# default
filename = item
alias = ""
param = "-c:v copy -c:a copy"
for index_item in CONFIG_list:
if item == index_item["file"]:
filename = index_item["file"]
alias = index_item["alias"]
param = index_item["param"]
(basename, extname)= filename.rsplit('.',1)
filefullname = basename + "." + extname
if alias != "":
filefullname = basename + " " + alias + "." + extname
filepath = SRC + "\\" + filename
outputpath = DIST + "\\" + filefullname
hashpath = outputpath + ".md5"
filesafe = " \"" + filepath + "\" "
outputsafe = " \"" + outputpath + "\" "
ffmpeg_cmd = "ffmpeg -i" + filesafe + param + outputsafe
# msg("CMD ➜ " + ffmpeg_cmd)
lumos(ffmpeg_cmd)
createhash(outputpath)
filesync(outputpath)
filesync(hashpath)
def createhash(filepath):
hashhex = None
filesize = os.path.getsize(filepath)
if filesize > 10*1024*1024*1024:
hashhex = "infinite"
else:
with open(filepath, 'rb') as f:
data = f.read()
hasher = hashlib.md5()
hasher.update(data)
hashhex = hasher.hexdigest()
hashpath = filepath + ".md5"
with open(hashpath, 'w', encoding='utf-8') as f:
f.write(hashhex)
def lumos(cmd):
# print(cmd)
# res = 0
pre = "\n🧪 "
logger.debug(pre + cmd)
res = os.system(cmd)
return res
def filesync(filepath):
upload_cmd = CURL_cmd + "\"" + filepath + "\""
# for windows, curl need download
# if os.path.exists('curl.exe'):
# windows_curl = ".\\curl ftp://192.168.3.200/ftp/input/ -u \"anonymous:\" -T "
# upload_cmd = windows_curl + "\"" + filepath + "\""
ic(upload_cmd) # debug
res = os.system(upload_cmd)
return res
def precheck():
global FILE_list
global SRC
for item in FILE_list:
filename = item["file"]
filepath = SRC + "\\" + filename
if not os.path.exists(filepath):
raise Exception("Missing " + filepath)
print("==== Precheck is OK ====")
if __name__ == '__main__':
load()
# precheck()
print("Source PATH: \t" + SRC)
print("Output PATH: \t" + DIST)
print("Info FTP: \t" + CURL_cmd)
# ic("Source PATH: \t" + SRC)
# ic("Output PATH: \t" + DIST)
# ic("Info FTP: \t" + CURL_cmd)
launch()