##// END OF EJS Templates
Specific order of downloaders ensures they will work as expected
neko259 -
r1811:c2aa90c2 default
parent child Browse files
Show More
@@ -27,7 +27,7 b' TYPE_URL_ONLY = ('
27 class Downloader:
27 class Downloader:
28 @staticmethod
28 @staticmethod
29 def handles(url: str) -> bool:
29 def handles(url: str) -> bool:
30 return False
30 return True
31
31
32 @staticmethod
32 @staticmethod
33 def download(url: str):
33 def download(url: str):
@@ -61,15 +61,6 b' class Downloader:'
61 return file
61 return file
62
62
63
63
64 def download(url):
65 for downloader in Downloader.__subclasses__():
66 if downloader.handles(url):
67 return downloader.download(url)
68 # If nobody of the specific downloaders handles this, use generic
69 # one
70 return Downloader.download(url)
71
72
73 class YouTubeDownloader(Downloader):
64 class YouTubeDownloader(Downloader):
74 @staticmethod
65 @staticmethod
75 def download(url: str):
66 def download(url: str):
@@ -93,3 +84,18 b' class NothingDownloader(Downloader):'
93 @staticmethod
84 @staticmethod
94 def download(url: str):
85 def download(url: str):
95 return None
86 return None
87
88
89 DOWNLOADERS = (
90 YouTubeDownloader,
91 NothingDownloader,
92 Downloader,
93 )
94
95
96 def download(url):
97 for downloader in DOWNLOADERS:
98 if downloader.handles(url):
99 return downloader.download(url)
100 raise Exception('No downloader supports this URL.')
101
General Comments 0
You need to be logged in to leave comments. Login now