Defined a base extractor interface from where others will be derived. Added methods to retrieve if the transcoder should be enabled or not, and to retrieve the default file format, which also will be used as file extension in the saveDialog suggestions

This commit is contained in:
Manuel Cortez 2019-06-20 17:44:39 -05:00
parent edc46ee824
commit 93b066804b
4 changed files with 43 additions and 18 deletions

View File

@ -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"""

View File

@ -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.")

View File

@ -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"

View File

@ -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.")