support for a final post-destroy value
[enigma2.git] / lib / python / Components / Scanner.py
index 6acdecc89b41ce25d3cda1576c2c456ac3faa036..813c09f896884301254512a67ee334d126746e60 100644 (file)
@@ -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:
@@ -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)