Added settings section for tidal

This commit is contained in:
Manuel Cortez 2019-06-21 14:47:24 -05:00
parent 1fcdd51358
commit d480e06ee3

View File

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
import logging
import webbrowser
import wx
import tidalapi
import config
from update.utils import seconds_to_string
@ -93,4 +95,65 @@ class interface(base.baseInterface):
return url
def format_track(self, item):
return "{title}. {artist}. {duration}".format(title=item.title, duration=item.duration, artist=item.artist)
return "{title}. {artist}. {duration}".format(title=item.title, duration=item.duration, artist=item.artist)
class settings(base.baseSettings):
name = _("Tidal")
config_section = "tidal"
def get_quality_list(self):
results = dict(low=_("Low"), high=_("High"), lossless=_("Lossless"))
return results
def get_quality_value(self, *args, **kwargs):
q = self.get_quality_list()
for i in q.keys():
if q.get(i) == self.quality.GetStringSelection():
return i
def __init__(self, parent):
super(settings, self).__init__(parent=parent)
sizer = wx.BoxSizer(wx.VERTICAL)
self.enabled = wx.CheckBox(self, wx.NewId(), _("Enable this service"))
self.enabled.Bind(wx.EVT_CHECKBOX, self.on_enabled)
self.map.append(("enabled", self.enabled))
sizer.Add(self.enabled, 0, wx.ALL, 5)
username = wx.StaticText(self, wx.NewId(), _("Tidal username or email address"))
self.username = wx.TextCtrl(self, wx.NewId())
usernamebox = wx.BoxSizer(wx.HORIZONTAL)
usernamebox.Add(username, 0, wx.ALL, 5)
usernamebox.Add(self.username, 0, wx.ALL, 5)
sizer.Add(usernamebox, 0, wx.ALL, 5)
self.map.append(("username", self.username))
password = wx.StaticText(self, wx.NewId(), _("Password"))
self.password = wx.TextCtrl(self, wx.NewId(), style=wx.TE_PASSWORD)
passwordbox = wx.BoxSizer(wx.HORIZONTAL)
passwordbox.Add(password, 0, wx.ALL, 5)
passwordbox.Add(self.password, 0, wx.ALL, 5)
sizer.Add(passwordbox, 0, wx.ALL, 5)
self.map.append(("password", self.password))
self.get_account = wx.Button(self, wx.NewId(), _("You can subscribe for a tidal account here"))
self.get_account.Bind(wx.EVT_BUTTON, self.on_get_account)
sizer.Add(self.get_account, 0, wx.ALL, 5)
quality = wx.StaticText(self, wx.NewId(), _("Audio quality"))
self.quality = wx.ComboBox(self, wx.NewId(), choices=[i for i in self.get_quality_list().values()], value=_("High"), style=wx.CB_READONLY)
qualitybox = wx.BoxSizer(wx.HORIZONTAL)
qualitybox.Add(quality, 0, wx.ALL, 5)
qualitybox.Add(self.quality, 0, wx.ALL, 5)
sizer.Add(qualitybox, 0, wx.ALL, 5)
# Monkeypatch for getting the right quality value here.
self.quality.GetValue = self.get_quality_value
self.map.append(("quality", self.quality))
self.SetSizer(sizer)
def on_enabled(self, *args, **kwargs):
for i in self.map:
if i[1] != self.enabled:
if self.enabled.GetValue() == True:
i[1].Enable(True)
else:
i[1].Enable(False)
def on_get_account(self, *args, **kwargs):
webbrowser.open_new_tab("https://tidal.com")