add .mov as playable extension
[enigma2.git] / lib / python / Plugins / Extensions / MediaPlayer / plugin.py
index 8477ecc17cfa2b962511c2991e0189e8a7ee2110..b0aa627495c4e90d95d9a9855e84e0a84f75c074 100644 (file)
@@ -44,6 +44,7 @@ class MediaPixmap(Pixmap):
 
        def applySkin(self, desktop, screen):
                from Tools.LoadPixmap import LoadPixmap
+               noCoverFile = None
                if self.skinAttributes is not None:
                        for (attrib, value) in self.skinAttributes:
                                if attrib == "pixmap":
@@ -82,10 +83,10 @@ class MediaPixmap(Pixmap):
        def showDefaultCover(self):
                self.instance.setPixmap(self.noCoverPixmap)
 
-       #def destroy(self):
-               #Pixmap.destroy(self)
-               #print "mediapixmap ***********+ destroy"
-               
+       def embeddedCoverArt(self):
+               print "[embeddedCoverArt] found"
+               self.coverArtFileName = "/tmp/.id3coverart"
+               self.picload.startDecode(self.coverArtFileName)
 
 class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarNotifications, InfoBarSubtitleSupport, HelpableScreen):
        ALLOW_SUSPEND = True
@@ -110,7 +111,7 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
 
                # 'None' is magic to start at the list of mountpoints
                defaultDir = config.mediaplayer.defaultDir.getValue()
-               self.filelist = FileList(defaultDir, matchingPattern = "(?i)^.*\.(mp2|mp3|ogg|ts|wav|wave|m3u|pls|e2pls|mpg|vob|avi|mkv|mp4|dat|flac)", useServiceRef = True, additionalExtensions = "4098:m3u 4098:e2pls 4098:pls")
+               self.filelist = FileList(defaultDir, matchingPattern = "(?i)^.*\.(mp2|mp3|ogg|ts|wav|wave|m3u|pls|e2pls|mpg|vob|avi|divx|mkv|mp4|m4a|dat|flac|mov)", useServiceRef = True, additionalExtensions = "4098:m3u 4098:e2pls 4098:pls")
                self["filelist"] = self.filelist
 
                self.playlist = MyPlayList()
@@ -122,15 +123,15 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
 
                self["currenttext"] = Label("")
 
-               self["artisttext"] = Label(_("Artist:"))
+               self["artisttext"] = Label(_("Artist")+':')
                self["artist"] = Label("")
-               self["titletext"] = Label(_("Title:"))
+               self["titletext"] = Label(_("Title")+':')
                self["title"] = Label("")
-               self["albumtext"] = Label(_("Album:"))
+               self["albumtext"] = Label(_("Album")+':')
                self["album"] = Label("")
-               self["yeartext"] = Label(_("Year:"))
+               self["yeartext"] = Label(_("Year")+':')
                self["year"] = Label("")
-               self["genretext"] = Label(_("Genre:"))
+               self["genretext"] = Label(_("Genre")+':')
                self["genre"] = Label("")
                self["coverArt"] = MediaPixmap()
                self["repeat"] = MultiPixmap()
@@ -147,7 +148,6 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
                                self.player.show()
                                return NumberActionMap.action(self, contexts, action)
 
-
                self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions", 
                        {
                                "ok": (self.ok, _("add file to playlist")),
@@ -223,8 +223,10 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
                self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
                        {
                                iPlayableService.evUpdatedInfo: self.__evUpdatedInfo,
-                               iPlayableService.evUser+11: self.__evDecodeError,
-                               iPlayableService.evUser+12: self.__evPluginError
+                               iPlayableService.evUser+10: self.__evAudioDecodeError,
+                               iPlayableService.evUser+11: self.__evVideoDecodeError,
+                               iPlayableService.evUser+12: self.__evPluginError,
+                               iPlayableService.evUser+13: self["coverArt"].embeddedCoverArt
                        })
 
        def doNothing(self):
@@ -266,11 +268,17 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
                print "[__evUpdatedInfo] title %d of %d (%s)" % (currenttitle, totaltitles, sTitle)
                self.readTitleInformation()
 
-       def __evDecodeError(self):
+       def __evAudioDecodeError(self):
+               currPlay = self.session.nav.getCurrentService()
+               sAudioType = currPlay.info().getInfoString(iServiceInformation.sUser+10)
+               print "[__evAudioDecodeError] audio-codec %s can't be decoded by hardware" % (sAudioType)
+               self.session.open(MessageBox, _("This Dreambox can't decode %s streams!") % sAudioType, type = MessageBox.TYPE_INFO,timeout = 20 )
+
+       def __evVideoDecodeError(self):
                currPlay = self.session.nav.getCurrentService()
                sVideoType = currPlay.info().getInfoString(iServiceInformation.sVideoType)
-               print "[__evDecodeError] video-codec %s can't be decoded by hardware" % (sVideoType)
-               self.session.open(MessageBox, _("This Dreambox can't decode %s video streams!") % sVideoType, type = MessageBox.TYPE_INFO,timeout = 20 )
+               print "[__evVideoDecodeError] video-codec %s can't be decoded by hardware" % (sVideoType)
+               self.session.open(MessageBox, _("This Dreambox can't decode %s streams!") % sVideoType, type = MessageBox.TYPE_INFO,timeout = 20 )
 
        def __evPluginError(self):
                currPlay = self.session.nav.getCurrentService()
