use choicebox instead of own menu
[enigma2-plugins.git] / orfat / src / ORFonDemand.py
1 # -*- coding: utf-8 -*-
2 # ORF.at onDemand streaming module by AliAbdul\r
3 from Components.ActionMap import ActionMap\r
4 from Components.MenuList import MenuList
5 from Plugins.Extensions.VlcPlayer.VlcServerConfig import vlcServerConfig
6 from Screens.ChoiceBox import ChoiceBox\r
7 from Screens.Screen import Screen\r
8 from Screens.MessageBox import MessageBox\r
9 from Tools.Directories import fileExists\r
10 from twisted.web.client import getPage\r
11 \r
12 ##########################################################
13
14 main_url = "http://ondemand.orf.at"
15
16 ##########################################################\r
17 \r
18 class ORFMain(Screen):\r
19         skin = """\r
20         <screen position="100,130" size="520,320" title="ORF.at onDemand" >\r
21                 <widget name="list" position="10,10" size="500,300" scrollbarMode="showOnDemand" />\r
22         </screen>"""\r
23 \r
24         def __init__(self, session):\r
25                 Screen.__init__(self, session)
26                 \r
27                 self.session = session  
28                 self.urls = []
29                 \r
30                 self["list"] = MenuList([])
31                 \r
32                 self["actions"] = ActionMap(["OkCancelActions"], {"ok": self.okClicked, "cancel": self.close}, -1)
33                 \r
34                 self.onLayoutFinish.append(self.downloadList)
35 \r
36         def okClicked(self):\r
37                 if len(self.urls) > 0:
38                         idx = self["list"].getSelectedIndex()
39                         self.session.open(ORFSub, main_url+self.urls[idx])\r
40 \r
41         def downloadList(self):\r
42                 getPage(main_url+"/news/player.php?id=zib").addCallback(self.downloadListCallback).addErrback(self.downloadListError)\r
43 \r
44         def downloadListCallback(self, html=""):
45                 list = []
46                 if html.__contains__('class="list"'):
47                         idx = html.index('class="list"')
48                         html = html[idx:]\r
49                         while html.__contains__('href="'):
50                                 idx = html.index('href="')
51                                 html = html[idx+6:]
52                                 idx = html.index('">')
53                                 url = html[:idx]
54                                 self.urls.append(url)
55                                 html = html[idx+2:]
56                                 idx = html.index('</a>')
57                                 name = html[:idx]
58                                 list.append(name)
59                                 html = html[idx:]
60                 self["list"].setList(list)\r
61 \r
62         def downloadListError(self, error=""):
63                 print str(error)\r
64                 self.session.open(MessageBox, "Fehler beim Verbindungsversuch!", MessageBox.TYPE_ERROR)
65
66 ##########################################################\r
67 \r
68 class ORFSub(Screen):\r
69         skin = """\r
70         <screen position="100,130" size="520,320" title="ORF.at onDemand" >\r
71                 <widget name="list" position="10,10" size="500,300" scrollbarMode="showOnDemand" />\r
72         </screen>"""\r
73 \r
74         def __init__(self, session, url):\r
75                 Screen.__init__(self, session)
76                 \r
77                 self.session = session
78                 self.url = url  
79                 self.urls = []
80                 \r
81                 self["list"] = MenuList([])
82                 \r
83                 self["actions"] = ActionMap(["OkCancelActions"], {"ok": self.okClicked, "cancel": self.close}, -1)
84                 \r
85                 self.onLayoutFinish.append(self.downloadList)
86 \r
87         def okClicked(self):
88                 if len(self.urls) > 0:
89                         idx = self["list"].getSelectedIndex()
90                         movie = self.urls[idx]
91                         serverList = vlcServerConfig.getServerlist()
92                         if len(serverList) == 0:
93                                 self.session.open(MessageBox, "Kein Server im vlc-Plugin konfiguriert!", MessageBox.TYPE_ERROR)
94                         elif len(serverList) == 1:
95                                 serverList[0].play(self.session, movie, self["list"].getCurrent())
96                         else:
97                                 list = []
98                                 for x in serverList:
99                                         list.append((x.getName(), x))
100                                 self.session.openWithCallback(self.serverChosen, ChoiceBox, title="Waehle den vlc-Server...", list=list)
101
102         def serverChosen(self, server):
103                 if server is not None:
104                         server[1].play(self.session, self.urls[self["list"].getSelectedIndex()], self["list"].getCurrent())\r
105 \r
106         def downloadList(self):\r
107                 getPage(self.url).addCallback(self.downloadListCallback).addErrback(self.downloadListError)\r
108 \r
109         def downloadListCallback(self, html=""):
110                 list = []
111                 while html.__contains__("javascript:jumpToClip('"):
112                         idx = html.index("javascript:jumpToClip('")
113                         html = html[idx+23:]
114                         idx = html.index('&offset')
115                         url = html[:idx]
116                         self.urls.append(url)
117                         idx = html.index('">')
118                         html = html[idx+2:]
119                         idx = html.index("<a/>")
120                         list.append(html[:idx])
121                 self["list"].setList(list)\r
122 \r
123         def downloadListError(self, error=""):
124                 print str(error)\r
125                 self.session.open(MessageBox, "Fehler beim Verbindungsversuch!", MessageBox.TYPE_ERROR)