mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Decouple fetching metadata
This commit is contained in:
69
spotdl/metadata/metadata_base.py
Normal file
69
spotdl/metadata/metadata_base.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from abc import ABC
|
||||
from abc import abstractmethod
|
||||
|
||||
|
||||
class StreamsBase(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self, streams):
|
||||
"""
|
||||
This method must parse audio streams into a list of
|
||||
dictionaries with the keys:
|
||||
"bitrate", "download_url", "encoding", "filesize".
|
||||
|
||||
The list should typically be sorted in descending order
|
||||
based on the audio stream's bitrate.
|
||||
|
||||
This sorted list must be assigned to `self.all`.
|
||||
"""
|
||||
self.all = streams
|
||||
|
||||
@abstractmethod
|
||||
def getbest(self):
|
||||
"""
|
||||
This method must return the audio stream with the
|
||||
highest bitrate.
|
||||
"""
|
||||
return self.all[0]
|
||||
|
||||
@abstractmethod
|
||||
def getworst(self):
|
||||
"""
|
||||
This method must return the audio stream with the
|
||||
lowest bitrate.
|
||||
"""
|
||||
return self.all[-1]
|
||||
|
||||
|
||||
class MetadataBase(ABC):
|
||||
def set_credentials(self, client_id, client_secret):
|
||||
"""
|
||||
This method may or not be used depending on
|
||||
whether the metadata provider requires authentication
|
||||
or not.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def from_url(self, url):
|
||||
"""
|
||||
This method must return track metadata from the
|
||||
corresponding Spotify URL.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def from_query(self, query):
|
||||
"""
|
||||
This method must return track metadata from the
|
||||
corresponding search query.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def metadata_to_standard_form(self, metadata):
|
||||
"""
|
||||
This method must transform the fetched metadata
|
||||
into a format consistent with all other metadata
|
||||
providers, for easy utilization.
|
||||
"""
|
||||
pass
|
||||
Reference in New Issue
Block a user