add ignore extension and force container
This commit is contained in:
parent
08248719a1
commit
5f268f6ad1
|
@ -53,6 +53,9 @@ transcode_parser.add_argument(
|
||||||
type=str,
|
type=str,
|
||||||
help='transcode level',
|
help='transcode level',
|
||||||
default="opus-96k")
|
default="opus-96k")
|
||||||
|
transcode_parser.add_argument(
|
||||||
|
'--ignore-extension',
|
||||||
|
action='store_true')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -71,4 +74,5 @@ elif args.subparser_name == "transcode":
|
||||||
args.src,
|
args.src,
|
||||||
args.dest,
|
args.dest,
|
||||||
args.transcode_level,
|
args.transcode_level,
|
||||||
|
args.ignore_extension
|
||||||
).run()
|
).run()
|
|
@ -4,10 +4,17 @@ from ..transcode_levels import transcode_levels
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
class TranscodeCommand:
|
class TranscodeCommand:
|
||||||
def __init__(self, src: str, dest: str, transcode_level: str):
|
def __init__(
|
||||||
|
self,
|
||||||
|
src: str,
|
||||||
|
dest: str,
|
||||||
|
transcode_level: str,
|
||||||
|
ignore_extension: bool,
|
||||||
|
):
|
||||||
self.src = src
|
self.src = src
|
||||||
self.dest = dest
|
self.dest = dest
|
||||||
self.transcode_level = transcode_level
|
self.transcode_level = transcode_level
|
||||||
|
self.ignore_extension = ignore_extension
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.transcode_level == "list":
|
if self.transcode_level == "list":
|
||||||
|
@ -21,12 +28,12 @@ class TranscodeCommand:
|
||||||
|
|
||||||
output_file = file_from_path(Path(self.dest), "")
|
output_file = file_from_path(Path(self.dest), "")
|
||||||
|
|
||||||
if trans_config.file_extension != output_file.extension:
|
if trans_config.file_extension != output_file.extension and not self.ignore_extension:
|
||||||
print(
|
print(
|
||||||
f"{output_file.extension} is not the recommended "+
|
f"{output_file.extension} is not the recommended "+
|
||||||
f"extension for transcode_level {self.transcode_level} "+
|
f"extension for transcode_level {self.transcode_level} "+
|
||||||
f"please change it to {trans_config.file_extension} "+
|
f"please change it to {trans_config.file_extension} "+
|
||||||
f"or TODO(add --ignore-extension)"
|
f"or run with --ignore-extension"
|
||||||
)
|
)
|
||||||
exit()
|
exit()
|
||||||
transcode(input_file, trans_config, self.transcode_level, self.dest)
|
transcode(input_file, trans_config, self.transcode_level, self.dest)
|
|
@ -3,9 +3,7 @@ def add_to_arr(arr: list[str], items: list[str]) -> list[str]:
|
||||||
arr.append(item)
|
arr.append(item)
|
||||||
|
|
||||||
# does not include copy
|
# does not include copy
|
||||||
transcode_levels = [
|
transcode_levels = []
|
||||||
"speex"
|
|
||||||
]
|
|
||||||
|
|
||||||
# mp3 v0 -> v9
|
# mp3 v0 -> v9
|
||||||
add_to_arr(transcode_levels, [
|
add_to_arr(transcode_levels, [
|
||||||
|
@ -26,6 +24,10 @@ add_to_arr(transcode_levels, [
|
||||||
f"vorbis-q{quality}" for quality in range(-2, 11)
|
f"vorbis-q{quality}" for quality in range(-2, 11)
|
||||||
])
|
])
|
||||||
|
|
||||||
|
add_to_arr(transcode_levels, [
|
||||||
|
f"speex-q{quality}" for quality in range(0, 11)
|
||||||
|
])
|
||||||
|
|
||||||
# Extra Default Mappings
|
# Extra Default Mappings
|
||||||
preset_transcode_levels = {
|
preset_transcode_levels = {
|
||||||
"mp3-low": "mp3-v4",
|
"mp3-low": "mp3-v4",
|
||||||
|
|
|
@ -9,6 +9,7 @@ class TranscodeConfig:
|
||||||
use_bitrate = False
|
use_bitrate = False
|
||||||
encoder = ""
|
encoder = ""
|
||||||
file_extension = ""
|
file_extension = ""
|
||||||
|
container = ""
|
||||||
bitrate = ""
|
bitrate = ""
|
||||||
quality = ""
|
quality = ""
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@ def get_transcode_config(file: File, level: str):
|
||||||
level = preset_transcode_levels["level"]
|
level = preset_transcode_levels["level"]
|
||||||
|
|
||||||
if level.startswith("opus-") and level.endswith("k"):
|
if level.startswith("opus-") and level.endswith("k"):
|
||||||
|
conf.container = "ogg"
|
||||||
conf.file_extension = "opus"
|
conf.file_extension = "opus"
|
||||||
conf.encoder = "libopus"
|
conf.encoder = "libopus"
|
||||||
conf.use_bitrate = True
|
conf.use_bitrate = True
|
||||||
|
@ -25,30 +27,34 @@ def get_transcode_config(file: File, level: str):
|
||||||
conf.bitrate = level.replace("opus-", "")
|
conf.bitrate = level.replace("opus-", "")
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
if level.startswith("mp3-v"):
|
if level.startswith("mp3-"):
|
||||||
|
conf.container = "mp3"
|
||||||
conf.file_extension = "mp3"
|
conf.file_extension = "mp3"
|
||||||
conf.encoder = "libmp3lame"
|
conf.encoder = "libmp3lame"
|
||||||
|
|
||||||
|
if level.startswith("mp3-v"):
|
||||||
conf.use_quality = True
|
conf.use_quality = True
|
||||||
conf.quality = level.replace("mp3-v", "")
|
conf.quality = level.replace("mp3-v", "")
|
||||||
return conf
|
return conf
|
||||||
elif level.startswith("mp3-") and level.endswith("k"):
|
elif level.startswith("mp3-") and level.endswith("k"):
|
||||||
conf.file_extension = "mp3"
|
|
||||||
conf.encoder = "libmp3lame"
|
|
||||||
conf.use_bitrate = True
|
conf.use_bitrate = True
|
||||||
# includes the k
|
|
||||||
conf.bitrate = level.replace("mp3-", "")
|
conf.bitrate = level.replace("mp3-", "")
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
if level.startswith("vorbis-q"):
|
if level.startswith("vorbis-q"):
|
||||||
|
conf.container = "ogg"
|
||||||
conf.file_extension = "ogg"
|
conf.file_extension = "ogg"
|
||||||
conf.encoder = "libvorbis"
|
conf.encoder = "libvorbis"
|
||||||
conf.use_quality = True
|
conf.use_quality = True
|
||||||
conf.quality = level.replace("vorbis-q", "")
|
conf.quality = level.replace("vorbis-q", "")
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
if level == "speex":
|
if level.startswith("speex-q"):
|
||||||
conf.encoder = "libspeex"
|
conf.container = "ogg"
|
||||||
conf.file_extension = "ogg"
|
conf.file_extension = "ogg"
|
||||||
|
conf.encoder = "libspeex"
|
||||||
|
conf.use_quality = True
|
||||||
|
conf.quality = level.replace("speex-q", "")
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
print("Unknown Level")
|
print("Unknown Level")
|
||||||
|
@ -66,9 +72,14 @@ def transcode(file: File, config: TranscodeConfig, level: str, dest: str):
|
||||||
"-i", file.join_path_to(),
|
"-i", file.join_path_to(),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if len(config.encoder) != 0:
|
||||||
ffmpeg_command.append("-c:a")
|
ffmpeg_command.append("-c:a")
|
||||||
ffmpeg_command.append(config.encoder)
|
ffmpeg_command.append(config.encoder)
|
||||||
|
|
||||||
|
if len(config.container) != 0:
|
||||||
|
ffmpeg_command.append("-f")
|
||||||
|
ffmpeg_command.append(config.container)
|
||||||
|
|
||||||
if config.use_quality:
|
if config.use_quality:
|
||||||
ffmpeg_command.append("-q:a")
|
ffmpeg_command.append("-q:a")
|
||||||
ffmpeg_command.append(config.quality)
|
ffmpeg_command.append(config.quality)
|
||||||
|
|
Loading…
Reference in a new issue