diff --git a/boards/models/attachment/downloaders.py b/boards/models/attachment/downloaders.py --- a/boards/models/attachment/downloaders.py +++ b/boards/models/attachment/downloaders.py @@ -27,7 +27,7 @@ TYPE_URL_ONLY = ( class Downloader: @staticmethod def handles(url: str) -> bool: - return False + return True @staticmethod def download(url: str): @@ -61,15 +61,6 @@ class Downloader: return file -def download(url): - for downloader in Downloader.__subclasses__(): - if downloader.handles(url): - return downloader.download(url) - # If nobody of the specific downloaders handles this, use generic - # one - return Downloader.download(url) - - class YouTubeDownloader(Downloader): @staticmethod def download(url: str): @@ -93,3 +84,18 @@ class NothingDownloader(Downloader): @staticmethod def download(url: str): return None + + +DOWNLOADERS = ( + YouTubeDownloader, + NothingDownloader, + Downloader, +) + + +def download(url): + for downloader in DOWNLOADERS: + if downloader.handles(url): + return downloader.download(url) + raise Exception('No downloader supports this URL.') +