mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Accept additional command-line options
This commit is contained in:
@@ -10,7 +10,7 @@ class EmbedderBase(ABC):
|
||||
The subclass must define the supported media file encoding
|
||||
formats here using a static variable - such as:
|
||||
|
||||
>>> supported_formats = ("mp3", "opus", "flac")
|
||||
>>> supported_formats = ("mp3", "m4a", "flac")
|
||||
"""
|
||||
supported_formats = ()
|
||||
|
||||
@@ -72,9 +72,9 @@ class EmbedderBase(ABC):
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def as_opus(self, path, metadata, cached_albumart=None):
|
||||
def as_m4a(self, path, metadata, cached_albumart=None):
|
||||
"""
|
||||
Method for opus support. This method might be defined in
|
||||
Method for m4a support. This method might be defined in
|
||||
a subclass.
|
||||
|
||||
Other methods for additional supported formats must also
|
||||
|
||||
@@ -37,7 +37,7 @@ for key in M4A_TAG_PRESET.keys():
|
||||
|
||||
|
||||
class EmbedderDefault(EmbedderBase):
|
||||
supported_formats = ("mp3", "opus", "flac")
|
||||
supported_formats = ("mp3", "m4a", "flac")
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -102,10 +102,10 @@ class EmbedderDefault(EmbedderBase):
|
||||
|
||||
audiofile.save(v2_version=3)
|
||||
|
||||
def as_opus(self, path, cached_albumart=None):
|
||||
def as_m4a(self, path, metadata, cached_albumart=None):
|
||||
""" Embed metadata to M4A files. """
|
||||
audiofile = MP4(path)
|
||||
self._embed_basic_metadata(audiofile, metadata, "opus", preset=M4A_TAG_PRESET)
|
||||
self._embed_basic_metadata(audiofile, metadata, "m4a", preset=M4A_TAG_PRESET)
|
||||
if metadata["year"]:
|
||||
audiofile[M4A_TAG_PRESET["year"]] = metadata["year"]
|
||||
provider = metadata["provider"]
|
||||
|
||||
@@ -117,11 +117,27 @@ class YouTubeStreams(StreamsBase):
|
||||
request.add_header(*header)
|
||||
return urllib.request.urlopen(request)
|
||||
|
||||
def getbest(self):
|
||||
return self.all[0]
|
||||
def get(self, quality="best", preftype="automatic"):
|
||||
if quality == "best":
|
||||
return self.getbest(preftype=preftype)
|
||||
elif quality == "worst":
|
||||
return self.getworst(preftype=preftype)
|
||||
else:
|
||||
return None
|
||||
|
||||
def getworst(self):
|
||||
return self.all[-1]
|
||||
def getbest(self, preftype="automatic"):
|
||||
if preftype == "automatic":
|
||||
return self.all[0]
|
||||
for stream in self.all:
|
||||
if stream["encoding"] == preftype:
|
||||
return stream
|
||||
|
||||
def getworst(self, preftype="automatic"):
|
||||
if preftype == "automatic":
|
||||
return self.all[-1]
|
||||
for stream in self.all[::-1]:
|
||||
if stream["encoding"] == preftype:
|
||||
return stream
|
||||
|
||||
|
||||
class ProviderYouTube(ProviderBase):
|
||||
|
||||
@@ -62,7 +62,7 @@ class TestMethods:
|
||||
|
||||
@pytest.mark.parametrize("fmt_method_suffix", (
|
||||
"as_mp3",
|
||||
"as_opus",
|
||||
"as_m4a",
|
||||
"as_flac",
|
||||
))
|
||||
def test_embed_formats(self, fmt_method_suffix, embedderkid):
|
||||
|
||||
Reference in New Issue
Block a user