From 0d0a85b7613ecce75da9653ea12930f1d75c3b5a Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Sat, 29 Dec 2018 14:56:00 +0530 Subject: [PATCH] Some updates for using spotdl as library --- spotdl/const.py | 9 ++++++--- test/loader.py | 1 - test/test_download_with_metadata.py | 12 ++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/spotdl/const.py b/spotdl/const.py index 635f389..d6c76c6 100644 --- a/spotdl/const.py +++ b/spotdl/const.py @@ -2,13 +2,16 @@ import logzero _log_format = "%(color)s%(levelname)s:%(end_color)s %(message)s" _formatter = logzero.LogFormatter(fmt=_log_format) +_log_level = 0 # Set up a temporary logger with default log level so that # it can be used before log level argument is determined -logzero.setup_default_logger(formatter=_formatter) +logzero.setup_default_logger(formatter=_formatter, level=_log_level) -# options -args = None +# Options +# Initialize an empty object which can be assigned attributes +# (useful when using spotdl as a library) +args = type('', (), {})() # Apple has specific tags - see mutagen docs - # http://mutagen.readthedocs.io/en/latest/api/mp4.html diff --git a/test/loader.py b/test/loader.py index f176cee..33e288d 100644 --- a/test/loader.py +++ b/test/loader.py @@ -8,7 +8,6 @@ import pytest def load_defaults(): const.args = handle.get_arguments(raw_args="", to_group=False, to_merge=False) const.args.overwrite = "skip" - const.args.log_level = 10 spotdl.args = const.args spotdl.log = const.logzero.setup_logger( diff --git a/test/test_download_with_metadata.py b/test/test_download_with_metadata.py index 8573c1d..9ed36fb 100644 --- a/test/test_download_with_metadata.py +++ b/test/test_download_with_metadata.py @@ -128,7 +128,7 @@ class TestDownload: class TestFFmpeg: def test_convert_from_webm_to_mp3(self, filename_fixture, monkeypatch): - expect_command = "ffmpeg -y -i {0}.webm -codec:a libmp3lame -ar 44100 -b:a 192k -vn {0}.mp3".format( + expect_command = "ffmpeg -y -hide_banner -nostats -v panic -i {0}.webm -codec:a libmp3lame -ar 44100 -b:a 192k -vn {0}.mp3".format( os.path.join(const.args.folder, filename_fixture) ) _, command = convert.song( @@ -137,7 +137,7 @@ class TestFFmpeg: assert " ".join(command) == expect_command def test_convert_from_webm_to_m4a(self, filename_fixture, monkeypatch): - expect_command = "ffmpeg -y -i {0}.webm -cutoff 20000 -codec:a aac -ar 44100 -b:a 192k -vn {0}.m4a".format( + expect_command = "ffmpeg -y -hide_banner -nostats -v panic -i {0}.webm -cutoff 20000 -codec:a aac -ar 44100 -b:a 192k -vn {0}.m4a".format( os.path.join(const.args.folder, filename_fixture) ) _, command = convert.song( @@ -146,7 +146,7 @@ class TestFFmpeg: assert " ".join(command) == expect_command def test_convert_from_m4a_to_mp3(self, filename_fixture, monkeypatch): - expect_command = "ffmpeg -y -i {0}.m4a -codec:v copy -codec:a libmp3lame -ar 44100 -b:a 192k -vn {0}.mp3".format( + expect_command = "ffmpeg -y -hide_banner -nostats -v panic -i {0}.m4a -codec:v copy -codec:a libmp3lame -ar 44100 -b:a 192k -vn {0}.mp3".format( os.path.join(const.args.folder, filename_fixture) ) _, command = convert.song( @@ -155,7 +155,7 @@ class TestFFmpeg: assert " ".join(command) == expect_command def test_convert_from_m4a_to_webm(self, filename_fixture, monkeypatch): - expect_command = "ffmpeg -y -i {0}.m4a -codec:a libopus -vbr on -b:a 192k -vn {0}.webm".format( + expect_command = "ffmpeg -y -hide_banner -nostats -v panic -i {0}.m4a -codec:a libopus -vbr on -b:a 192k -vn {0}.webm".format( os.path.join(const.args.folder, filename_fixture) ) _, command = convert.song( @@ -164,7 +164,7 @@ class TestFFmpeg: assert " ".join(command) == expect_command def test_convert_from_m4a_to_flac(self, filename_fixture, monkeypatch): - expect_command = "ffmpeg -y -i {0}.m4a -codec:a flac -ar 44100 -b:a 192k -vn {0}.flac".format( + expect_command = "ffmpeg -y -hide_banner -nostats -v panic -i {0}.m4a -codec:a flac -ar 44100 -b:a 192k -vn {0}.flac".format( os.path.join(const.args.folder, filename_fixture) ) _, command = convert.song( @@ -175,7 +175,7 @@ class TestFFmpeg: class TestAvconv: def test_convert_from_m4a_to_mp3(self, filename_fixture): - expect_command = "avconv -loglevel debug -i {0}.m4a -ab 192k {0}.mp3 -y".format( + expect_command = "avconv -loglevel 0 -i {0}.m4a -ab 192k {0}.mp3 -y".format( os.path.join(const.args.folder, filename_fixture) ) _, command = convert.song(