4.3.0r12
[enigma2.git] / usr / lib / enigma2 / python / Plugins / Extensions / MediaCenter / MediaBrowserFile.py
1 from enigma import eServiceReference
2 from Components.FileList import FileList
3
4 from Tools.Log import Log
5 from MediaBrowser import MediaBrowser, MediaBrowserList
6 from MediaCore import MediaCore, mediaCore
7
8 class MediaBrowserFileList(FileList, MediaBrowserList):
9         filter_audio = "(?i)^.*\.(mp2|mp3|ogg|wav|wave|m4a|flac)"
10         filter_video = "(?i)^.*\.(mpg|vob|avi|divx|m4v|mkv|mp4|dat|mov|ts)"
11         filter_media = "(?i)^.*\.(mp2|mp3|ogg|ts|wav|wave|m3u|pls|e2pls|mpg|vob|avi|divx|m4v|mkv|mp4|m4a|dat|flac|mov)"
12
13         def __init__(self, type):
14                 MediaBrowserList.__init__(self, type)
15                 if self._type == MediaCore.TYPE_AUDIO:
16                         self.filter = MediaBrowserFileList.filter_audio
17                 elif self._type == MediaCore.TYPE_VIDEO:
18                         self.filter = MediaBrowserFileList.filter_video
19                 else:
20                         self.filter = MediaBrowserFileList.filter_media
21
22                 defaultDir = None
23                 FileList.__init__(self, defaultDir, matchingPattern=self.filter, useServiceRef=True)
24
25         def canDescend(self):
26                 return self.canDescent()
27
28         def descend(self):
29                 return self.descent()
30
31         def getItemName(self, item=None):
32                 if item is None:
33                         return self.getFilename()
34                 else:
35                         if isinstance(item, str):
36                                 return item
37                         elif isinstance(item, eServiceReference):
38                                 return item.getPath()
39                         elif isinstance(item[0], eServiceReference):
40                                 return item[0].getPath()
41                 return None
42
43         def getMeta(self, item):
44                 return None
45
46 class MediaBrowserFile(MediaBrowser):
47         FEATURE_FILTER_TYPE = True
48         FEATURE_ADD_FOLDER = True
49         TITLE = _("File Browser")
50
51         def __init__(self, session, type=type, player=None):
52                 MediaBrowser.__init__(self, session, type, player=player)
53                 self._setList(MediaBrowserFileList(type))
54
55         def addFolderToPlaylist(self, folder, recursive=True):
56                 if folder == '/':
57                         Log.w("refusing to operate on /")
58                         return False
59                 filelist = FileList(folder, matchingPattern=self._list.filter, useServiceRef=True, showMountpoints=False, isTop=True)
60                 for x in filelist.getFileList():
61                         if x[0][1] == True: #isDir
62                                 if recursive:
63                                         if x[0][0] != folder:
64                                                 self.addFolderToPlaylist(x[0][0])
65                         else:
66                                 self.addToPlaylist(x[0][0])
67
68                 return True
69
70 mediaCore.registerBrowser(MediaBrowserFile, _("Filesystem"), MediaCore.TYPE_AUDIO_VIDEO)