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
# -*- coding: UTF-8 -*-
import config
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
from . import youtube, zaycev, tidal

View File

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

View File

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

View File

@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals # at top of module
import isodate
import youtube_dl
import logging
import wx
import config
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from update.utils import seconds_to_string
from .import baseFile
from .import base
DEVELOPER_KEY = "AIzaSyCU_hvZJEjLlAGAnlscquKEkE8l0lVOfn0"
YOUTUBE_API_SERVICE_NAME = "youtube"
@ -17,6 +17,7 @@ log = logging.getLogger("extractors.youtube.com")
class interface(object):
name = "YouTube"
enabled = config.app["services"]["youtube"].get("enabled")
def __init__(self):
self.results = []
@ -38,7 +39,7 @@ class interface(object):
ids = []
for search_result in search_response.get("items", []):
if search_result["id"]["kind"] == "youtube#video":
s = baseFile.song(self)
s = base.song(self)
s.title = search_result["snippet"]["title"]
ids.append(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):
return "{0} {1}".format(item.title, item.duration)
class settings(baseFile.baseSettings):
class settings(base.baseSettings):
name = _("Youtube Settings")
config_section = "youtube"
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)
self.transcode = wx.CheckBox(self, wx.NewId(), _("Enable transcode when downloading"))
self.map.append(("transcode", self.transcode))
sizer.Add(self.transcode, 0, wx.ALL, 5)
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
# -*- coding: UTF-8 -*-
from __future__ import unicode_literals # at top of module
import re
import json
import requests
import logging
import config
from bs4 import BeautifulSoup
from . import baseFile
from . import base
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.
data = i.find_all("a")
# 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.artist = data[0].text
s.url = "http://zaycev.net%s" % (data[1].attrs["href"])