Merge branch 'vuplus_experimental' of code.vuplus.com:/opt/repository/dvbapp into...
[vuplus_dvbapp] / lib / python / Plugins / Extensions / WebBrowser / plugin.py
index 1985c06..48cea21 100644 (file)
@@ -16,9 +16,15 @@ from urllib import quote, unquote_plus, unquote
 from urllib2 import Request, URLError, urlopen as urlopen2
 from httplib import HTTPConnection, CannotSendRequest, BadStatusLine, HTTPException
 
 from urllib2 import Request, URLError, urlopen as urlopen2
 from httplib import HTTPConnection, CannotSendRequest, BadStatusLine, HTTPException
 
+from Screens.Screen import Screen
+from Screens.ChoiceBox import ChoiceBox
+from Screens.MessageBox import MessageBox
+from Screens.DefaultWizard import DefaultWizard
+from Screens.InfoBarGenerics import InfoBarNotifications
+
 from Components.Button import Button
 from Components.Label import Label
 from Components.Button import Button
 from Components.Label import Label
-from Components.Pixmap import Pixmap
+from Components.Pixmap import Pixmap, MovingPixmap
 from Components.Language import language
 from Components.Sources.List import List
 from Components.ConfigList import ConfigListScreen
 from Components.Language import language
 from Components.Sources.List import List
 from Components.ConfigList import ConfigListScreen
@@ -27,13 +33,10 @@ from Components.ActionMap import NumberActionMap, ActionMap
 from Components.ServiceEventTracker import ServiceEventTracker
 from Components.config import config, ConfigSelection, getConfigListEntry, ConfigSlider
 
 from Components.ServiceEventTracker import ServiceEventTracker
 from Components.config import config, ConfigSelection, getConfigListEntry, ConfigSlider
 
-from Screens.Screen import Screen
-from Screens.ChoiceBox import ChoiceBox
-from Screens.MessageBox import MessageBox
-from Screens.DefaultWizard import DefaultWizard
-from Screens.InfoBarGenerics import InfoBarNotifications
+from Tools.Directories import resolveFilename, SCOPE_PLUGINS
+from Tools.LoadPixmap import LoadPixmap
 
 
-from enigma import eTimer, eServiceReference, iPlayableService, fbClass, eRCInput, eConsoleAppContainer
+from enigma import eTimer, eServiceReference, iPlayableService, fbClass, eRCInput, eConsoleAppContainer, getDesktop, ePicLoad
 
 HTTPConnection.debuglevel = 1
 
 
 HTTPConnection.debuglevel = 1
 
@@ -88,10 +91,14 @@ def wb_islock():
        return lock
 
 class VuPlayer(Screen, InfoBarNotifications):
        return lock
 
 class VuPlayer(Screen, InfoBarNotifications):
+       size = getDesktop(0).size()
+       wb_bgr = resolveFilename(SCOPE_PLUGINS, "Extensions/WebBrowser/mp_wb_background.png")
+       wb_btn = resolveFilename(SCOPE_PLUGINS, "Extensions/WebBrowser/mp_wb_buttons.png")
+       position_params = size.width() > 750 and (620, wb_bgr, wb_btn) or (480, wb_bgr, wb_btn)
        skin =  """
        skin =  """
-               <screen name="VuPlayer" flags="wfNoBorder" position="center,620" size="455,53" title="VuPlayer" backgroundColor="transparent">
-                       <ePixmap pixmap="Vu_HD/mp_wb_background.png" position="0,0" zPosition="-1" size="455,53" />
-                       <ePixmap pixmap="Vu_HD/icons/mp_wb_buttons.png" position="40,23" size="30,13" alphatest="on" />
+               <screen name="VuPlayer" flags="wfNoBorder" position="center,%d" size="455,53" title="VuPlayer" backgroundColor="transparent">
+                       <ePixmap pixmap="%s" position="0,0" zPosition="-1" size="455,53" />
+                       <ePixmap pixmap="%s" position="40,23" size="30,13" alphatest="on" />
 
                        <widget source="session.CurrentService" render="PositionGauge" position="80,25" size="220,10" zPosition="2" pointer="skin_default/position_pointer.png:540,0" transparent="1" foregroundColor="#20224f">
                                <convert type="ServicePosition">Gauge</convert>
 
                        <widget source="session.CurrentService" render="PositionGauge" position="80,25" size="220,10" zPosition="2" pointer="skin_default/position_pointer.png:540,0" transparent="1" foregroundColor="#20224f">
                                <convert type="ServicePosition">Gauge</convert>
