diff --git a/src/extractors/base.py b/src/extractors/base.py index d72bcfd..859c7ad 100644 --- a/src/extractors/base.py +++ b/src/extractors/base.py @@ -6,6 +6,31 @@ import wx import config log = logging.getLogger("extractors.config") +class baseInterface(object): + name = "base" + enabled = False + needs_transcode = False + results = [] + + def __init__(self): + super(baseInterface, self).__init__() + log.debug("started extraction service for {0}".format(self.name,)) + + def search(self, text, *args, **kwargs): + raise NotImplementedError() + + def get_download_url(self, url): + raise NotImplementedError() + + def format_track(self, item): + raise NotImplementedError() + + def get_file_format(self): + return "mp3" + + def transcoder_enabled(self): + return False + class song(object): """ Represents a song in all services. Data will be filled by the service itself""" diff --git a/src/extractors/tidal.py b/src/extractors/tidal.py index 08dceef..2ff1549 100644 --- a/src/extractors/tidal.py +++ b/src/extractors/tidal.py @@ -7,7 +7,7 @@ from .import base log = logging.getLogger("extractors.tidal.com") -class interface(object): +class interface(base.baseInterface): name = "tidal" enabled = config.app["services"]["tidal"].get("enabled") # This should not be enabled if credentials are not in config. @@ -15,9 +15,10 @@ class interface(object): enabled = False def __init__(self): - self.results = [] - self.needs_transcode = False - log.debug("started extraction service for {0}".format(self.name,)) + super(interface, self).__init__() + self.setup() + + def setup(self): # Assign quality or switch to high if not specified/not found. if hasattr(tidalapi.Quality, config.app["services"]["tidal"]["quality"]): quality = getattr(tidalapi.Quality, config.app["services"]["tidal"]["quality"]) @@ -29,11 +30,19 @@ class interface(object): log.debug("Using quality: %s" % (quality,)) self.session = tidalapi.Session(config=_config) self.session.login(username=username, password=password) + + def get_file_format(self): if config.app["services"]["tidal"]["quality"] == "lossless": self.file_extension = "flac" else: self.file_extension = "mp3" + def transcoder_enabled(self): + if config.app["services"]["tidal"]["quality"] == "lossless": + return False + else: + return True + def search(self, text, page=1): if text == "" or text == None: raise ValueError("Text must be passed and should not be blank.") diff --git a/src/extractors/youtube.py b/src/extractors/youtube.py index ea2af97..263ad33 100644 --- a/src/extractors/youtube.py +++ b/src/extractors/youtube.py @@ -15,16 +15,10 @@ YOUTUBE_API_VERSION = "v3" log = logging.getLogger("extractors.youtube.com") -class interface(object): +class interface(base.baseInterface): name = "YouTube" enabled = config.app["services"]["youtube"].get("enabled") - def __init__(self): - self.results = [] - self.needs_transcode = True - log.debug("started extraction service for {0}".format(self.name,)) - self.file_extension = "mp3" - def search(self, text, page=1): if text == "" or text == None: raise ValueError("Text must be passed and should not be blank.") @@ -105,6 +99,9 @@ class interface(object): def format_track(self, item): return "{0} {1}".format(item.title, item.duration) + def transcoder_enabled(self): + return config.app["services"]["youtube"]["transcode"] + class settings(base.baseSettings): name = _("Youtube Settings") config_section = "youtube" diff --git a/src/extractors/zaycev.py b/src/extractors/zaycev.py index f15bb7e..bbe2eaf 100644 --- a/src/extractors/zaycev.py +++ b/src/extractors/zaycev.py @@ -10,16 +10,10 @@ from . import base log = logging.getLogger("extractors.zaycev.net") -class interface(object): +class interface(base.baseInterface): name = "zaycev.net" enabled = True - def __init__(self): - self.results = [] - self.needs_transcode = False - log.debug("Started extraction service for zaycev.net") - self.file_extension = "mp3" - def search(self, text, page=1): if text == "" or text == None: raise ValueError("Text must be passed and should not be blank.")