From e2099a3e5c8f38c8bae88d862950b0c2bf5b1d13 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 15 Aug 2020 17:08:58 +0200 Subject: Add option to specifie extractor --- extractors/job.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'extractors/job.py') diff --git a/extractors/job.py b/extractors/job.py index 596a3ae..795617a 100644 --- a/extractors/job.py +++ b/extractors/job.py @@ -3,6 +3,8 @@ import re import importlib import sys +from utils import NoExtractorException + extrs = [ 'bandcamp' ] @@ -10,12 +12,16 @@ extrs = [ class DlJob(): - def __init__(self, url, output): - self.extr = self._find(url) + def __init__(self, url, output, extractor=None): + if extractor in extrs: + cls = self._get_class(extractor) + self.extr = cls(reg=None, url=url) + else: + self.extr = self._find(url) self.output = output self._albums = [] if not self.extr: - logging.error("No extractor found for " + url + ".") + raise NoExtractorException("No extractor found for " + url + ".") def _find(self, url): for cls in self._list_extractors(): @@ -41,6 +47,13 @@ class DlJob(): ) ] + def _get_class(self, extractor): + module = importlib.import_module('.' + extractor, __package__) + classes = self._get_classes(module) + for cls in classes: + if cls.__name__ == extractor: + return cls + def run(self): self.extr.get_albums() self.extr.download_albums(self.output) -- cgit v1.2.1