From c4fb7fda5b1b6bb22db1f517f71cf393f68c6a9b Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 15 Aug 2020 14:07:15 +0200 Subject: Initial commit --- extractors/job.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 extractors/job.py (limited to 'extractors/job.py') diff --git a/extractors/job.py b/extractors/job.py new file mode 100644 index 0000000..ce44e9a --- /dev/null +++ b/extractors/job.py @@ -0,0 +1,47 @@ +import logging +import re +import importlib +import sys + +extrs = [ + 'bandcamp' +] + + +class DlJob(): + + def __init__(self, url, output): + self.extr = self._find(url) + self.output = output + self._albums = [] + if not self.extr: + logging.error(url + " is not supported") + sys.exit(1) + + def _find(self, url): + for cls in self._list_extractors(): + match = cls.pattern.match(url) + if match: + return cls(match, url) + + def _list_extractors(self): + for extr in iter(extrs): + module = importlib.import_module('.'+extr, __package__) + yield from self._add_module(module) + + def _add_module(self, module): + classes = self._get_classes(module) + for cls in classes: + cls.pattern = re.compile(cls.pattern) + return classes + + def _get_classes(self, module): + return [ + cls for cls in module.__dict__.values() if ( + hasattr(cls, "pattern") and cls.__module__ == module.__name__ + ) + ] + + def run(self): + self.extr.get_albums() + self.extr.download_albums(self.output) -- cgit v1.2.1