enigma2 20130314 (master) -> 20130424 (master)
[enigma2.git] / usr / lib / enigma2 / python / Plugins / Extensions / BludiscPlayer / plugin.py
1 from enigma import eServiceReference, ePicLoad
2 from Screens.Screen import Screen
3 from Screens.InfoBar import MoviePlayer
4 from Components.Sources.StaticText import StaticText
5 from Components.ActionMap import ActionMap
6 from Components.MenuList import MenuList
7 from Components.ResourceManager import resourcemanager
8 from Components.AVSwitch import AVSwitch
9 from Components.Pixmap import Pixmap
10
11 import bludiscmenu
12
13 BD_PATHS = ["/media/bludisc/","/autofs/sr0/"]
14 BD_AACS_ERRORS = {-1: _("corrupted disc"), -2: _("AACS configuration file missing"), -3: _("no matching processing key"), -4: _("no valid AACS certificate"), -5: _("AACS certificate revoked"), -6: _("MMC authentication failed")}
15
16 class BludiscMenu(Screen):
17         skin = """
18         <screen name="BludiscMenu" position="center,center" size="560,480" title="Bludisc Player">
19                         <widget name="pixmap" position="8,8" size="544,306" />
20                         <widget name="menu" position="8,320" size="544,125" scrollbarMode="showOnDemand" />
21                         <widget source="statusbar" render="Label" position="10,450" size="530,30" halign="left" valign="center" font="Regular;14" backgroundColor="#254f7497" foregroundColor="#272F97" />
22         </screen>"""
23         def __init__(self, session, bd_mountpoint = None):
24                 
25                 Screen.__init__(self, session)
26                 self.tried_bdpath = 0
27                 self.bd_mountpoint = bd_mountpoint or BD_PATHS[self.tried_bdpath]
28                 self.list = []
29                 self["menu"] = MenuList(self.list)
30                 self["statusbar"] = StaticText(_("Please wait... Loading list..."))
31                 self.session = session
32                 self.onFirstExecBegin.append(self.opened)
33                 self.picload = ePicLoad()
34                 self.picload.PictureData.get().append(self.picdecodedCB)
35                 sc = AVSwitch().getFramebufferScale()
36                 self.picload.setPara((544, 306, sc[0], sc[1], False, 1, '#ff000000'))
37                 self["pixmap"] = Pixmap()
38
39                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
40                 {
41                         "ok": self.ok,
42                         "cancel": self.exit,
43                         "red": self.exit,
44                         "green": self.ok,
45                         "yellow": self.settings,
46                 }, -1)
47
48         def opened(self):
49                 self.discinfo = bludiscmenu.getDiscinfo(self.bd_mountpoint)
50                 print 'bludiscmenu.getDiscinfo("%s") returned:' % self.bd_mountpoint, self.discinfo
51                 if isinstance(self.discinfo, dict):
52                         for idx, duration, chapters, angels, clips, title_no, title_name in self.discinfo["titles"]:
53                                 titlestring = "%d. %s (%02d:%02d:%02d), %d %s" % (title_no or idx, title_name or _("Title"), (duration / 3600), ((duration % 3600) / 60), (duration % 60), chapters, _("chapters"))
54                                 self.list.append((titlestring, idx))
55                         self["menu"].l.setList(self.list)
56                         thumbs = self.discinfo["thumbnails"]
57                         if thumbs and isinstance(thumbs, list) and isinstance(thumbs[0], tuple) and isinstance(thumbs[0][0], str):
58                                 max_x = 0
59                                 thumb_filename = thumbs[0][0]
60                                 for filename, x, y in thumbs:
61                                         if x > max_x or ( x == -1 and filename.lower().find("lg") > 0 ):
62                                                 thumb_filename = filename
63                                 thumb_path = self.bd_mountpoint+"/BDMV/META/DL/"+thumb_filename
64                                 print "decoding thumbnail:", thumb_path
65                                 self.picload.startDecode(thumb_path)
66                         if self.discinfo["di_name"]:
67                                 self.setTitle(_("Bludisc Player") + ": " + self.discinfo["di_name"])
68                         statustext =  "%i titles on %s." % (len(self.list), self.bd_mountpoint)
69                         if self.discinfo["aacs_detected"]:
70                                 statustext = "Disc is AACS MKBv %i encrypted" % self.discinfo["aacs_mkbv"]
71                                 if not self.discinfo["aacs_handled"]:
72                                         statustext += ", unable to play!"
73                                         if self.discinfo["aacs_error_code"] in BD_AACS_ERRORS:
74                                                 statustext += " (%s)" % BD_AACS_ERRORS[self.discinfo["aacs_error_code"]]
75                         if self.discinfo["bdplus_detected"] and not self.discinfo["bdplus_handled"]:
76                                 statustext += " Disc is BD+ encrypted!"
77                         self["statusbar"].text = statustext     
78                 elif self.tried_bdpath < len(BD_PATHS)-1:
79                                 self.tried_bdpath += 1
80                                 self.bd_mountpoint = BD_PATHS[self.tried_bdpath]
81                                 self.opened()
82
83         def picdecodedCB(self, picInfo = None):
84                 ptr = self.picload.getData()
85                 if ptr is not None:
86                         self["pixmap"].instance.setPixmap(ptr)
87
88         def ok(self):
89                 if type(self["menu"].getCurrent()) is type(None):
90                         self.exit()
91                         return
92                 name = self["menu"].getCurrent()[0]
93                 idx = self["menu"].getCurrent()[1]
94                 newref = eServiceReference(0x04, 0, "%s:%03d" % (self.bd_mountpoint, idx))
95                 newref.setData(1,1)
96                 newref.setName("Bludisc title %d" % idx)
97                 print "[Bludisc] play: ", name, newref.toString()               
98                 self.session.openWithCallback(self.moviefinished, BludiscPlayer, newref)
99
100         def settings(self):
101                 pass
102
103         def moviefinished(self):
104                 print "Bludisc playback finished"
105
106         def exit(self):
107                 self.close()
108
109 class BludiscPlayer(MoviePlayer):
110         def __init__(self, session, service):
111                 MoviePlayer.__init__(self, session, service)
112                 self.skinName = "MoviePlayer"
113
114         def handleLeave(self, how):
115                 self.is_closing = True
116                 if how == "ask":
117                         list = (
118                                 (_("Yes"), "quit"),
119                                 (_("No"), "continue")
120                         )
121                         from Screens.ChoiceBox import ChoiceBox
122                         self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("Stop playing this movie?"), list = list)
123                 else:
124                         self.leavePlayerConfirmed([True, how])
125
126         def showMovies(self):
127                 pass
128
129         def movieSelected(self, service):
130                 pass
131
132 def main(session, **kwargs):
133         session.open(BludiscMenu)
134
135 def autostart(reason, **kwargs):
136         resourcemanager.addResource("Bludisc", main)
137
138 from Plugins.Plugin import PluginDescriptor
139
140 def filescan(**kwargs):
141         from Components.Scanner import Scanner, ScanPath
142         return [
143                 Scanner(mimetypes = ["video/x-bluray"],
144                         paths_to_scan =
145                                 [
146                                         ScanPath(path = "BDMV", with_subdirs = False),
147                                 ],
148                         name = "Bludisc",
149                         description = _("Play Bludisc"),
150                         openfnc = filescan_open,
151                 )]
152
153 def filescan_open(list, session, **kwargs):
154         print "filescan_open", list, list[0].mimetype, list[0].path
155         if len(list) >= 1 and list[0].mimetype == "video/x-bluray":
156                 pos = list[0].path.find("BDMV")
157                 path = None
158                 if pos > 0:
159                         path = list[0].path[:pos]
160                 session.open(BludiscMenu, bd_mountpoint=path)
161                 return
162
163 def menu(menuid, **kwargs):
164         if menuid == "mainmenu":
165                 return [("Bludisc Player", main, "bludiscplayer", 47)]
166         return []
167
168 def Plugins(**kwargs):
169         return [ PluginDescriptor(name = "BludiscPlayer", description = _("Play Bludisc"), where = PluginDescriptor.WHERE_MENU, fnc = menu),
170                 PluginDescriptor(where = PluginDescriptor.WHERE_FILESCAN, fnc = filescan)]
171                 #PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart) ]