@@ -377,7 +385,7 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
                self.updateCurrentInfo()
 
        def showAfterSeek(self):
-               self.show()
+               pass
 
        def showAfterCuesheetOperation(self):
                self.show()
@@ -481,17 +489,20 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
                        else:
                                menu.append((_("add files to playlist"), "copyfiles"))
                        menu.append((_("switch to playlist"), "playlist"))
-                       menu.append((_("delete file"), "deletefile"))
+                       if config.usage.setup_level.index >= 1: # intermediate+
+                               menu.append((_("delete file"), "deletefile"))
                else:
                        menu.append((_("switch to filelist"), "filelist"))
-                       menu.append((_("shuffle playlist"), "shuffle"))
-                       menu.append((_("Delete entry"), "deleteentry"))
                        menu.append((_("clear playlist"), "clear"))
+                       menu.append((_("Delete entry"), "deleteentry"))
+                       if config.usage.setup_level.index >= 1: # intermediate+
+                               menu.append((_("shuffle playlist"), "shuffle"))
                menu.append((_("hide player"), "hide"));
-               menu.append((_("save playlist"), "saveplaylist"));
                menu.append((_("load playlist"), "loadplaylist"));
-               menu.append((_("delete saved playlist"), "deleteplaylist"));
-               menu.append((_("Edit settings"), "settings"))
+               if config.usage.setup_level.index >= 1: # intermediate+
+                       menu.append((_("save playlist"), "saveplaylist"));
+                       menu.append((_("delete saved playlist"), "deleteplaylist"));
+                       menu.append((_("Edit settings"), "settings"))
                self.session.openWithCallback(self.menuCallback, ChoiceBox, title="", list=menu)
 
        def menuCallback(self, choice):
@@ -654,12 +665,16 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
 
        def copyDirectory(self, directory, recursive = True):
                print "copyDirectory", directory
-               filelist = FileList(directory, useServiceRef = True, isTop = True)
+               if directory == '/':
+                       print "refusing to operate on /"
+                       return
+               filelist = FileList(directory, useServiceRef = True, showMountpoints = False, isTop = True)
 
                for x in filelist.getFileList():
                        if x[0][1] == True: #isDir
                                if recursive:
-                                       self.copyDirectory(x[0][0])
+                                       if x[0][0] != directory:
+                                               self.copyDirectory(x[0][0])
                        elif filelist.getServiceRef() and filelist.getServiceRef().type == 4097:
                                self.playlist.addFile(x[0][0])
                self.playlist.updateList()
@@ -800,6 +815,7 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
        
        def playEntry(self):
                if len(self.playlist.getServiceRefList()):
+                       audio_extensions = (".mp2", ".mp3", ".wav", ".ogg", "flac", "m4a")
                        needsInfoUpdate = False
                        currref = self.playlist.getServiceRefList()[self.playlist.getCurrentIndex()]
                        if self.session.nav.getCurrentlyPlayingServiceReference() is None or currref != self.session.nav.getCurrentlyPlayingServiceReference():
@@ -815,7 +831,7 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
                                ext = text[-4:].lower()
 
                                # FIXME: the information if the service contains video (and we should hide our window) should com from the service instead 
-                               if ext not in [".mp2", ".mp3", ".wav", ".ogg", "flac"] and not self.isAudioCD:
+                               if ext not in audio_extensions and not self.isAudioCD:
                                        self.hide()
                                else:
                                        needsInfoUpdate = True
@@ -842,7 +858,7 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
                                currref = self.playlist.getServiceRefList()[idx]
                                text = currref.getPath()
                                ext = text[-4:].lower()
-                               if ext not in [".mp2", ".mp3", ".wav", ".ogg", "flac"] and not self.isAudioCD:
+                               if ext not in audio_extensions and not self.isAudioCD:
                                        self.hide()
                                else:
                                        needsInfoUpdate = True
@@ -974,7 +990,7 @@ def filescan(**kwargs):
                                        ScanPath(path = "", with_subdirs = False),
                                ],
                        name = "Movie",
-                       description = "View Movies...",
+                       description = _("View Movies..."),
                        openfnc = filescan_open,
                ),
                Scanner(mimetypes = ["video/x-vcd"],
@@ -984,7 +1000,7 @@ def filescan(**kwargs):
                                        ScanPath(path = "MPEGAV", with_subdirs = False),
                                ],
                        name = "Video CD",
-                       description = "View Video CD...",
+                       description = _("View Video CD..."),
                        openfnc = filescan_open,
                ),
                Scanner(mimetypes = ["audio/mpeg", "audio/x-wav", "application/ogg", "audio/x-flac"],
@@ -993,7 +1009,7 @@ def filescan(**kwargs):
                                        ScanPath(path = "", with_subdirs = False),
                                ],
                        name = "Music",
-                       description = "Play Music...",
+                       description = _("Play Music..."),
                        openfnc = filescan_open,
                )]
        try:
@@ -1005,7 +1021,7 @@ def filescan(**kwargs):
                                        ScanPath(path = "", with_subdirs = False),
                                ],
                        name = "Audio-CD",
-                       description = "Play Audio-CD...",
+                       description = _("Play Audio-CD..."),
                        openfnc = audioCD_open,
                ))
                return mediatypes