@@ -105,7 +112,8 @@ class VuPlayer(Screen, InfoBarNotifications):
                                <convert type="ServicePosition">Length</convert>
                        </widget>
                </screen>
                                <convert type="ServicePosition">Length</convert>
                        </widget>
                </screen>
-               """
+               """ % position_params
+
        PLAYER_IDLE     = 0
        PLAYER_PLAYING  = 1
        PLAYER_PAUSED   = 2
        PLAYER_IDLE     = 0
        PLAYER_PLAYING  = 1
        PLAYER_PAUSED   = 2
@@ -143,6 +151,7 @@ class VuPlayer(Screen, InfoBarNotifications):
                self.onClose.append(self.__onClose)
                self.doPlay()
 
                self.onClose.append(self.__onClose)
                self.doPlay()
 
+
        def __onClose(self):
                self.session.nav.stopService()
 
        def __onClose(self):
                self.session.nav.stopService()
 
@@ -164,8 +173,9 @@ class VuPlayer(Screen, InfoBarNotifications):
                self.hidetimer.start(5000)
 
        def doExit(self):
                self.hidetimer.start(5000)
 
        def doExit(self):
+               message = "Stop playing this movie?"
                list = ((_("Yes"), "y"), (_("No, but play video again"), "n"),)
                list = ((_("Yes"), "y"), (_("No, but play video again"), "n"),)
-               self.session.openWithCallback(self.cbDoExit, ChoiceBox, title=_("Stop playing this movie?"), list = list)
+               self.session.openWithCallback(self.cbDoExit, ChoiceBox, title=_(message), list = list)
 
        def cbDoExit(self, answer):
                answer = answer and answer[1]
 
        def cbDoExit(self, answer):
                answer = answer and answer[1]
@@ -240,6 +250,29 @@ std_headers = {
 }
 
 class VuPlayerLauncher:
 }
 
 class VuPlayerLauncher:
+       QUALITY_CODE =  {
+                        '5': 'FLV 224p'
+                       ,'6': 'FLV 270p'
+                       ,'34':'FLV 360p'
+                       ,'35':'FLV 480p'
+                       ,'18':'MP4 360p'
+                       ,'22':'MP4 720p'
+                       ,'37':'MP4 1080p'
+                       ,'38':'MP4 2304p'
+                       ,'83':'MP4-3D 240p'
+                       ,'82':'MP4-3D 360p'
+                       ,'85':'MP4-3D 520p'
+                       ,'84':'MP4-3D 720p'
+                       ,'43':'WebM 360p'
+                       ,'44':'WebM 480p'
+                       ,'45':'WebM 720p'
+                       ,'46':'WebM 1080p'
+                       ,'100':'WebM-3D 360p'
+                       ,'101':'WebM-3D 480p'
+                       ,'102':'WebM-3D 720p'
+                       ,'13':'3GP 0.5'
+                       ,'17':'3GP 2.0'
+                       }
        def getVideoUrl(self, video_id):
                video_url = None
 
        def getVideoUrl(self, video_id):
                video_url = None
 
@@ -284,31 +317,72 @@ class VuPlayerLauncher:
                else:
                        tmp_fmtUrlDATA = videoinfo['fmt_url_map'][0].split(',')
                for fmtstring in tmp_fmtUrlDATA:
                else:
                        tmp_fmtUrlDATA = videoinfo['fmt_url_map'][0].split(',')
                for fmtstring in tmp_fmtUrlDATA:
+                       num_fmtid = 0
                        if videoinfo.has_key('url_encoded_fmt_stream_map'):
                                (fmturl, fmtid) = fmtstring.split('&itag=')
                        if videoinfo.has_key('url_encoded_fmt_stream_map'):
                                (fmturl, fmtid) = fmtstring.split('&itag=')
+                               try:
+                                       num_fmtid = int(fmtid)
+                               except: 
+                                       try:
+                                               num_fmtid = int(fmtid[:fmtid.find(',')])
+                                       except: pass
+                                       pass
+
                                if fmturl.find("url=") !=-1:
                                        fmturl = fmturl.replace("url=","")
                        else:
                                (fmtid,fmturl) = fmtstring.split('|')
                        if VIDEO_FMT_PRIORITY_MAP.has_key(fmtid):
                                video_fmt_map[VIDEO_FMT_PRIORITY_MAP[fmtid]] = { 'fmtid': fmtid, 'fmturl': unquote_plus(fmturl) }
                                if fmturl.find("url=") !=-1:
                                        fmturl = fmturl.replace("url=","")
                        else:
                                (fmtid,fmturl) = fmtstring.split('|')
                        if VIDEO_FMT_PRIORITY_MAP.has_key(fmtid):
                                video_fmt_map[VIDEO_FMT_PRIORITY_MAP[fmtid]] = { 'fmtid': fmtid, 'fmturl': unquote_plus(fmturl) }
