-
Notifications
You must be signed in to change notification settings - Fork 3
/
AudioVideoAutoMerge.py
59 lines (47 loc) · 1.43 KB
/
AudioVideoAutoMerge.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
from platform import subprocess
import os
##############################################
################### CONFIG ###################
# Identifier are substrings without which name of video file is same as name of audio file. It doesn't matter if there extensions are different.
# Example
# [WebM 480p] Some Video Series Ep 1.webm
# [WebM Audio] Some Video Series Ep 1.webm
video_identifier = '[WebM 480p]'
audio_identifier = '[WebM Audio]'
# The extension of the merged file
output_ext = 'mkv'
#############################################
#############################################
path = input('Path to the folder :\n> ')
dic = {}
for i in os.listdir(path):
ti = i[0:i.rfind('.')] # remove extension
reduced = ''
if ti.find(video_identifier) != -1:
reduced = ti.replace(video_identifier, '')
if ti.find(audio_identifier) != -1:
reduced = ti.replace(audio_identifier, '')
if reduced == '': # if different file
continue
if not reduced in dic:
dic[reduced] = []
dic[reduced].append(i)
# got the pairs, now merge them
for i in dic:
if len(dic[i]) == 2:
subprocess.call([
'ffmpeg',
'-i', dic[i][0],
'-i', dic[i][1],
'-c:v', 'copy',
'-c:a', 'copy',
i.strip() + '.' + output_ext
], cwd=path)
# done
# now delete source files
confirm = input('Delete source files (y/n) ?\n> ').lower()
if confirm == 'y':
for i in dic:
if len(dic[i]) == 2:
os.remove(path + '/' + dic[i][0])
os.remove(path + '/' + dic[i][1])