add ability to load custom encoder config from file
This commit is contained in:
parent
5f268f6ad1
commit
4d0c0496b8
|
@ -56,6 +56,10 @@ transcode_parser.add_argument(
|
|||
transcode_parser.add_argument(
|
||||
'--ignore-extension',
|
||||
action='store_true')
|
||||
transcode_parser.add_argument(
|
||||
'--custom-encoder-config',
|
||||
type=str,
|
||||
help='custom encoder config')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -74,5 +78,6 @@ elif args.subparser_name == "transcode":
|
|||
args.src,
|
||||
args.dest,
|
||||
args.transcode_level,
|
||||
args.ignore_extension
|
||||
args.ignore_extension,
|
||||
args.custom_encoder_config
|
||||
).run()
|
|
@ -109,7 +109,7 @@ class CopyCommand():
|
|||
|
||||
print("Transcoding", src, "to", dest_filepath)
|
||||
|
||||
transcode(file, trans_config, level, dest_filepath)
|
||||
transcode(file, trans_config, dest_filepath)
|
||||
|
||||
self.state.transcoded_files.append(new_file)
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
from ..utils.transcoder import get_transcode_config, transcode
|
||||
from ..utils.transcoder import get_transcode_config, transcode, TranscodeConfig
|
||||
from ..utils.scan_for_music import file_from_path
|
||||
from ..transcode_levels import transcode_levels
|
||||
|
||||
from pathlib import Path
|
||||
from json import load as load_json_file
|
||||
|
||||
class TranscodeCommand:
|
||||
def __init__(
|
||||
|
@ -10,11 +12,13 @@ class TranscodeCommand:
|
|||
dest: str,
|
||||
transcode_level: str,
|
||||
ignore_extension: bool,
|
||||
custom_encoder_config_path: str,
|
||||
):
|
||||
self.src = src
|
||||
self.dest = dest
|
||||
self.transcode_level = transcode_level
|
||||
self.ignore_extension = ignore_extension
|
||||
self.custom_encoder_config_path = custom_encoder_config_path
|
||||
|
||||
def run(self):
|
||||
if self.transcode_level == "list":
|
||||
|
@ -24,7 +28,13 @@ class TranscodeCommand:
|
|||
print("Transcoding...")
|
||||
input_file = file_from_path(Path(self.src), "")
|
||||
|
||||
trans_config = get_transcode_config(input_file, self.transcode_level)
|
||||
if self.custom_encoder_config_path is None or len(self.custom_encoder_config_path) == 0:
|
||||
trans_config = get_transcode_config(input_file, self.transcode_level)
|
||||
else:
|
||||
with open(self.custom_encoder_config_path, "r+") as f:
|
||||
trans_config_dict = load_json_file(f)
|
||||
trans_config = TranscodeConfig()
|
||||
trans_config.load_from_dict(trans_config_dict)
|
||||
|
||||
output_file = file_from_path(Path(self.dest), "")
|
||||
|
||||
|
@ -36,4 +46,4 @@ class TranscodeCommand:
|
|||
f"or run with --ignore-extension"
|
||||
)
|
||||
exit()
|
||||
transcode(input_file, trans_config, self.transcode_level, self.dest)
|
||||
transcode(input_file, trans_config, self.dest)
|
|
@ -13,6 +13,23 @@ class TranscodeConfig:
|
|||
bitrate = ""
|
||||
quality = ""
|
||||
|
||||
def load_from_dict(self, data):
|
||||
if "use_quality" in data:
|
||||
self.use_quality = data["use_quality"]
|
||||
if "use_bitrate" in data:
|
||||
self.use_bitrate = data["use_bitrate"]
|
||||
if "encoder" in data:
|
||||
self.encoder = data["encoder"]
|
||||
if "file_extension" in data:
|
||||
self.file_extension = data["file_extension"]
|
||||
if "container" in data:
|
||||
self.container = data["container"]
|
||||
if "bitrate" in data:
|
||||
self.bitrate = data["bitrate"]
|
||||
if "quality" in data:
|
||||
self.quality = data["quality"]
|
||||
return self
|
||||
|
||||
def get_transcode_config(file: File, level: str):
|
||||
conf = TranscodeConfig()
|
||||
if level in preset_transcode_levels.keys():
|
||||
|
@ -60,7 +77,7 @@ def get_transcode_config(file: File, level: str):
|
|||
print("Unknown Level")
|
||||
exit()
|
||||
|
||||
def transcode(file: File, config: TranscodeConfig, level: str, dest: str):
|
||||
def transcode(file: File, config: TranscodeConfig, dest: str):
|
||||
title = file.tags.title
|
||||
artist = file.tags.artist
|
||||
|
||||
|
|
Loading…
Reference in a new issue