X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/fdb15fdd11d88b73900badf092cf2db0e8d3aabf..4c1d3d2f5cf39f72bf85041a6ba6665350ea742e:/lib/python/Components/Scanner.py diff --git a/lib/python/Components/Scanner.py b/lib/python/Components/Scanner.py index 860918c0..813c09f8 100644 --- a/lib/python/Components/Scanner.py +++ b/lib/python/Components/Scanner.py @@ -2,28 +2,30 @@ from Plugins.Plugin import PluginDescriptor from Components.PluginComponent import plugins from os import path as os_path, walk as os_walk -from string import lower -from mimetypes import guess_type +from mimetypes import guess_type, add_type -def getExtension(file): - p = file.rfind('.') - if p == -1: - ext = "" - else: - ext = file[p+1:] - - return lower(ext) +add_type("application/x-debian-package", ".ipk") +add_type("application/ogg", ".ogg") +add_type("audio/x-flac", ".flac") +add_type("application/x-dream-package", ".dmpkg") +add_type("application/x-dream-image", ".nfi") +add_type("video/MP2T", ".ts") +add_type("video/x-dvd-iso", ".iso") def getType(file): (type, _) = guess_type(file) if type is None: - # Detect some mimetypes unknown to dm7025 - # TODO: do mimetypes.add_type once should be better - ext = getExtension(file) - if ext == "ipk": - return "application/x-debian-package" - elif ext == "ogg": - return "application/ogg" + # Detect some unknown types + if file[-12:].lower() == "video_ts.ifo": + return "video/x-dvd" + + p = file.rfind('.') + if p == -1: + return None + ext = file[p+1:].lower() + + if ext == "dat" and file[-11:-6].lower() == "avseq": + return "video/x-vcd" return type class Scanner: @@ -72,7 +74,7 @@ class ScanFile: def __init__(self, path, mimetype = None, size = None, autodetect = True): self.path = path if mimetype is None and autodetect: - (self.mimetype, _) = guess_type(path) + self.mimetype = getType(path) else: self.mimetype = mimetype self.size = size @@ -112,12 +114,13 @@ def scanDevice(mountpoint): # ...then remove with_subdir=False when same path exists # with with_subdirs=True - for p in set(paths_to_scan): + for p in paths_to_scan: if p.with_subdirs == True and ScanPath(path=p.path) in paths_to_scan: paths_to_scan.remove(ScanPath(path=p.path)) - # convert to list - paths_to_scan = list(paths_to_scan) + from Components.Harddisk import harddiskmanager + blockdev = mountpoint.rstrip("/").rsplit('/',1)[-1] + error, blacklisted, removable, is_cdrom, partitions, medium_found = harddiskmanager.getBlockDevInfo(blockdev) # now scan the paths for p in paths_to_scan: @@ -125,7 +128,11 @@ def scanDevice(mountpoint): for root, dirs, files in os_walk(path): for f in files: - sfile = ScanFile(os_path.join(root, f)) + path = os_path.join(root, f) + if is_cdrom and path.endswith(".wav") and path[-13:-6] == ("/track-"): + sfile = ScanFile(path,"audio/x-cda") + else: + sfile = ScanFile(path) for s in scanner: s.handleFile(res, sfile)