forked from ThoughtfulDev/Anime4K
-
Notifications
You must be signed in to change notification settings - Fork 2
/
extract_audio.py
51 lines (48 loc) · 1.72 KB
/
extract_audio.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
from pymkv import MKVFile
from simple_term_menu import TerminalMenu
import subprocess, sys, os, glob, time
from utils import language_mapping, is_tool
def extract_audio(fn):
mkv = MKVFile(fn)
tracks = mkv.get_track()
for track in tracks:
if track.track_type == 'audio':
ext = track._track_codec
lang = language_mapping[track._language]
id = str(track._track_id)
subprocess.call(['mkvextract', 'tracks', fn, id + ':' + lang + '.' + ext])
flacs = []
for file in glob.glob("*.FLAC"):
flacs.append(file)
if len(flacs) > 0:
convert_menu = TerminalMenu(["Yes", "No"], title="Do you want to convert every FLAC to Opus?")
convert_choice = convert_menu.show()
if convert_choice == 0:
for f in flacs:
br_menu = TerminalMenu(["192K", "256K", "320K"], title="Whats the format of the file? => {0}".format(f))
br_choice = br_menu.show()
if br_choice == 0:
br = "192K"
elif br_choice == 1:
br = "256K"
elif br_choice == 2:
br = "320K"
else:
br = "192K"
fn_base = f.split(".")[0]
out_audio = fn_base + ".Opus"
subprocess.call([
"ffmpeg",
"-hide_banner",
"-i",
f,
"-c:a",
"libopus",
"-b:a",
br,
"-vbr",
"on",
out_audio
])
time.sleep(1)
os.remove(f)