Пример #1
0
    def handle_login_dialog_status(self, *kwargs):
        # When load finished
        if str(self.webview.get_load_status()
               ) == "<enum WEBKIT_LOAD_FINISHED of type WebKitLoadStatus>":
            # Show current URL in terminal
            url = self.webview.get_property('uri')
            print "current url>>> ", url

            # Hide an element
            if 'https://api.weibo.com/oauth2/authorize' in url:
                self.webview.execute_script(
                    'document.getElementsByClassName("WB_btn_pass")[0].style.display="None"'
                )

            elif 'http://music.163.com/back/weibo?error' in url:
                self.close()
            elif 'http://music.163.com/back/weibo?state=' in url:
                # load cookie
                cookie = {}
                with open(get_cookie_file(), 'r') as f:
                    for line in f.readlines():
                        if "music.163.com" in line:
                            line = line.split()
                            cookie[line[5]] = line[6]
                nplayer.cookies = cookie
                nplayer.save_uid_and_cookies()
                print 'login-success emit from LoginDialog'
                event_manager.emit("login-success")
                self.close()
    def __init__(self, url, enable_plugins=False, cookie=get_cookie_file()):
        super(BaseWebView, self).__init__(cookie)

        # Init objects
        self._player = neteasecloud_music_player
        self._player_interface = player_interface
        #self._ttp_download = ttp_download

        class External(object):
            NeteaseCloudMusic = self._player

        self.external = External()

        # Disable webkit plugins
        settings = self.get_settings()
        settings.set_property('enable-plugins', enable_plugins)
        self.set_settings(settings)

        # Load URI
        if url:
            self.load_uri(url)

        # Javascriptcore context
        #self.js_context = jscore.JSContext(
                #self.get_main_frame().get_global_context()).globalObject
        #self._player.__class__.js_context = self.js_context

         #Set connect signal
        self.connect("window-object-cleared", self.on_webview_object_cleared)
        self.connect("script-alert", self.on_script_alert)
        self.connect("console-message", self.on_console_message)
        self.connect("resource-load-failed", self.on_resouse_load_failed)
        self.connect("load-progress-changed", self.on_webview_progress_changed)
        self.connect("load-finished", self.on_webview_load_finished)
Пример #3
0
    def __init__(self, url, enable_plugins=False, cookie=get_cookie_file()):
        super(BaseWebView, self).__init__(cookie)

        # Init objects
        self._player = neteasecloud_music_player
        self._player_interface = player_interface

        #self._ttp_download = ttp_download

        class External(object):
            NeteaseCloudMusic = self._player

        self.external = External()

        # Disable webkit plugins
        settings = self.get_settings()
        settings.set_property('enable-plugins', enable_plugins)
        self.set_settings(settings)

        # Load URI
        if url:
            self.load_uri(url)

        # Javascriptcore context
        #self.js_context = jscore.JSContext(
        #self.get_main_frame().get_global_context()).globalObject
        #self._player.__class__.js_context = self.js_context

        #Set connect signal
        self.connect("window-object-cleared", self.on_webview_object_cleared)
        self.connect("script-alert", self.on_script_alert)
        self.connect("console-message", self.on_console_message)
        self.connect("resource-load-failed", self.on_resouse_load_failed)
        self.connect("load-progress-changed", self.on_webview_progress_changed)
        self.connect("load-finished", self.on_webview_load_finished)
    def handle_login_dialog_status(self, *kwargs):
        # When load finished
        if str(self.webview.get_load_status()) == "<enum WEBKIT_LOAD_FINISHED of type WebKitLoadStatus>":
            # Show current URL in terminal
            url = self.webview.get_property('uri')
            print "current url>>> ", url

            # Hide an element
            if 'https://api.weibo.com/oauth2/authorize' in url:
                self.webview.execute_script('document.getElementsByClassName("WB_btn_pass")[0].style.display="None"')

            elif 'http://music.163.com/back/weibo?error' in url:
                self.close()
            elif 'http://music.163.com/back/weibo?state=' in url:
                # load cookie
                cookie = {}
                with open(get_cookie_file(), 'r') as f:
                    for line in f.readlines():
                        if "music.163.com" in line:
                            line = line.split()
                            cookie[line[5]] = line[6]
                nplayer.cookies = cookie
                nplayer.save_cookie(cookie)
                print 'login-success emit from LoginDialog'
                event_manager.emit("login-success")
                self.close()