# HG changeset patch
# User neko259 <neko259@gmail.com>
# Date 2017-01-07 22:08:33
# Node ID c2aa90c2b1595d14f49fabbdcfa93d926bb1df87
# Parent  167a799feebd6c4cd0501f8a173b8a4405fbb14a

Specific order of downloaders ensures they will work as expected

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.')
+