mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 09:50:16 +00:00
Better handling when FFmpeg isn't found
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@
|
|||||||
*.mp3
|
*.mp3
|
||||||
*.opus
|
*.opus
|
||||||
*.flac
|
*.flac
|
||||||
|
*.temp
|
||||||
config.yml
|
config.yml
|
||||||
Music/
|
Music/
|
||||||
*.txt
|
*.txt
|
||||||
|
|||||||
@@ -292,10 +292,13 @@ class Arguments:
|
|||||||
"--write-to can only be used with --playlist, --album, --all-albums, --username, or --write-m3u."
|
"--write-to can only be used with --playlist, --album, --all-albums, --username, or --write-m3u."
|
||||||
)
|
)
|
||||||
|
|
||||||
ffmpeg_exists = shutil.which("ffmpeg")
|
ffmpeg_exists = shutil.which("fffmpeg")
|
||||||
if not ffmpeg_exists:
|
if not ffmpeg_exists:
|
||||||
logger.warn("FFmpeg was not found in PATH. Will not re-encode media to specified output format.")
|
logger.warn("FFmpeg was not found in PATH. Will not re-encode media to specified output format.")
|
||||||
self.parsed.output_ext = self.parsed.input_ext
|
self.parsed.no_encode = True
|
||||||
|
|
||||||
|
if self.parsed.no_encode and self.parsed.trim_silence:
|
||||||
|
logger.warn("--trim-silence can only be used when an encoder is set.")
|
||||||
|
|
||||||
if self.parsed.output_file == "-" and self.parsed.no_metadata is False:
|
if self.parsed.output_file == "-" and self.parsed.no_metadata is False:
|
||||||
logger.warn(
|
logger.warn(
|
||||||
@@ -311,7 +314,7 @@ class Arguments:
|
|||||||
logger.warn(
|
logger.warn(
|
||||||
"Given output file is a directory. Will download tracks "
|
"Given output file is a directory. Will download tracks "
|
||||||
"in this directory with their filename as per the default "
|
"in this directory with their filename as per the default "
|
||||||
"file format. Pass '--output-file=\"{}\"' to hide this "
|
"file format. Pass --output-file=\"{}\" to hide this "
|
||||||
"warning.".format(
|
"warning.".format(
|
||||||
adjusted_output_file
|
adjusted_output_file
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class TestArguments:
|
|||||||
arguments["spotify_client_secret"] = None
|
arguments["spotify_client_secret"] = None
|
||||||
|
|
||||||
expect_arguments = {
|
expect_arguments = {
|
||||||
"track": ["elena coats - one last song"],
|
"song": ["elena coats - one last song"],
|
||||||
"song": None,
|
"song": None,
|
||||||
"list": None,
|
"list": None,
|
||||||
"playlist": None,
|
"playlist": None,
|
||||||
@@ -46,7 +46,6 @@ class TestArguments:
|
|||||||
"no_remove_original": False,
|
"no_remove_original": False,
|
||||||
"no_metadata": False,
|
"no_metadata": False,
|
||||||
"no_fallback_metadata": False,
|
"no_fallback_metadata": False,
|
||||||
"avconv": False,
|
|
||||||
"directory": "/home/ritiek/Music",
|
"directory": "/home/ritiek/Music",
|
||||||
"overwrite": "prompt",
|
"overwrite": "prompt",
|
||||||
"input_ext": ".m4a",
|
"input_ext": ".m4a",
|
||||||
@@ -60,7 +59,6 @@ class TestArguments:
|
|||||||
"music_videos_only": False,
|
"music_videos_only": False,
|
||||||
"no_spaces": False,
|
"no_spaces": False,
|
||||||
"log_level": 20,
|
"log_level": 20,
|
||||||
"youtube_api_key": None,
|
|
||||||
"skip": None,
|
"skip": None,
|
||||||
"write_successful": None,
|
"write_successful": None,
|
||||||
"spotify_client_id": None,
|
"spotify_client_id": None,
|
||||||
@@ -72,5 +70,5 @@ class TestArguments:
|
|||||||
|
|
||||||
def test_grouped_arguments(self):
|
def test_grouped_arguments(self):
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
spotdl.command_line.arguments.get_arguments(to_merge=True)
|
spotdl.command_line.arguments.get_arguments()
|
||||||
|
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
from spotdl.encode import EncoderBase
|
|
||||||
from spotdl.encode.exceptions import AvconvNotFoundError
|
|
||||||
from spotdl.encode.encoders import EncoderAvconv
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
class TestEncoderAvconv:
|
|
||||||
def test_subclass(self):
|
|
||||||
assert issubclass(EncoderAvconv, EncoderBase)
|
|
||||||
|
|
||||||
def test_avconv_not_found_error(self):
|
|
||||||
with pytest.raises(AvconvNotFoundError):
|
|
||||||
EncoderAvconv(encoder_path="/a/nonexistent/path")
|
|
||||||
|
|
||||||
|
|
||||||
class TestEncodingDefaults:
|
|
||||||
def encode_command(input_file, target_file):
|
|
||||||
command = [
|
|
||||||
'avconv', '-y', '-loglevel', '0',
|
|
||||||
'-i', input_file,
|
|
||||||
'-ab', '192k',
|
|
||||||
target_file,
|
|
||||||
]
|
|
||||||
return command
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("files, expected_command", [
|
|
||||||
(("test.m4a", "test.mp3"), encode_command("test.m4a", "test.mp3")),
|
|
||||||
(("abc.m4a", "cba.opus"), encode_command("abc.m4a", "cba.opus")),
|
|
||||||
(("bla bla.m4a", "ble ble.m4a"), encode_command("bla bla.m4a", "ble ble.m4a")),
|
|
||||||
(("😛.m4a", "• tongue.flac"), encode_command("😛.m4a", "• tongue.flac")),
|
|
||||||
])
|
|
||||||
def test_generate_encode_command(self, files, expected_command):
|
|
||||||
encoder = EncoderAvconv()
|
|
||||||
assert encoder._generate_encode_command(*files) == expected_command
|
|
||||||
|
|
||||||
|
|
||||||
class TestEncodingInDebugMode:
|
|
||||||
def debug_encode_command(input_file, target_file):
|
|
||||||
command = [
|
|
||||||
'avconv', '-y', '-loglevel', 'debug',
|
|
||||||
'-i', input_file,
|
|
||||||
'-ab', '192k',
|
|
||||||
target_file,
|
|
||||||
]
|
|
||||||
return command
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("files, expected_command", [
|
|
||||||
(("test.m4a", "test.mp3"), debug_encode_command("test.m4a", "test.mp3")),
|
|
||||||
(("abc.m4a", "cba.opus"), debug_encode_command("abc.m4a", "cba.opus")),
|
|
||||||
(("bla bla.m4a", "ble ble.m4a"), debug_encode_command("bla bla.m4a", "ble ble.m4a")),
|
|
||||||
(("😛.m4a", "• tongue.flac"), debug_encode_command("😛.m4a", "• tongue.flac")),
|
|
||||||
])
|
|
||||||
def test_generate_encode_command_with_debug(self, files, expected_command):
|
|
||||||
encoder = EncoderAvconv()
|
|
||||||
encoder.set_debuglog()
|
|
||||||
assert encoder._generate_encode_command(*files) == expected_command
|
|
||||||
|
|
||||||
@@ -11,10 +11,3 @@ class FFmpegNotFoundError(EncoderNotFoundError):
|
|||||||
def __init__(self, message=None):
|
def __init__(self, message=None):
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
|
|
||||||
|
|
||||||
class AvconvNotFoundError(EncoderNotFoundError):
|
|
||||||
__module__ = Exception.__module__
|
|
||||||
|
|
||||||
def __init__(self, message=None):
|
|
||||||
super().__init__(message)
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from spotdl.encode.exceptions import EncoderNotFoundError
|
from spotdl.encode.exceptions import EncoderNotFoundError
|
||||||
from spotdl.encode.exceptions import FFmpegNotFoundError
|
from spotdl.encode.exceptions import FFmpegNotFoundError
|
||||||
from spotdl.encode.exceptions import AvconvNotFoundError
|
|
||||||
|
|
||||||
|
|
||||||
class TestEncoderNotFoundSubclass:
|
class TestEncoderNotFoundSubclass:
|
||||||
@@ -10,6 +9,3 @@ class TestEncoderNotFoundSubclass:
|
|||||||
def test_ffmpeg_not_found_subclass(self):
|
def test_ffmpeg_not_found_subclass(self):
|
||||||
assert issubclass(FFmpegNotFoundError, EncoderNotFoundError)
|
assert issubclass(FFmpegNotFoundError, EncoderNotFoundError)
|
||||||
|
|
||||||
def test_avconv_not_found_subclass(self):
|
|
||||||
assert issubclass(AvconvNotFoundError, EncoderNotFoundError)
|
|
||||||
|
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ class YouTubeStreams(StreamsBase):
|
|||||||
if stream["encoding"] == preftype:
|
if stream["encoding"] == preftype:
|
||||||
selected_stream = stream
|
selected_stream = stream
|
||||||
break
|
break
|
||||||
logger.debug('Selected worst quality stream for "{preftype}" format:\n'.format(
|
logger.debug('Selected worst quality stream for "{preftype}" format:\n{stream}'.format(
|
||||||
preftype=preftype,
|
preftype=preftype,
|
||||||
stream=selected_stream,
|
stream=selected_stream,
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in New Issue
Block a user