replace some sUser with more readable code
[enigma2.git] / lib / python / Plugins / Extensions / DVDPlayer / plugin.py
index 101166bb74ba0a17588f8fd0aa050e3c6fbdc54b..f433ce6b3606d2dbfa5464c4947e10bb15383e2b 100644 (file)
@@ -1,10 +1,8 @@
 from os import path as os_path, remove as os_remove, listdir as os_listdir, system
-from time import strftime
-from enigma import eTimer, iPlayableService, eServiceCenter, iServiceInformation, eServiceReference, iServiceKeys
+from enigma import eTimer, iPlayableService, iServiceInformation, eServiceReference, iServiceKeys
 from Screens.Screen import Screen
 from Screens.MessageBox import MessageBox
 from Screens.ChoiceBox import ChoiceBox
-from Screens.InputBox import InputBox
 from Screens.HelpMenu import HelpableScreen
 from Screens.InfoBarGenerics import InfoBarSeek, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarShowHide, InfoBarNotifications
 from Components.ActionMap import ActionMap, NumberActionMap, HelpableActionMap
@@ -12,11 +10,8 @@ from Components.Label import Label
 from Components.FileList import FileList
 from Components.ServiceEventTracker import ServiceEventTracker, InfoBarBase
 from Components.config import config
-from Components.ProgressBar import ProgressBar
-from ServiceReference import ServiceReference
 from Tools.Directories import pathExists, fileExists
 
-import random
 import servicedvd # load c++ part of dvd player plugin
 
 lastpath = ""
@@ -56,8 +51,7 @@ class FileBrowser(Screen):
                                self.close(filename[0:-9])
                if self["filelist"].canDescent(): # isDir
                        self["filelist"].descent()
-                       pathname = self["filelist"].getCurrentDirectory()
-                       print self["filelist"].getFilename()
+                       pathname = self["filelist"].getCurrentDirectory() or ""
                        if fileExists(pathname+"VIDEO_TS.IFO"):
                                print "dvd structure found, trying to open..."
                                self.close(pathname)
@@ -224,7 +218,7 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                config.seek.stepwise_repeat.value = self.saved_config_seek_stepwise_repeat
                config.seek.on_pause.value = self.saved_config_seek_on_pause
 
-       def __init__(self, session, args = None):
+       def __init__(self, session, dvd_device = None, args = None):
                Screen.__init__(self, session)
                InfoBarBase.__init__(self)
                InfoBarNotifications.__init__(self)
@@ -324,11 +318,17 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
 
                self.onClose.append(self.__onClose)
 
-               if fileExists("/dev/cdroms/cdrom0"):
-                       print "physical dvd found (/dev/cdroms/cdrom0)"
-                       self.physicalDVD = True
+               if dvd_device:
+                               self.dvd_device = dvd_device
+                               self.physicalDVD = True
                else:
-                       self.physicalDVD = False
+                       if fileExists("/dev/cdroms/cdrom0"):
+                               print "physical dvd found (/dev/cdroms/cdrom0)"
+                               self.dvd_device = "/dev/cdroms/cdrom0"
+                               self.physicalDVD = True
+                       else:
+                               self.dvd_device = None
+                               self.physicalDVD = False
 
                self.onFirstExecBegin.append(self.showFileBrowser)
                self.service = None
@@ -424,14 +424,14 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                        self.doShow()
 
        def __chapterUpdated(self):
-               self.currentChapter = self.service.info().getInfo(iServiceInformation.sUser+8)
-               self.totalChapters = self.service.info().getInfo(iServiceInformation.sUser+80)
+               self.currentChapter = self.service.info().getInfo(iServiceInformation.sCurrentChapter)
+               self.totalChapters = self.service.info().getInfo(iServiceInformation.sTotalChapters)
                self.setChapterLabel()
                print "__chapterUpdated: %d/%d" % (self.currentChapter, self.totalChapters)
 
        def __titleUpdated(self):
-               self.currentTitle = self.service.info().getInfo(iServiceInformation.sUser+9)
-               self.totalTitles = self.service.info().getInfo(iServiceInformation.sUser+90)
+               self.currentTitle = self.service.info().getInfo(iServiceInformation.sCurrentTitle)
+               self.totalTitles = self.service.info().getInfo(iServiceInformation.sTotalTitles)
                self.setChapterLabel()
                print "__titleUpdated: %d/%d" % (self.currentTitle, self.totalTitles)
                if not self.in_menu:
@@ -442,7 +442,10 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                #self.__osdSubtitleInfoAvail()
 
        def askLeavePlayer(self):
-               self.session.openWithCallback(self.exitCB, ChoiceBox, title=_("Leave DVD Player?"), list=[(_("Exit"), "exit"), (_("Return to file browser"), "browser"), (_("Continue playing"), "play")])
+               if self.physicalDVD:
+                       self.session.openWithCallback(self.exitCB, ChoiceBox, title=_("Leave DVD Player?"), list=[(_("Continue playing"), "play"), (_("Exit"), "exit")])
+               else:
+                       self.session.openWithCallback(self.exitCB, ChoiceBox, title=_("Leave DVD Player?"), list=[(_("Continue playing"), "play"), (_("Return to file browser"), "browser"), (_("Exit"), "exit")])
 
        def nextAudioTrack(self):
                if self.service:
@@ -517,13 +520,16 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
 
        def showFileBrowser(self):
                if self.physicalDVD:
-                       self.session.openWithCallback(self.DVDdriveCB, MessageBox, text=_("Do you want to play DVD in drive?"), timeout=5 )
+                       if self.dvd_device == "/dev/cdroms/cdrom0":
+                               self.session.openWithCallback(self.DVDdriveCB, MessageBox, text=_("Do you want to play DVD in drive?"), timeout=5 )
+                       else:
+                               self.DVDdriveCB(True)
                else:
                        self.session.openWithCallback(self.FileBrowserClosed, FileBrowser)
        
        def DVDdriveCB(self, answer):
                if answer == True:
-                       self.FileBrowserClosed("/dev/cdroms/cdrom0")
+                       self.FileBrowserClosed(self.dvd_device)
                else:
                        self.session.openWithCallback(self.FileBrowserClosed, FileBrowser)
 
@@ -550,6 +556,8 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                        if answer[1] == "browser":
                                #TODO check here if a paused dvd playback is already running... then re-start it...
                                #else
+                               if self.service:
+                                       self.service = None
                                self.showFileBrowser()
                        else:
                                pass
@@ -588,7 +596,6 @@ class DVDPlayer(Screen, InfoBarBase, InfoBarNotifications, InfoBarSeek, InfoBarP
                        self.show()
 
        def createSummary(self):
-               print "DVDCreateSummary"
                return DVDSummary
 
 #override some InfoBarSeek functions
@@ -607,5 +614,39 @@ def menu(menuid, **kwargs):
        return []
 
 from Plugins.Plugin import PluginDescriptor
+
+#TODO add *.iso to filescanner and ask when more than one iso file is found
+
+def filescan_open(list, session, **kwargs):
+       for x in list:
+               splitted = x.path.split('/')
+               print "splitted", splitted
+               if len(splitted) > 2:
+                       if splitted[1] == 'autofs':
+                               session.open(DVDPlayer, "/dev/%s" %(splitted[2]))
+                               return
+                       else:
+                               print "splitted[0]", splitted[1]
+
+def filescan(**kwargs):
+       from Components.Scanner import Scanner, ScanPath
+
+       # Overwrite checkFile to only detect local
+       class LocalScanner(Scanner):
+               def checkFile(self, file):
+                       return fileExists(file.path)
+
+       return \
+               LocalScanner(mimetypes = None,
+                       paths_to_scan =
+                               [
+                                       ScanPath(path = "video_ts", with_subdirs = False),
+                               ],
+                       name = "DVD",
+                       description = "Play DVD",
+                       openfnc = filescan_open,
+               )
+
 def Plugins(**kwargs):
-       return [PluginDescriptor(name = "DVDPlayer", description = "Play DVDs", where = PluginDescriptor.WHERE_MENU, fnc = menu)]
+       return [PluginDescriptor(name = "DVDPlayer", description = "Play DVDs", where = PluginDescriptor.WHERE_MENU, fnc = menu),
+                       PluginDescriptor(where = PluginDescriptor.WHERE_FILESCAN, fnc = filescan)]