def download(item, download_path, provider, on_update_download=None): url = item['download_info']['url'] headers = None if provider.download_requires_auth: headers = {"Authorization":"Bearer %s"%provider.get_access_tokens()['access_token']} try: req = Request(url, None, headers, download_path = download_path, on_update_download = on_update_download) req.request() except Exception as e: ErrorReport.handle_exception(e) return False return req.success
def _select_stream_format(self, driveid, item_driveid=None, item_id=None): url = None self._progress_dialog.update(0, self._addon.getLocalizedString(32009)) self._provider.configure(self._account_manager, driveid) self.get_item(driveid, item_driveid, item_id) request = Request('https://drive.google.com/get_video_info', urllib.urlencode({'docid' : item_id}), {'authorization': 'Bearer %s' % self._provider.get_access_tokens()['access_token']}) response_text = request.request() response_params = dict(urlparse.parse_qsl(response_text)) self._progress_dialog.close() if Utils.get_safe_value(response_params, 'status', '') == 'ok': fmt_list = Utils.get_safe_value(response_params, 'fmt_list', '').split(',') stream_formats = [self._addon.getLocalizedString(32015)] for fmt in fmt_list: data = fmt.split('/') stream_formats.append(data[1]) select = self._dialog.select(self._addon.getLocalizedString(32016), stream_formats, 8000) if select > 0: data = fmt_list[select-1].split('/') fmt_stream_map = Utils.get_safe_value(response_params, 'fmt_stream_map', '').split(',') for fmt in fmt_stream_map: stream_data = fmt.split('|') if stream_data[0] == data[0]: url = stream_data[1] break if url: cookie_header = '' for cookie in request.response_cookies: if cookie_header: cookie_header += ';' cookie_header += cookie.name + '=' + cookie.value; url += '|cookie=' + urllib.quote(cookie_header) return url;
def _select_stream_format(self, driveid, item_driveid=None, item_id=None, auto=False): url = None if not auto: self._progress_dialog.update(0, self._addon.getLocalizedString(32009)) self._provider.configure(self._account_manager, driveid) self._provider.get_item(item_driveid, item_id) request = Request( 'https://drive.google.com/get_video_info', urllib.parse.urlencode({'docid': item_id}), { 'authorization': 'Bearer %s' % self._provider.get_access_tokens()['access_token'] }) response_text = request.request() response_params = dict(urllib.parse.parse_qsl(response_text)) if not auto: self._progress_dialog.close() if Utils.get_safe_value(response_params, 'status', '') == 'ok': fmt_list = Utils.get_safe_value(response_params, 'fmt_list', '').split(',') stream_formats = [] for fmt in fmt_list: data = fmt.split('/') stream_formats.append(data[1]) stream_formats.append(self._addon.getLocalizedString(32015)) Logger.debug('Stream formats: %s' % Utils.str(stream_formats)) select = -1 if auto: select = self._auto_select_stream(stream_formats) else: select = self._dialog.select( self._addon.getLocalizedString(32016), stream_formats, 8000, 0) Logger.debug('Selected: %s' % Utils.str(select)) if select == -1: self._cancel_operation = True elif select != len(stream_formats) - 1: data = fmt_list[select].split('/') fmt_stream_map = Utils.get_safe_value(response_params, 'fmt_stream_map', '').split(',') for fmt in fmt_stream_map: stream_data = fmt.split('|') if stream_data[0] == data[0]: url = stream_data[1] break if url: cookie_header = '' for cookie in request.response_cookies: if cookie_header: cookie_header += ';' cookie_header += cookie.name + '=' + cookie.value url += '|cookie=' + urllib.parse.quote(cookie_header) return url