Enigma2-Plugins-{GraphMultiEPG/GraphMultiEpg.py, MediaPlayer/plugin.py, SoftwareManag...
[enigma2.git] / lib / python / Plugins / Extensions / MediaPlayer / plugin.py
old mode 100644 (file)
new mode 100755 (executable)
index c25af78..a2422be
@@ -19,9 +19,8 @@ from Components.Playlist import PlaylistIOInternal, PlaylistIOM3U, PlaylistIOPLS
 from Components.AVSwitch import AVSwitch
 from Components.Harddisk import harddiskmanager
 from Components.config import config
-from Tools.Directories import fileExists, pathExists, resolveFilename, SCOPE_CONFIG, SCOPE_PLAYLIST, SCOPE_SKIN_IMAGE
+from Tools.Directories import fileExists, pathExists, resolveFilename, SCOPE_CONFIG, SCOPE_PLAYLIST, SCOPE_CURRENT_SKIN
 from settings import MediaPlayerSettings
-from Plugins.SystemPlugins.Hotplug.plugin import hotplugNotifier
 import random
 
 class MyPlayList(PlayList):
@@ -51,7 +50,7 @@ class MediaPixmap(Pixmap):
                                        noCoverFile = value
                                        break
                if noCoverFile is None:
-                       noCoverFile = resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/no_coverArt.png")
+                       noCoverFile = resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/no_coverArt.png")
                self.noCoverPixmap = LoadPixmap(noCoverFile)
                return Pixmap.applySkin(self, desktop, screen)
 
@@ -111,7 +110,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|divx|mkv|mp4|m4a|dat|flac)", useServiceRef = True, additionalExtensions = "4098:m3u 4098:e2pls 4098:pls")
+               self.filelist = FileList(defaultDir, matchingPattern = "(?i)^.*\.(mp2|mp3|ogg|ts|m2ts|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()
@@ -123,20 +122,22 @@ 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()
 
                self.seek_target = None
+
+               from Plugins.SystemPlugins.Hotplug.plugin import hotplugNotifier
                hotplugNotifier.append(self.hotplugCB)
 
                class MoviePlayerActionMap(NumberActionMap):
@@ -148,7 +149,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")),
@@ -212,7 +212,7 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
                self.isAudioCD = False
                self.AudioCD_albuminfo = {}
                self.cdAudioTrackFiles = []
-               self.applySettings()
+               self.onShown.append(self.applySettings)
 
                self.playlistIOInternal = PlaylistIOInternal()
                list = self.playlistIOInternal.open(resolveFilename(SCOPE_CONFIG, "playlist.e2pls"))
@@ -224,7 +224,8 @@ 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+10: self.__evAudioDecodeError,
+                               iPlayableService.evUser+11: self.__evVideoDecodeError,
                                iPlayableService.evUser+12: self.__evPluginError,
                                iPlayableService.evUser+13: self["coverArt"].embeddedCoverArt
                        })
@@ -240,10 +241,14 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
                for x in self.playlist.list:
                        self.playlistIOInternal.addService(ServiceReference(x[0]))
                if self.savePlaylistOnExit:
-                       self.playlistIOInternal.save(resolveFilename(SCOPE_CONFIG, "playlist.e2pls"))
+                       try:
+                               self.playlistIOInternal.save(resolveFilename(SCOPE_CONFIG, "playlist.e2pls"))
+                       except IOError:
+                               print "couldn't save playlist.e2pls"
                if config.mediaplayer.saveDirOnExit.getValue():
                        config.mediaplayer.defaultDir.setValue(self.filelist.getCurrentDirectory())
                        config.mediaplayer.defaultDir.save()
+               from Plugins.SystemPlugins.Hotplug.plugin import hotplugNotifier
                hotplugNotifier.remove(self.hotplugCB)
                del self["coverArt"].picload
                self.close()
@@ -262,17 +267,23 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
 
        def __evUpdatedInfo(self):
                currPlay = self.session.nav.getCurrentService()
