2 # To be used as simple Downloading Application by other Plugins
5 from Components.config import config, ConfigSubsection, ConfigLocations
6 from Tools.Directories import resolveFilename, SCOPE_HDD
8 # SCOPE_HDD is not really what we want but the best we can get :-)
9 config.plugins.mediadownloader = ConfigSubsection()
10 config.plugins.mediadownloader.bookmarks = ConfigLocations(default = [resolveFilename(SCOPE_HDD)])
12 # TODO: support custom bookmark element?
14 # Download a single File
15 def download_file(session, url, to = None, askOpen = False, callback = None, \
17 """Provides a simple downloader Application"""
19 from Components.Scanner import ScanFile
20 file = ScanFile(url, autodetect = False)
22 from MediaDownloader import MediaDownloader
23 session.open(MediaDownloader, file, askOpen, to, callback)
26 def filescan_chosen(session, item):
28 from MediaDownloader import MediaDownloader
30 session.open(MediaDownloader, item[1], askOpen = True)
33 def filescan_open(items, session, **kwargs):
34 """Download a file from a given List"""
38 from Screens.ChoiceBox import ChoiceBox
39 from Tools.BoundFunction import boundFunction
41 # Create human-readable filenames
44 item.path[item.path.rfind("/")+1:].replace('%20', ' ').\
45 replace('%5F', '_').replace('%2D', '-'),
51 # And let the user choose one
52 session.openWithCallback(
53 boundFunction(filescan_chosen, session),
55 _("Which file do you want to download?"),
59 from MediaDownloader import MediaDownloader
61 session.open(MediaDownloader, items[0], askOpen = True)
63 # Return Scanner provided by this Plugin
64 def filescan(**kwargs):
65 from Components.Scanner import Scanner, ScanPath
67 # Overwrite checkFile to detect remote files
68 class RemoteScanner(Scanner):
69 def checkFile(self, file):
70 return file.path.startswith(("http://", "https://", "ftp://"))
77 ScanPath(path = "", with_subdirs = False),
80 description = "Download...",
81 openfnc = filescan_open,
85 def Plugins(**kwargs):
86 from Plugins.Plugin import PluginDescriptor
90 name="MediaDownloader",
91 where = PluginDescriptor.WHERE_FILESCAN,