Nuke avconv

This commit is contained in:
Ritiek Malhotra
2020-05-10 04:44:31 +05:30
parent 4abdecf9ec
commit 083af5b802
8 changed files with 33 additions and 139 deletions

View File

@@ -10,9 +10,6 @@ from spotdl.encode.exceptions import EncoderNotFoundError
NOTE ON ENCODERS
================
* A comparision between FFmpeg, avconv, and libav:
https://stackoverflow.com/questions/9477115
* FFmeg encoders sorted in descending order based
on the quality of audio produced:
libopus > libvorbis >= libfdk_aac > aac > libmp3lame

View File

@@ -1,4 +1 @@
from spotdl.encode.encoders.ffmpeg import EncoderFFmpeg
from spotdl.encode.encoders.avconv import EncoderAvconv
EncodeClasses = (EncoderFFmpeg, EncoderAvconv)

View File

@@ -1,87 +0,0 @@
import subprocess
import os
import logging
logger = logging.getLogger(__name__)
from spotdl.encode import EncoderBase
from spotdl.encode.exceptions import EncoderNotFoundError
from spotdl.encode.exceptions import AvconvNotFoundError
class EncoderAvconv(EncoderBase):
def __init__(self, encoder_path="avconv"):
logger.warn(
"Using EncoderAvconv is deprecated and will be removed",
"in future versions. Use EncoderFFmpeg instead."
)
encoder_path = encoder_path
_loglevel = "-loglevel 0"
_additional_arguments = ["-ab", "192k"]
try:
super().__init__(encoder_path, _loglevel, _additional_arguments)
except EncoderNotFoundError as e:
raise AvconvNotFoundError(e.args[0])
def set_argument(self, argument):
super().set_argument(argument)
def get_encoding(self, filename):
return super().get_encoding(filename)
def _generate_encoding_arguments(self, input_encoding, target_encoding):
initial_arguments = self._rules.get(input_encoding)
if initial_arguments is None:
raise TypeError(
'The input format ("{}") is not supported.'.format(
input_extension,
)
)
arguments = initial_arguments.get(target_encoding)
if arguments is None:
raise TypeError(
'The output format ("{}") is not supported.'.format(
output_extension,
)
)
return arguments
def _generate_encoding_arguments(self, input_encoding, target_encoding):
return ""
def set_debuglog(self):
self._loglevel = "-loglevel debug"
def _generate_encode_command(self, input_file, target_file):
input_encoding = self.get_encoding(input_file)
target_encoding = self.get_encoding(target_file)
arguments = self._generate_encoding_arguments(
input_encoding,
target_encoding
)
command = [self.encoder_path] \
+ ["-y"] \
+ self._loglevel.split() \
+ ["-i", input_file] \
+ self._additional_arguments \
+ [target_file]
return command
def re_encode(self, input_file, target_file, delete_original=False):
encode_command = self._generate_encode_command(
input_file,
target_file
)
returncode = subprocess.call(encode_command)
encode_successful = returncode == 0
if encode_successful and delete_original:
os.remove(input_file)
return returncode

View File

@@ -60,12 +60,12 @@ class EncoderFFmpeg(EncoderBase):
def set_debuglog(self):
self._loglevel = "-loglevel debug"
def _generate_encode_command(self, input_path, target_path,
def _generate_encode_command(self, input_path, target_file,
input_encoding=None, target_encoding=None):
if input_encoding is None:
input_encoding = self.get_encoding(input_path)
if target_encoding is None:
target_encoding = self.get_encoding(target_path)
target_encoding = self.get_encoding(target_file)
arguments = self._generate_encoding_arguments(
input_encoding,
target_encoding
@@ -77,14 +77,14 @@ class EncoderFFmpeg(EncoderBase):
+ arguments.split() \
+ self._additional_arguments \
+ ["-f", target_encoding] \
+ [target_path]
+ [target_file]
return command
def re_encode(self, input_path, target_path, target_encoding=None, delete_original=False):
def re_encode(self, input_path, target_file, target_encoding=None, delete_original=False):
encode_command = self._generate_encode_command(
input_path,
target_path,
target_file,
target_encoding=target_encoding
)
logger.debug("Calling FFmpeg with:\n{command}".format(
@@ -97,10 +97,10 @@ class EncoderFFmpeg(EncoderBase):
os.remove(input_path)
return process
def re_encode_from_stdin(self, input_encoding, target_path, target_encoding=None):
def re_encode_from_stdin(self, input_encoding, target_file, target_encoding=None):
encode_command = self._generate_encode_command(
"-",
target_path,
target_file,
input_encoding=input_encoding,
target_encoding=target_encoding,
)