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