-                       fmt_infomap[int(fmtid)] = unquote_plus(fmturl)
-               print "got",sorted(fmt_infomap.iterkeys())
-               if video_fmt_map and len(video_fmt_map):
-                       video_url = video_fmt_map[sorted(video_fmt_map.iterkeys())[0]]['fmturl'].split(';')[0]
-                       #print "found best available video format:",video_fmt_map[sorted(video_fmt_map.iterkeys())[0]]['fmtid']
-                       #print "found best available video url:",video_url
-               return video_url
+                       if num_fmtid:
+                               fmt_infomap[num_fmtid] = unquote_plus(fmturl)
+               print "fmtinfomap :",sorted(fmt_infomap.iterkeys())
+       
+               video_url_list = []
+               if video_fmt_map:
+                       idx = 0
+                       sorted_fmt_keys = sorted(video_fmt_map.iterkeys())
+                       for x in video_fmt_map:
+                               try:
+                                       videofmt    = video_fmt_map[sorted_fmt_keys[idx]]
+                                       video_url   = videofmt['fmturl'].split(';')[0]
+                                       quality_str = self.qCode2String(videofmt['fmtid'])
+                                       #print "detected video : quality [%s], url [%s]" % (quality_str, video_url)
+                                       if video_url and quality_str:
+                                               video_url_list.append((quality_str, video_url))
+                                               print "added quality [%s], url [%s]" % (quality_str, video_url)
+                               except Exception, msg: print "Error >>", msg
+                               idx = idx + 1
+               return video_url_list
+
+       def qCode2String(self, qcode):
+               qstr = None
+               try:
+                       qstr = self.QUALITY_CODE[qcode]
+               except: pass 
+               #print "quality : code[%s], str[%s]" % (qcode, qstr)
+               return qstr
 
        def run(self, tubeid, session, service):
 
        def run(self, tubeid, session, service):
+               self.session = session
+               self.service = service
                try:
                try:
-                       myurl = self.getVideoUrl(tubeid)
-                       print "Playing URL", myurl
-                       if myurl is None:
+                       self.url_list = self.getVideoUrl(tubeid)
+                       if self.url_list is None or len(self.url_list) == 0:
                                session.open(MessageBox, _("Sorry, video is not available!"), MessageBox.TYPE_INFO)
                                session.open(MessageBox, _("Sorry, video is not available!"), MessageBox.TYPE_INFO)
+                               wb_unlock()
                                return
                                return
-                       myreference = eServiceReference(4097, 0, myurl)
-                       session.open(VuPlayer, myreference, service)
+                       titlemsg = "Please, choice video quality.\nFor smooth playback depends on network conditions."
+                       self.session.openWithCallback(self.cbSelectedQuality, ChoiceBox, title=_(titlemsg), list = self.url_list)
+               except Exception, msg:
+                       wb_unlock()
+                       print "Error >>", msg
+
+       def cbSelectedQuality(self, choice):
+               try:
+                       print "selected [%s] : [%s]" % (choice[0], choice[1])
+                       myreference = eServiceReference(4097, 0, choice[1])
+                       self.session.open(VuPlayer, myreference, self.service)
                except Exception, msg:
                        wb_unlock()
                        print "Error >>", msg
                except Exception, msg:
                        wb_unlock()
                        print "Error >>", msg
@@ -363,10 +437,10 @@ class VuPlayerService:
                        tmp = data.split("?")
                        print tmp # ['http://www.youtube.com/watch', 'v=BpThu778qB4&feature=related']
                        service = self.session.nav.getCurrentlyPlayingServiceReference()
                        tmp = data.split("?")
                        print tmp # ['http://www.youtube.com/watch', 'v=BpThu778qB4&feature=related']
                        service = self.session.nav.getCurrentlyPlayingServiceReference()
-                       if len(tmp) == 2 and tmp[0] == "http://www.youtube.com/watch":
+                       if len(tmp) and tmp[0] == "http://www.youtube.com/watch":
                                tmp = tmp[1].split("&")
                                print tmp # ['v=BpThu778qB4', 'feature=related']
                                tmp = tmp[1].split("&")
                                print tmp # ['v=BpThu778qB4', 'feature=related']