-               currenttitle = currPlay.info().getInfo(iServiceInformation.sCurrentTitle)
-               totaltitles = currPlay.info().getInfo(iServiceInformation.sTotalTitles)
-               sTitle = currPlay.info().getInfoString(iServiceInformation.sTitle)
-               print "[__evUpdatedInfo] title %d of %d (%s)" % (currenttitle, totaltitles, sTitle)
+               sTagTrackNumber = currPlay.info().getInfo(iServiceInformation.sTagTrackNumber)
+               sTagTrackCount = currPlay.info().getInfo(iServiceInformation.sTagTrackCount)
+               sTagTitle = currPlay.info().getInfoString(iServiceInformation.sTagTitle)
+               print "[__evUpdatedInfo] title %d of %d (%s)" % (sTagTrackNumber, sTagTrackCount, sTagTitle)
                self.readTitleInformation()
 
-       def __evDecodeError(self):
+       def __evAudioDecodeError(self):
+               currPlay = self.session.nav.getCurrentService()
+               sTagAudioCodec = currPlay.info().getInfoString(iServiceInformation.sTagAudioCodec)
+               print "[__evAudioDecodeError] audio-codec %s can't be decoded by hardware" % (sTagAudioCodec)
+               self.session.open(MessageBox, _("This Dreambox can't decode %s streams!") % sTagAudioCodec, 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 )
+               sTagVideoCodec = currPlay.info().getInfoString(iServiceInformation.sTagVideoCodec)
+               print "[__evVideoDecodeError] video-codec %s can't be decoded by hardware" % (sTagVideoCodec)
+               self.session.open(MessageBox, _("This Dreambox can't decode %s streams!") % sTagVideoCodec, type = MessageBox.TYPE_INFO,timeout = 20 )
 
        def __evPluginError(self):
                currPlay = self.session.nav.getCurrentService()
@@ -287,11 +298,11 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
        def readTitleInformation(self):
                currPlay = self.session.nav.getCurrentService()
                if currPlay is not None:
-                       sTitle = currPlay.info().getInfoString(iServiceInformation.sTitle)
-                       sAlbum = currPlay.info().getInfoString(iServiceInformation.sAlbum)
-                       sGenre = currPlay.info().getInfoString(iServiceInformation.sGenre)
-                       sArtist = currPlay.info().getInfoString(iServiceInformation.sArtist)
-                       sYear = currPlay.info().getInfoString(iServiceInformation.sTimeCreate)
+                       sTitle = currPlay.info().getInfoString(iServiceInformation.sTagTitle)
+                       sAlbum = currPlay.info().getInfoString(iServiceInformation.sTagAlbum)
+                       sGenre = currPlay.info().getInfoString(iServiceInformation.sTagGenre)
+                       sArtist = currPlay.info().getInfoString(iServiceInformation.sTagArtist)
+                       sYear = currPlay.info().getInfoString(iServiceInformation.sTagDate)
 
                        if sTitle == "":
                                if not self.isAudioCD:
@@ -379,7 +390,7 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
                self.updateCurrentInfo()
 
        def showAfterSeek(self):
-               self.show()
+               pass
 
        def showAfterCuesheetOperation(self):
                self.show()
@@ -659,12 +670,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()
@@ -805,6 +820,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():
@@ -820,7 +836,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
@@ -847,7 +863,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
@@ -888,7 +904,7 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarSeek, InfoBarAudioSelection, InfoB
                
        def subtitleSelection(self):
                from Screens.Subtitles import Subtitles
-               self.session.open(Subtitles)
+               self.session.open(Subtitles, self)
        
        def hotplugCB(self, dev, media_state):
                if dev == harddiskmanager.getCD():
@@ -979,7 +995,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"],
@@ -989,7 +1005,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"],
@@ -998,7 +1014,7 @@ def filescan(**kwargs):
                                        ScanPath(path = "", with_subdirs = False),
                                ],
                        name = "Music",
-                       description = "Play Music...",
+                       description = _("Play Music..."),
                        openfnc = filescan_open,
                )]
        try:
@@ -1010,7 +1026,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