Example #1
0
    def add_cloud_bt_task(self, source_url):
        """从服务器上获取种子, 并建立离线下载任务

        source_url - BT 种子在服务器上的绝对路径, 或者是磁链的地址.
        """

        def check_vcode(info, error=None):
            if error or not info:
                return
            if "task_id" in info or info["error_code"] == 0:
                self.reload()
            elif info["error_code"] == -19:
                vcode_dialog = VCodeDialog(self, self.app, info)
                response = vcode_dialog.run()
                vcode_input = vcode_dialog.get_vcode()
                vcode_dialog.destroy()
                if response != Gtk.ResponseType.OK:
                    return
                gutil.async_call(
                    pcs.cloud_add_bt_task,
                    self.app.cookie,
                    self.app.tokens,
                    source_url,
                    save_path,
                    selected_idx,
                    file_sha1,
                    info["vcode"],
                    vcode_input,
                    callback=check_vcode,
                )
            else:
                self.app.toast(_("Error: {0}").format(info["error_msg"]))

        self.check_first()
        folder_browser = FolderBrowserDialog(self, self.app, _("Save to.."))
        response = folder_browser.run()
        if response != Gtk.ResponseType.OK:
            folder_browser.destroy()
            return
        save_path = folder_browser.get_path()
        folder_browser.destroy()

        bt_browser = BTBrowserDialog(self, self.app, _("Choose.."), source_url, save_path)
        response = bt_browser.run()
        selected_idx, file_sha1 = bt_browser.get_selected()
        bt_browser.destroy()
        if response != Gtk.ResponseType.OK or not selected_idx:
            return
        gutil.async_call(
            pcs.cloud_add_bt_task,
            self.app.cookie,
            self.app.tokens,
            source_url,
            save_path,
            selected_idx,
            file_sha1,
            callback=check_vcode,
        )
Example #2
0
    def add_cloud_bt_task(self, source_url, save_path=None):
        '''从服务器上获取种子, 并建立离线下载任务

        source_url - BT 种子在服务器上的绝对路径, 或者是磁链的地址.
        save_path  - 要保存到的路径, 如果为None, 就会弹出目录选择的对话框
        '''
        def check_vcode(info, error=None):
            if error or not info:
                logger.error('CloudPage.check_vcode: %s, %s' % (info, error))
                return
            if info.get('error_code', -1) != 0:
                logger.error('CloudPage.check_vcode: %s, %s' % (info, error))

            if 'task_id' in info or info['error_code'] == 0:
                self.reload()
            elif info['error_code'] == -19:
                vcode_dialog = VCodeDialog(self, self.app, info)
                response = vcode_dialog.run()
                vcode_input = vcode_dialog.get_vcode()
                vcode_dialog.destroy()
                if response != Gtk.ResponseType.OK:
                    return
                gutil.async_call(pcs.cloud_add_bt_task, self.app.cookie,
                                 self.app.tokens, source_url, save_path,
                                 selected_idx, file_sha1, info['vcode'],
                                 vcode_input, callback=check_vcode)
            else:
                self.app.toast(_('Error: {0}').format(info['error_msg']))

        self.check_first()

        if not save_path:
            folder_browser = FolderBrowserDialog(self, self.app, _('Save to..'))
            response = folder_browser.run()
            save_path = folder_browser.get_path()
            folder_browser.destroy()
            if response != Gtk.ResponseType.OK:
                return
        if not save_path:
            return

        bt_browser = BTBrowserDialog(self, self.app, _('Choose..'),
                                     source_url, save_path)
        response = bt_browser.run()
        selected_idx, file_sha1 = bt_browser.get_selected()
        bt_browser.destroy()
        if response != Gtk.ResponseType.OK or not selected_idx:
            return
        gutil.async_call(pcs.cloud_add_bt_task, self.app.cookie,
                         self.app.tokens, source_url, save_path, selected_idx,
                         file_sha1, callback=check_vcode)
        self.app.blink_page(self.app.cloud_page)
