mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-12-08 20:39:08 +00:00
Refactor embedding metadata to media
This commit is contained in:
@@ -31,14 +31,11 @@ class EncoderFFmpeg(EncoderBase):
|
||||
raise FFmpegNotFoundError(e.args[0])
|
||||
self._rules = RULES
|
||||
|
||||
def set_argument(self, argument):
|
||||
super().set_argument(argument)
|
||||
|
||||
def set_trim_silence(self):
|
||||
self.set_argument("-af silenceremove=start_periods=1")
|
||||
|
||||
def get_encoding(self, filename):
|
||||
return super().get_encoding(filename)
|
||||
def get_encoding(self, path):
|
||||
return super().get_encoding(path)
|
||||
|
||||
def _generate_encoding_arguments(self, input_encoding, output_encoding):
|
||||
initial_arguments = self._rules.get(input_encoding)
|
||||
@@ -46,26 +43,24 @@ class EncoderFFmpeg(EncoderBase):
|
||||
raise TypeError(
|
||||
'The input format ("{}") is not supported.'.format(
|
||||
input_encoding,
|
||||
)
|
||||
)
|
||||
))
|
||||
arguments = initial_arguments.get(output_encoding)
|
||||
if arguments is None:
|
||||
raise TypeError(
|
||||
'The output format ("{}") is not supported.'.format(
|
||||
output_encoding,
|
||||
)
|
||||
)
|
||||
))
|
||||
return arguments
|
||||
|
||||
def set_debuglog(self):
|
||||
self._loglevel = "-loglevel debug"
|
||||
|
||||
def _generate_encode_command(self, input_file, output_file,
|
||||
def _generate_encode_command(self, input_path, target_path,
|
||||
input_encoding=None, output_encoding=None):
|
||||
if input_encoding is None:
|
||||
input_encoding = self.get_encoding(input_file)
|
||||
input_encoding = self.get_encoding(input_path)
|
||||
if output_encoding is None:
|
||||
output_encoding = self.get_encoding(output_file)
|
||||
output_encoding = self.get_encoding(target_path)
|
||||
arguments = self._generate_encoding_arguments(
|
||||
input_encoding,
|
||||
output_encoding
|
||||
@@ -73,30 +68,30 @@ class EncoderFFmpeg(EncoderBase):
|
||||
command = [self.encoder_path] \
|
||||
+ ["-y", "-nostdin"] \
|
||||
+ self._loglevel.split() \
|
||||
+ ["-i", input_file] \
|
||||
+ ["-i", input_path] \
|
||||
+ arguments.split() \
|
||||
+ self._additional_arguments \
|
||||
+ [output_file]
|
||||
+ [target_path]
|
||||
|
||||
return command
|
||||
|
||||
def re_encode(self, input_file, output_file, delete_original=False):
|
||||
def re_encode(self, input_path, target_path, delete_original=False):
|
||||
encode_command = self._generate_encode_command(
|
||||
input_file,
|
||||
output_file
|
||||
input_path,
|
||||
target_path
|
||||
)
|
||||
process = subprocess.Popen(encode_command)
|
||||
process.wait()
|
||||
encode_successful = process.returncode == 0
|
||||
if encode_successful and delete_original:
|
||||
os.remove(input_file)
|
||||
os.remove(input_path)
|
||||
return process
|
||||
|
||||
def re_encode_from_stdin(self, input_encoding, output_file):
|
||||
output_encoding = self.get_encoding(output_file)
|
||||
def re_encode_from_stdin(self, input_encoding, target_path):
|
||||
output_encoding = self.get_encoding(target_path)
|
||||
encode_command = self._generate_encode_command(
|
||||
"-",
|
||||
output_file,
|
||||
target_path,
|
||||
input_encoding=input_encoding,
|
||||
)
|
||||
process = subprocess.Popen(encode_command, stdin=subprocess.PIPE)
|
||||
|
||||
Reference in New Issue
Block a user