diff --git a/Pipfile b/Pipfile index 9a64d88..e9db80a 100644 --- a/Pipfile +++ b/Pipfile @@ -11,3 +11,4 @@ twine = "*" sphinx = "*" sphinx-rtd-theme = "*" radon = "*" +"flake8" = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 4b319ea..12ad9c7 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "f182f386e6ad648cfa47633b4e6b6e48511e18e06eb0f602c6d0b2c449e57ca7" + "sha256": "457dc98718285d0b6166dc6acec90e416c6578bc88d2ecc12337a38848c863f3" }, "pipfile-spec": 6, "requires": {}, @@ -176,6 +176,7 @@ "sha256:859996073f341f2670741b51ec1e67a01da142831aa1fdc6242dbf88dffbe661", "sha256:a796a115208f5c03b18f332f7c11729812c8c3ded6c46319c59b53efd3819da8" ], + "index": "pypi", "version": "==3.7.7" }, "flake8-polyfill": { diff --git a/anime_downloader/sites/anime.py b/anime_downloader/sites/anime.py index 4916da3..46b2076 100644 --- a/anime_downloader/sites/anime.py +++ b/anime_downloader/sites/anime.py @@ -7,6 +7,7 @@ from bs4 import BeautifulSoup import os import logging import copy +import importlib from anime_downloader.sites.exceptions import AnimeDLError, NotFoundError from anime_downloader import util @@ -92,6 +93,24 @@ class Anime: def factory(cls, sitename: str): return cls.subclasses[sitename] + @classmethod + def new_anime(cls, sitename: str): + """ + new_anime is a factory which returns the anime class corresposing to + `sitename` + + Returns + ------- + subclass of Anime + """ + module = importlib.import_module( + 'anime_downloader.sites.{}'.format(sitename) + ) + for c in dir(module): + if issubclass(c, cls): + return c + raise ImportError("Cannot find subclass of {}".format(cls)) + def get_data(self): """ get_data is called inside the :code:`__init__` of