Example #3
0
    def add_cloud_bt_task(self, source_url):
        '''从服务器上获取种子, 并建立离线下载任务

        source_url - BT 种子在服务器上的绝对路径, 或者是磁链的地址.
        '''
        def check_vcode(info, error=None):
            if error or not info:
                print('Error in check_vcode:', info, Error)
                return
            if 'task_id' in info or info['error_code'] == 0:
                self.reload()
            elif info['error_code'] == -19:
                vcode_dialog = VCodeDialog(self, self.app, info)
                response = vcode_dialog.run()
                vcode_input = vcode_dialog.get_vcode()
                vcode_dialog.destroy()
                if response != Gtk.ResponseType.OK:
                    return
                gutil.async_call(
                    pcs.cloud_add_bt_task, self.app.cookie,
                    self.app.tokens, source_url, save_path,
                    selected_idx, file_sha1, info['vcode'], vcode_input,
                    callback=check_vcode)
            else:
                print('Unknown error info:', info)
                self.app.toast(_('Error: {0}').format(info['error_msg']))

        self.check_first()
        folder_browser = FolderBrowserDialog(
                self, self.app, _('Save to..'))
        response = folder_browser.run()
        if response != Gtk.ResponseType.OK:
            folder_browser.destroy()
            return
        save_path = folder_browser.get_path()
        folder_browser.destroy()

        bt_browser = BTBrowserDialog(
                self, self.app, _('Choose..'), source_url, save_path)
        response = bt_browser.run()
        selected_idx, file_sha1 = bt_browser.get_selected()
        bt_browser.destroy()
        if response != Gtk.ResponseType.OK or not selected_idx:
            return
        gutil.async_call(
            pcs.cloud_add_bt_task, self.app.cookie, self.app.tokens,
            source_url, save_path, selected_idx, file_sha1,
            callback=check_vcode)
Example #4
0
    def add_cloud_bt_task(self, source_url, save_path=None):
        '''从服务器上获取种子, 并建立离线下载任务

        source_url - BT 种子在服务器上的绝对路径, 或者是磁链的地址.
        save_path  - 要保存到的路径, 如果为None, 就会弹出目录选择的对话框
        '''
        def check_vcode(info, error=None):
            if error or not info:
                return
            if 'task_id' in info or info['error_code'] == 0:
                self.reload()
            elif info['error_code'] == -19:
                vcode_dialog = VCodeDialog(self, self.app, info)
                response = vcode_dialog.run()
                vcode_input = vcode_dialog.get_vcode()
                vcode_dialog.destroy()
                if response != Gtk.ResponseType.OK:
                    return
                gutil.async_call(pcs.cloud_add_bt_task,
                                 self.app.cookie,
                                 self.app.tokens,
                                 source_url,
                                 save_path,
                                 selected_idx,
                                 file_sha1,
                                 info['vcode'],
                                 vcode_input,
                                 callback=check_vcode)
            else:
                self.app.toast(_('Error: {0}').format(info['error_msg']))

        self.check_first()

        if not save_path:
            folder_browser = FolderBrowserDialog(self, self.app,
                                                 _('Save to..'))
            response = folder_browser.run()
            save_path = folder_browser.get_path()
            folder_browser.destroy()
            if response != Gtk.ResponseType.OK:
                return
        if not save_path:
            return

        bt_browser = BTBrowserDialog(self, self.app, _('Choose..'), source_url,
                                     save_path)
        response = bt_browser.run()
        selected_idx, file_sha1 = bt_browser.get_selected()
        bt_browser.destroy()
        if response != Gtk.ResponseType.OK or not selected_idx:
            return
        gutil.async_call(pcs.cloud_add_bt_task,
                         self.app.cookie,
                         self.app.tokens,
                         source_url,
                         save_path,
                         selected_idx,
                         file_sha1,
                         callback=check_vcode)
        self.app.blink_page(self.app.cloud_page)