Add options for all extractors to be enabled or disabled

This commit is contained in:
Manuel Cortez 2019-06-18 16:16:29 -05:00
parent 0447974029
commit b090d7f896
5 changed files with 26 additions and 15 deletions

View File

@ -1,7 +1,3 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
import config from . import youtube, zaycev, tidal
from . import youtube, zaycev
# conditional imports
if config.app != None and config.app["services"]["tidal"]["username"] != "" and config.app["services"]["tidal"]["password"] != "":
from . import tidal

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
from __future__ import unicode_literals # at top of module """ Base components useful for all other extractors. """
import logging import logging
import wx import wx
import config import config

View File

@ -2,12 +2,14 @@
import logging import logging
import tidalapi import tidalapi
import config import config
from .import baseFile
from update.utils import seconds_to_string from update.utils import seconds_to_string
from .import base
log = logging.getLogger("extractors.tidal.com") log = logging.getLogger("extractors.tidal.com")
class interface(object): class interface(object):
name = "tidal" name = "tidal"
enabled = config.app["services"]["tidal"].get("enabled")
def __init__(self): def __init__(self):
self.results = [] self.results = []
@ -62,7 +64,7 @@ class interface(object):
for track in tracks: for track in tracks:
data.append(track) data.append(track)
for search_result in data: for search_result in data:
s = baseFile.song(self) s = base.song(self)
s.title = search_result.name s.title = search_result.name
s.artist = search_result.artist.name s.artist = search_result.artist.name
s.duration = seconds_to_string(search_result.duration) s.duration = seconds_to_string(search_result.duration)

View File

@ -1,13 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals # at top of module
import isodate import isodate
import youtube_dl import youtube_dl
import logging import logging
import wx import wx
import config
from googleapiclient.discovery import build from googleapiclient.discovery import build
from googleapiclient.errors import HttpError from googleapiclient.errors import HttpError
from update.utils import seconds_to_string from update.utils import seconds_to_string
from .import baseFile from .import base
DEVELOPER_KEY = "AIzaSyCU_hvZJEjLlAGAnlscquKEkE8l0lVOfn0" DEVELOPER_KEY = "AIzaSyCU_hvZJEjLlAGAnlscquKEkE8l0lVOfn0"
YOUTUBE_API_SERVICE_NAME = "youtube" YOUTUBE_API_SERVICE_NAME = "youtube"
@ -17,6 +17,7 @@ log = logging.getLogger("extractors.youtube.com")
class interface(object): class interface(object):
name = "YouTube" name = "YouTube"
enabled = config.app["services"]["youtube"].get("enabled")
def __init__(self): def __init__(self):
self.results = [] self.results = []
@ -38,7 +39,7 @@ class interface(object):
ids = [] ids = []
for search_result in search_response.get("items", []): for search_result in search_response.get("items", []):
if search_result["id"]["kind"] == "youtube#video": if search_result["id"]["kind"] == "youtube#video":
s = baseFile.song(self) s = base.song(self)
s.title = search_result["snippet"]["title"] s.title = search_result["snippet"]["title"]
ids.append(search_result["id"]["videoId"]) ids.append(search_result["id"]["videoId"])
s.url = "https://www.youtube.com/watch?v="+search_result["id"]["videoId"] s.url = "https://www.youtube.com/watch?v="+search_result["id"]["videoId"]
@ -104,14 +105,26 @@ class interface(object):
def format_track(self, item): def format_track(self, item):
return "{0} {1}".format(item.title, item.duration) return "{0} {1}".format(item.title, item.duration)
class settings(baseFile.baseSettings): class settings(base.baseSettings):
name = _("Youtube Settings") name = _("Youtube Settings")
config_section = "youtube" config_section = "youtube"
def __init__(self, parent): def __init__(self, parent):
super(settings, self).__init__(parent=parent) super(settings, self).__init__(parent=parent)
sizer = wx.BoxSizer(wx.VERTICAL) 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)
self.transcode = wx.CheckBox(self, wx.NewId(), _("Enable transcode when downloading")) self.transcode = wx.CheckBox(self, wx.NewId(), _("Enable transcode when downloading"))
self.map.append(("transcode", self.transcode)) self.map.append(("transcode", self.transcode))
sizer.Add(self.transcode, 0, wx.ALL, 5) sizer.Add(self.transcode, 0, wx.ALL, 5)
self.SetSizer(sizer) 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)

View File

@ -1,12 +1,12 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
from __future__ import unicode_literals # at top of module
import re import re
import json import json
import requests import requests
import logging import logging
import config
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from . import baseFile from . import base
log = logging.getLogger("extractors.zaycev.net") log = logging.getLogger("extractors.zaycev.net")
@ -32,7 +32,7 @@ class interface(object):
# The easiest method to get artist and song names is to fetch links. There are only two links per result here. # The easiest method to get artist and song names is to fetch links. There are only two links per result here.
data = i.find_all("a") data = i.find_all("a")
# from here, data[0] contains artist info and data[1] contains info of the retrieved song. # from here, data[0] contains artist info and data[1] contains info of the retrieved song.
s = baseFile.song(self) s = base.song(self)
s.title = data[1].text s.title = data[1].text
s.artist = data[0].text s.artist = data[0].text
s.url = "http://zaycev.net%s" % (data[1].attrs["href"]) s.url = "http://zaycev.net%s" % (data[1].attrs["href"])