-                               if len(tmp) == 2:
+                               if len(tmp):
                                        tmp = tmp[0].split("=")
                                        print tmp # ['v', 'BpThu778qB4']
                                        if len(tmp) == 2 and tmp[0] == "v":
                                        tmp = tmp[0].split("=")
                                        print tmp # ['v', 'BpThu778qB4']
                                        if len(tmp) == 2 and tmp[0] == "v":
@@ -405,28 +479,32 @@ class VuPlayerService:
 
 class BrowserLauncher(ConfigListScreen, Screen):
        skin=   """
 
 class BrowserLauncher(ConfigListScreen, Screen):
        skin=   """
-               <screen name="BrowserLauncher" position="center,center" size="309,498" title="Web Browser">
-                       <ePixmap pixmap="Vu_HD/buttons/red.png" position="4,0" size="40,40" alphatest="on" />
-                       <ePixmap pixmap="Vu_HD/buttons/green.png" position="154,0" size="40,40" alphatest="on" />
+               <screen position="center,center" size="623,300" title="Web Browser">
+                       <ePixmap pixmap="skin_default/buttons/red.png" position="10,0" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/green.png" position="158,0" size="140,40" alphatest="on" />
 
 
-                       <widget source="key_red" render="Label" position="30,0" zPosition="1" size="125,30" font="Regular;20" halign="center" valign="center" transparent="1" />
-                       <widget source="key_green" render="Label" position="180,0" zPosition="1" size="125,30" font="Regular;20" halign="center" valign="center" transparent="1" />
+                       <widget source="key_red" render="Label" position="10,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
+                       <widget source="key_green" render="Label" position="158,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
 
                        <widget name="config" position="0,50" size="309,100" scrollbarMode="showOnDemand" />
 
                        <widget name="config" position="0,50" size="309,100" scrollbarMode="showOnDemand" />
-                       <ePixmap pixmap="Vu_HD/rc_wb_desc.png" position="0,150" size="309,296" alphatest="on" />
-                       <widget name="info" position="0,455" size="309,50" font="Regular;18" halign="center" foregroundColor="blue" transparent="1" />
+                       <ePixmap pixmap="rc_wb_desc.png" position="312,5" size="309,296" alphatest="on" />
+                       <widget name="info" position="0,180" size="309,50" font="Regular;18" halign="center" foregroundColor="#a08500" transparent="1" />
                </screen>
                """
 
        def __init__(self, session): 
                Screen.__init__(self, session)
                </screen>
                """
 
        def __init__(self, session): 
                Screen.__init__(self, session)
+               
+
                 self.session = session
                self.list = []
                ConfigListScreen.__init__(self, self.list)
 
                self.browser_root = "/usr/bin"
                self.browser_name = "arora"
                 self.session = session
                self.list = []
                ConfigListScreen.__init__(self, self.list)
 
                self.browser_root = "/usr/bin"
                self.browser_name = "arora"
