Write tests for YouTube metadata

This commit is contained in:
Ritiek Malhotra
2020-03-27 04:33:00 +05:30
parent c9a804268d
commit 68c25e2aaa
25 changed files with 411 additions and 55 deletions

View File

@@ -81,7 +81,7 @@ class EncoderBase(ABC):
pass
@abstractmethod
def _generate_encoding_arguments(self, input_encoding, output_encoding):
def _generate_encoding_arguments(self, input_encoding, target_encoding):
"""
This method must return the core arguments for the defined
encoder such as defining the sample rate, audio bitrate,

View File

@@ -26,7 +26,7 @@ class EncoderAvconv(EncoderBase):
def get_encoding(self, filename):
return super().get_encoding(filename)
def _generate_encoding_arguments(self, input_encoding, output_encoding):
def _generate_encoding_arguments(self, input_encoding, target_encoding):
initial_arguments = self._rules.get(input_encoding)
if initial_arguments is None:
raise TypeError(
@@ -35,7 +35,7 @@ class EncoderAvconv(EncoderBase):
)
)
arguments = initial_arguments.get(output_encoding)
arguments = initial_arguments.get(target_encoding)
if arguments is None:
raise TypeError(
'The output format ("{}") is not supported.'.format(
@@ -45,19 +45,19 @@ class EncoderAvconv(EncoderBase):
return arguments
def _generate_encoding_arguments(self, input_encoding, output_encoding):
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, output_file):
def _generate_encode_command(self, input_file, target_file):
input_encoding = self.get_encoding(input_file)
output_encoding = self.get_encoding(output_file)
target_encoding = self.get_encoding(target_file)
arguments = self._generate_encoding_arguments(
input_encoding,
output_encoding
target_encoding
)
command = [self.encoder_path] \
@@ -65,14 +65,14 @@ class EncoderAvconv(EncoderBase):
+ self._loglevel.split() \
+ ["-i", input_file] \
+ self._additional_arguments \
+ [output_file]
+ [target_file]
return command
def re_encode(self, input_file, output_file, delete_original=False):
def re_encode(self, input_file, target_file, delete_original=False):
encode_command = self._generate_encode_command(
input_file,
output_file
target_file
)
returncode = subprocess.call(encode_command)

View File

@@ -37,18 +37,18 @@ class EncoderFFmpeg(EncoderBase):
def get_encoding(self, path):
return super().get_encoding(path)
def _generate_encoding_arguments(self, input_encoding, output_encoding):
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_encoding,
))
arguments = initial_arguments.get(output_encoding)
arguments = initial_arguments.get(target_encoding)
if arguments is None:
raise TypeError(
'The output format ("{}") is not supported.'.format(
output_encoding,
target_encoding,
))
return arguments
@@ -56,14 +56,14 @@ class EncoderFFmpeg(EncoderBase):
self._loglevel = "-loglevel debug"
def _generate_encode_command(self, input_path, target_path,
input_encoding=None, output_encoding=None):
input_encoding=None, target_encoding=None):
if input_encoding is None:
input_encoding = self.get_encoding(input_path)
if output_encoding is None:
output_encoding = self.get_encoding(target_path)
if target_encoding is None:
target_encoding = self.get_encoding(target_path)
arguments = self._generate_encoding_arguments(
input_encoding,
output_encoding
target_encoding
)
command = [self.encoder_path] \
+ ["-y", "-nostdin"] \
@@ -88,7 +88,7 @@ class EncoderFFmpeg(EncoderBase):
return process
def re_encode_from_stdin(self, input_encoding, target_path):
output_encoding = self.get_encoding(target_path)
target_encoding = self.get_encoding(target_path)
encode_command = self._generate_encode_command(
"-",
target_path,

View File

@@ -15,12 +15,12 @@ class TestEncoderAvconv:
class TestEncodingDefaults:
def encode_command(input_file, output_file):
def encode_command(input_file, target_file):
command = [
'avconv', '-y', '-loglevel', '0',
'-i', input_file,
'-ab', '192k',
output_file,
target_file,
]
return command
@@ -36,12 +36,12 @@ class TestEncodingDefaults:
class TestEncodingInDebugMode:
def debug_encode_command(input_file, output_file):
def debug_encode_command(input_file, target_file):
command = [
'avconv', '-y', '-loglevel', 'debug',
'-i', input_file,
'-ab', '192k',
output_file,
target_file,
]
return command

View File

@@ -4,7 +4,6 @@ from spotdl.encode.encoders import EncoderFFmpeg
import pytest
class TestEncoderFFmpeg:
def test_subclass(self):
assert issubclass(EncoderFFmpeg, EncoderBase)

View File

@@ -2,19 +2,19 @@ class EncoderNotFoundError(Exception):
__module__ = Exception.__module__
def __init__(self, message=None):
super(EncoderNotFoundError, self).__init__(message)
super().__init__(message)
class FFmpegNotFoundError(EncoderNotFoundError):
__module__ = Exception.__module__
def __init__(self, message=None):
super(FFmpegNotFoundError, self).__init__(message)
super().__init__(message)
class AvconvNotFoundError(EncoderNotFoundError):
__module__ = Exception.__module__
def __init__(self, message=None):
super(AvconvNotFoundError, self).__init__(message)
super().__init__(message)

View File

@@ -3,7 +3,6 @@ from spotdl.encode.exceptions import EncoderNotFoundError
import pytest
class TestAbstractBaseClass:
def test_error_abstract_base_class_encoderbase(self):
encoder_path = "ffmpeg"
@@ -27,15 +26,9 @@ class TestAbstractBaseClass:
def _generate_encoding_arguments(self):
pass
def get_encoding(self):
pass
def re_encode(self):
pass
def set_argument(self):
pass
def set_debuglog(self):
pass
@@ -52,21 +45,15 @@ class TestMethods:
def __init__(self, encoder_path, _loglevel, _additional_arguments):
super().__init__(encoder_path, _loglevel, _additional_arguments)
def _generate_encode_command(self, input_file, output_file):
def _generate_encode_command(self, input_file, target_file):
pass
def _generate_encoding_arguments(self, input_encoding, output_encoding):
def _generate_encoding_arguments(self, input_encoding, target_encoding):
pass
def get_encoding(self, filename):
return super().get_encoding(filename)
def re_encode(self, input_encoding, output_encoding):
def re_encode(self, input_encoding, target_encoding):
pass
def set_argument(self, argument):
super().set_argument(argument)
def set_debuglog(self):
pass

View File

@@ -2,8 +2,6 @@ from spotdl.encode.exceptions import EncoderNotFoundError
from spotdl.encode.exceptions import FFmpegNotFoundError
from spotdl.encode.exceptions import AvconvNotFoundError
import pytest
class TestEncoderNotFoundSubclass:
def test_encoder_not_found_subclass(self):