Gets all extractors with a simple function

This commit is contained in:
Manuel Cortez 2018-04-01 05:12:23 -05:00
parent 61f4371509
commit 7385613218

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" main controller for MusicDL""" """ main controller for MusicDL"""
from __future__ import unicode_literals # at top of module from __future__ import unicode_literals # at top of module
import types
import webbrowser import webbrowser
import wx import wx
import logging import logging
@ -9,12 +10,18 @@ import utils
import application import application
from pubsub import pub from pubsub import pub
from wxUI import mainWindow, menus from wxUI import mainWindow, menus
from extractors import zaycev, youtube, vk, mailru
from update import updater from update import updater
from . import player from . import player
log = logging.getLogger("controller.main") log = logging.getLogger("controller.main")
def get_extractors():
""" Function for importing everything wich is located in the extractors package and has a class named interface."""
import extractors
module_type = types.ModuleType
classes = [m.interface for m in extractors.__dict__.values() if type(m) == module_type and hasattr(m, 'interface')]
return sorted(classes, key=lambda c: c.name)
class Controller(object): class Controller(object):
def __init__(self): def __init__(self):
@ -229,16 +236,11 @@ class Controller(object):
if text == "": if text == "":
return return
extractor = self.window.extractor.GetValue() extractor = self.window.extractor.GetValue()
if extractor == "youtube": extractors = get_extractors()
self.extractor = youtube.interface() for i in extractors:
elif extractor == "vk": if extractor == i.name:
self.extractor = vk.interface() self.extractor = i()
elif extractor == "mail.ru": break
self.extractor = mailru.interface()
elif extractor == "zaycev.net":
self.extractor = zaycev.interface()
elif extractor == "":
return
log.debug("Started search for {0} (selected extractor: {1})".format(text, self.extractor.name)) log.debug("Started search for {0} (selected extractor: {1})".format(text, self.extractor.name))
self.window.list.Clear() self.window.list.Clear()
self.change_status(_(u"Searching {0}... ").format(text)) self.change_status(_(u"Searching {0}... ").format(text))