-               self.conf_file = "/usr/lib/enigma2/python/Plugins/Extensions/WebBrowser/settings.conf"
+
+               from Tools.Directories import resolveFilename, SCOPE_PLUGINS
+               self.conf_file = resolveFilename(SCOPE_PLUGINS, "Extensions/WebBrowser/settings.conf")
                self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions", ],
                 {      "red": self.keyCancel,
                        "green": self.keyGo,
                self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions", "WizardActions", "ColorActions", "SetupActions", ],
                 {      "red": self.keyCancel,
                        "green": self.keyGo,
@@ -549,30 +627,29 @@ class BrowserLauncher(ConfigListScreen, Screen):
                        self.conf_mouse = self.mouse_list[0][0]
                self.mouse = ConfigSelection(default = self.conf_mouse, choices = self.mouse_list)
                self.list.append(getConfigListEntry(_('Mouse'), self.mouse))            
                        self.conf_mouse = self.mouse_list[0][0]
                self.mouse = ConfigSelection(default = self.conf_mouse, choices = self.mouse_list)
                self.list.append(getConfigListEntry(_('Mouse'), self.mouse))            
-
+               
                if self.conf_keyboard == "" or self.getHandlerName(self.conf_keyboard) is None:
                        self.conf_keyboard = self.keyboard_list[0][0]
                self.keyboard = ConfigSelection(default = self.conf_keyboard, choices = self.keyboard_list)
                self.list.append(getConfigListEntry(_('Keyboard'), self.keyboard))
 
                if self.conf_keyboard == "" or self.getHandlerName(self.conf_keyboard) is None:
                        self.conf_keyboard = self.keyboard_list[0][0]
                self.keyboard = ConfigSelection(default = self.conf_keyboard, choices = self.keyboard_list)
                self.list.append(getConfigListEntry(_('Keyboard'), self.keyboard))
 
-               if self.conf_alpha == "":
-                       self.conf_alpha = "255"
-               self.alpha = ConfigSlider(default = int(self.conf_alpha), increment = 10, limits = (0, 255))
-               self.list.append(getConfigListEntry(_("Alpha Value"), self.alpha))
-
                if self.conf_keymap == "":
                        self.conf_keymap = self.getLanguage()
                if self.conf_keymap == "":
                        self.conf_keymap = self.getLanguage()
-               self.lang_list = [("en", "English"), ("de", "German")]
+               self.lang_list = [("rc_en", "English(RC)"), ("rc_ch", "German(RC)"), ("en", "English"), ("ch", "German")]
                self.langs = ConfigSelection(default = self.conf_keymap, choices = self.lang_list)
                self.langs = ConfigSelection(default = self.conf_keymap, choices = self.lang_list)
-               self.list.append(getConfigListEntry(_("Language"), self.langs))
+               self.list.append(getConfigListEntry(_("    - Type"), self.langs))
 
 
+               if self.conf_alpha == "":
+                       self.conf_alpha = "255"
+               self.alpha = ConfigSlider(default = int(self.conf_alpha), increment = 10, limits = (0, 255))
+               self.list.append(getConfigListEntry(_("Alpha Value"), self.alpha))
                self["config"].list = self.list
                self["config"].l.setList(self.list)
 
        def getLanguage(self, lang=language.getLanguage()):
                if self.current_lang_idx == 1:
                self["config"].list = self.list
                self["config"].l.setList(self.list)
 
        def getLanguage(self, lang=language.getLanguage()):
                if self.current_lang_idx == 1:
-                       return "de"
-               return "en"
+                       return "rc_ch"
+               return "rc_en"
 
        def makeHandlerList(self, data):
                n = ""
 
        def makeHandlerList(self, data):
                n = ""
@@ -668,8 +745,13 @@ class BrowserLauncher(ConfigListScreen, Screen):
                        mouse_cmd = "export QWS_MOUSE_PROTO=LinuxInput:/dev/input/%s; " % (str(mouse_param))
 
                keymap_param = ""
                        mouse_cmd = "export QWS_MOUSE_PROTO=LinuxInput:/dev/input/%s; " % (str(mouse_param))
 
                keymap_param = ""
-               if self.langs.value == "de":
+               if self.langs.value == "ch":
+                       keymap_param = ":keymap=/usr/share/keymaps/vuplus/ch.qmap"
+               elif self.langs.value == "rc_ch":
                        keymap_param = ":keymap=/usr/share/keymaps/vuplus/de.qmap"
                        keymap_param = ":keymap=/usr/share/keymaps/vuplus/de.qmap"
+               elif self.langs.value == "rc_en":
+                       keymap_param = ":keymap=/usr/share/keymaps/vuplus/us.qmap"
+
                kbd_cmd = "export QWS_KEYBOARD=LinuxInput:/dev/input/%s%s; " % (str(keyboard_param), keymap_param)
 
                cmd = "%s%s%s%s" % (extra_cmd, kbd_cmd, mouse_cmd, browser_cmd)
                kbd_cmd = "export QWS_KEYBOARD=LinuxInput:/dev/input/%s%s; " % (str(keyboard_param), keymap_param)
 
                cmd = "%s%s%s%s" % (extra_cmd, kbd_cmd, mouse_cmd, browser_cmd)
@@ -693,7 +775,7 @@ class BrowserLauncher(ConfigListScreen, Screen):
                self.saveConfig()
                self.info.setText("Starting Webbrowser. Please wait...")
                if self.lock == False:
                self.saveConfig()
                self.info.setText("Starting Webbrowser. Please wait...")
                if self.lock == False:
-                       if self.langs.value == "de":
+                       if self.langs.value == "ch" or self.langs.value == "rc_ch":
                                language.activateLanguageIndex(1)
                        else:
                                language.activateLanguageIndex(0)
                                language.activateLanguageIndex(1)
                        else:
                                language.activateLanguageIndex(0)