bitwarden

This commit is contained in:
jaydee
2024-09-24 22:27:29 +02:00
parent 90aed99cf5
commit 2c9f970883

View File

@@ -41,7 +41,7 @@ for o, a in opts:
elif o in ("-d", "--device"): elif o in ("-d", "--device"):
_DEV = True _DEV = True
elif o in ("-p", "--part"): elif o in ("-p", "--part"):
_DAY_DIR = a _DAY_DIRS = a.split(",")
elif o in ("-f", "--flip"): elif o in ("-f", "--flip"):
_FLIP = True _FLIP = True
elif o in ("-r", "--source"): elif o in ("-r", "--source"):
@@ -62,138 +62,144 @@ for o, a in opts:
#_SOURCE_DIR = "/media/nas/nas-photo/imported/" #_SOURCE_DIR = "/media/nas/nas-photo/imported/"
if ops == "win":
_FULL_PATH = _SOURCE_DIR + "\\" + _DEV + "\\" + _DAY_DIR + "\\"
else:
_FULL_PATH = _SOURCE_DIR + "/" + _DEV + "/" + _DAY_DIR + "/"
#print(_FULL_PATH) #print(_FULL_PATH)
if _ACTION == "join": if _ACTION == "join":
video_seq = {} for _DAY_DIR in _DAY_DIRS:
if ops == "win":
_FULL_PATH = _SOURCE_DIR + "\\" + _DEV + "\\" + _DAY_DIR + "\\"
else:
_FULL_PATH = _SOURCE_DIR + "/" + _DEV + "/" + _DAY_DIR + "/"
video_seq = {}
if os.path.exists(_FULL_PATH): if os.path.exists(_FULL_PATH):
if os.path.exists(_FULL_PATH + "100GOPRO"): if os.path.exists(_FULL_PATH + "100GOPRO"):
_FULL_PATH = _FULL_PATH + "100GOPRO" _FULL_PATH = _FULL_PATH + "100GOPRO"
for filename in os.listdir(_FULL_PATH): for filename in os.listdir(_FULL_PATH):
if filename.endswith(".MP4") and not filename.startswith("joined_"): if filename.endswith(".MP4") and not filename.startswith("joined_"):
prefix = filename[0:2] prefix = filename[0:2]
part = prefix + filename[2:4] part = prefix + filename[2:4]
seq = filename[4:8] seq = filename[4:8]
if not seq in video_seq: if not seq in video_seq:
video_seq[seq] = [] video_seq[seq] = []
video_seq[seq].append(part + seq + ".MP4") video_seq[seq].append(part + seq + ".MP4")
# print(filename) # print(filename)
# print(seq) # print(seq)
# print(part) # print(part)
# print(json.dumps(video_seq,indent=2)) # print(json.dumps(video_seq,indent=2))
_PROCESSED = _FULL_PATH + "processed" _PROCESSED = _FULL_PATH + "processed"
if not os.path.exists(_PROCESSED): if not os.path.exists(_PROCESSED):
os.mkdir(_PROCESSED) os.mkdir(_PROCESSED)
# print(f"SEQUENCES : {_SEQUENCES}") # print(f"SEQUENCES : {_SEQUENCES}")
os.chdir(_FULL_PATH) os.chdir(_FULL_PATH)
for vid in video_seq: for vid in video_seq:
if len(_SEQUENCES) != 0 and vid not in _SEQUENCES: if len(_SEQUENCES) != 0 and vid not in _SEQUENCES:
continue continue
export_name = "joined_" + vid + ".MP4" export_name = "joined_" + vid + ".MP4"
parts = video_seq[vid] parts = video_seq[vid]
parts.sort() parts.sort()
# print(parts) # print(parts)
if len(parts) == 1: if len(parts) == 1:
shutil.move(parts[0], export_name) shutil.move(parts[0], export_name)
continue continue
# print(type(parts)) # print(type(parts))
#ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4 #ffmpeg -i concat:"input1.mp4|input2.mp4" output.mp4
f = open("video.txt", "w") f = open("video.txt", "w")
f.write("# Files to join\n") f.write("# Files to join\n")
f.close() f.close()
f = open("video.txt", "a") f = open("video.txt", "a")
final_size = 0 final_size = 0
for p in parts:
f.write(f"file '{p}'\n")
file_stats = os.stat(p)
final_size += file_stats.st_size
f.close()
#print(final_size)
#print(_FULL_PATH)
if _TEST:
input(" ???? ")
# print(os.getcwd())
#status, output = subprocess.getstatusoutput(myCmd)
if _FLIP:
if ops == "win":
myCmd = [
"ffmpeg", "-display_rotation", "180", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name
]
else:
myCmd = [
"/opt/ffmpeg/ffmpeg", "-display_rotation", "180", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name
]
else:
if ops == "win":
myCmd = [
"ffmpeg", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name
]
else:
myCmd = [
"/opt/ffmpeg/ffmpeg", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name
]
#print(myCmd)
print(f"Joining {len(parts)} files...")
proc = subprocess.Popen(myCmd,stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT)
# with tqdm(total=100, position=1, desc="Convert") as pbar:
# for progress in ff.run_command_with_progress():
# pbar.update(progress - pbar.n)
with tqdm(total=100, position=1, desc="Join") as pbar:
position=0
while proc.returncode is None:
#pbar.update()
try:
file_stats = os.stat(export_name)
cur_size = file_stats.st_size
final_size
cur_stat = (cur_size / final_size) * 100
pbar.update(int(cur_stat) - position)
position = int(cur_stat)
proc.call()
except:
pass
time.sleep(3)
pbar.update(1)
# get the output
status = 0
if status == 0:
print("Moving...")
for p in parts: for p in parts:
try: f.write(f"file '{p}'\n")
shutil.move(p, _PROCESSED) file_stats = os.stat(p)
except: final_size += file_stats.st_size
print(f"Failed to move {p}") f.close()
try: #print(final_size)
shutil.move(p.replace("MP4", "THM"), _PROCESSED) #print(_FULL_PATH)
except:
print(f"Failed to move {p.replace("MP4", "THM")}") if _TEST:
input(" ???? ")
# print(os.getcwd())
#status, output = subprocess.getstatusoutput(myCmd)
if _FLIP:
if ops == "win":
myCmd = [
"ffmpeg", "-display_rotation", "180", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name
]
else:
myCmd = [
"/opt/ffmpeg/ffmpeg", "-display_rotation", "180", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name
]
else:
if ops == "win":
myCmd = [
"ffmpeg", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name
]
else:
myCmd = [
"/opt/ffmpeg/ffmpeg", "-f", "concat", "-i", "video.txt ","-vcodec", "copy", "-acodec", "copy", export_name
]
#print(myCmd)
print(f"Joining {len(parts)} files...")
proc = subprocess.Popen(myCmd,stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT)
# with tqdm(total=100, position=1, desc="Convert") as pbar:
# for progress in ff.run_command_with_progress():
# pbar.update(progress - pbar.n)
with tqdm(total=100, position=1, desc="Join") as pbar:
position=0
while proc.returncode is None:
try: #pbar.update()
shutil.move(p.replace("MP4", "LRV").replace("GH","GL"), _PROCESSED) try:
except: file_stats = os.stat(export_name)
print(f"Failed to move {p.replace("MP4", "LRV")}") cur_size = file_stats.st_size
os.remove("video.txt") final_size
cur_stat = (cur_size / final_size) * 100
pbar.update(int(cur_stat) - position)
position = int(cur_stat)
proc.call()
except:
pass
time.sleep(3)
pbar.update(1)
# get the output
status = 0
if status == 0:
print("Moving...")
for p in parts:
try:
shutil.move(p, _PROCESSED)
except:
print(f"Failed to move {p}")
try:
shutil.move(p.replace("MP4", "THM"), _PROCESSED)
except:
print(f"Failed to move {p.replace("MP4", "THM")}")
try:
shutil.move(p.replace("MP4", "LRV").replace("GH","GL"), _PROCESSED)
except:
print(f"Failed to move {p.replace("MP4", "LRV")}")
os.remove("video.txt")
if _ACTION == "encode": if _ACTION == "encode":
if ops == "win":
_FULL_PATH = _SOURCE_DIR + "\\" + _DEV + "\\" + _DAY_DIR + "\\"
else:
_FULL_PATH = _SOURCE_DIR + "/" + _DEV + "/" + _DAY_DIR + "/"
if os.path.exists(_FULL_PATH): if os.path.exists(_FULL_PATH):
if os.path.exists(_FULL_PATH + "100GOPRO"): if os.path.exists(_FULL_PATH + "100GOPRO"):
_FULL_PATH = _FULL_PATH + "100GOPRO" _FULL_PATH = _FULL_PATH + "100GOPRO"