2 # To be used as simple Downloading Application by other Plugins
5 # for localized messages
8 from Components.config import config, ConfigSubsection, ConfigLocations
9 from Tools.Directories import resolveFilename, SCOPE_HDD
11 # SCOPE_HDD is not really what we want but the best we can get :-)
12 config.plugins.mediadownloader = ConfigSubsection()
13 config.plugins.mediadownloader.bookmarks = ConfigLocations(default = [resolveFilename(SCOPE_HDD)])
15 # TODO: support custom bookmark element?
17 # Download a single File
18 def download_file(session, url, to = None, askOpen = False, callback = None, \
20 """Provides a simple downloader Application"""
22 from Components.Scanner import ScanFile
23 file = ScanFile(url, autodetect = False)
25 from MediaDownloader import MediaDownloader
26 session.open(MediaDownloader, file, askOpen, to, callback)
29 def filescan_chosen(session, item):
31 from MediaDownloader import MediaDownloader
33 session.open(MediaDownloader, item[1], askOpen = True)
36 def filescan_open(items, session, **kwargs):
37 """Download a file from a given List"""
41 from Screens.ChoiceBox import ChoiceBox
42 from Tools.BoundFunction import boundFunction
44 # Create human-readable filenames
47 item.path[item.path.rfind("/")+1:].replace('%20', ' ').\
48 replace('%5F', '_').replace('%2D', '-'),
54 # And let the user choose one
55 session.openWithCallback(
56 boundFunction(filescan_chosen, session),
58 _("Which file do you want to download?"),
62 from MediaDownloader import MediaDownloader
64 session.open(MediaDownloader, items[0], askOpen = True)
66 # Return Scanner provided by this Plugin
67 def filescan(**kwargs):
68 from Components.Scanner import Scanner, ScanPath
70 # Overwrite checkFile to detect remote files
71 class RemoteScanner(Scanner):
72 def checkFile(self, file):
73 return file.path.startswith(("http://", "https://", "ftp://"))
80 ScanPath(path = "", with_subdirs = False),
83 description = _("Download..."),
84 openfnc = filescan_open,
88 def Plugins(**kwargs):
89 from Plugins.Plugin import PluginDescriptor
93 name = "MediaDownloader",
94 where = PluginDescriptor.WHERE_FILESCAN,