Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mikf
GitHub Repository: mikf/gallery-dl
Path: blob/master/gallery_dl/downloader/__init__.py
8935 views
1
# -*- coding: utf-8 -*-
2
3
# Copyright 2015-2021 Mike Fährmann
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License version 2 as
7
# published by the Free Software Foundation.
8
9
"""Downloader modules"""
10
11
modules = [
12
"http",
13
"text",
14
"ytdl",
15
]
16
17
18
def find(scheme):
19
"""Return downloader class suitable for handling the given scheme"""
20
try:
21
return _cache[scheme]
22
except KeyError:
23
pass
24
25
cls = None
26
if scheme == "https":
27
scheme = "http"
28
if scheme in modules: # prevent unwanted imports
29
try:
30
module = __import__(scheme, globals(), None, None, 1)
31
except ImportError:
32
pass
33
else:
34
cls = module.__downloader__
35
36
if scheme == "http":
37
_cache["http"] = _cache["https"] = cls
38
else:
39
_cache[scheme] = cls
40
return cls
41
42
43
# --------------------------------------------------------------------
44
# internals
45
46
_cache = {}
47
48