-
Notifications
You must be signed in to change notification settings - Fork 0
/
dts2flac.py
73 lines (58 loc) · 1.56 KB
/
dts2flac.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
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
import argparse
import subprocess
import os
from pathlib import Path
import unicodedata
INSTALL_DIR = Path(__file__).parent.absolute()
PROCESS_DIR = os.getcwd()
parser = argparse.ArgumentParser()
parser.add_argument(
dest="POSITIONAL_INPUT_PATH", nargs="?", help="the path to the input file"
)
parser.add_argument(
"-i", "--input", dest="INPUT_PATH", help="the path to the input file"
)
parser.add_argument(
"-o",
"--output",
dest="OUTPUT_PATH",
default="output"
if str(INSTALL_DIR) == PROCESS_DIR or INSTALL_DIR.as_posix() == PROCESS_DIR
else ".",
help="the path to the output folder",
)
args = parser.parse_args()
INPUT_PATH = args.POSITIONAL_INPUT_PATH or args.INPUT_PATH
OUTPUT_PATH = (
args.OUTPUT_PATH
if os.path.isabs(args.OUTPUT_PATH)
else os.path.join(PROCESS_DIR, args.OUTPUT_PATH)
)
def strip_accents(text):
text = unicodedata.normalize("NFKD", text)
text = text.encode("ascii", "ignore")
text = text.decode("utf-8")
return str(text)
def convert():
subprocess.run(
[
"ffmpeg",
"-i",
INPUT_PATH,
"-c:a",
"flac",
# "-ar",
# "48000",
f"{FILE_NAME}.flac",
]
)
def main():
global BASE_PATH, FILE_EXTENSION
BASE_PATH = os.path.basename(INPUT_PATH)
FILE_EXTENSION = os.path.splitext(BASE_PATH)[1]
global FILE_NAME, INPUT_DIR, FILE_PATH
FILE_NAME = strip_accents(BASE_PATH.removesuffix(FILE_EXTENSION))
convert()
if __name__ == "__main__":
main()