def playback(self, playing_file): last_callback = None cur_time = time.time() play_time = 0 while not monitor.waitForAbort(1) and self.isPlaying( ) and self.getPlayingFile() == playing_file: cur_time = time.time() play_time = self.getTime() if self._up_next and play_time >= self._up_next['time']: play_time = self.getTotalTime() self.seekTime(play_time) last_callback = None if self._callback and self._callback['type'] == 'interval' and ( not last_callback or cur_time >= last_callback + self._callback['interval']): callback = add_url_args(self._callback['callback'], _time=int(play_time)) xbmc.executebuiltin('RunPlugin({})'.format(callback)) last_callback = cur_time if self._callback: callback = add_url_args(self._callback['callback'], _time=int(play_time)) xbmc.executebuiltin('RunPlugin({})'.format(callback))
def _manifest_middleware(self, data): url = self._session.get('manifest_middleware') if not url: return data data_path = xbmc.translatePath('special://temp/proxy.manifest') with open(data_path, 'wb') as f: f.write(data.encode('utf8')) url = add_url_args(url, _data_path=data_path, _headers=json.dumps(self._headers)) log.debug('PLUGIN MANIFEST MIDDLEWARE REQUEST: {}'.format(url)) dirs, files = run_plugin(url, wait=True) if not files: raise Exception('No data returned from plugin') path = unquote_plus(files[0]) split = path.split('|') data_path = split[0] if len(split) > 1: self._plugin_headers = dict( parse_qsl(u'{}'.format(split[1]), keep_blank_values=True)) with open(data_path, 'rb') as f: data = f.read().decode('utf8') if not ADDON_DEV: remove_file(data_path) return data
def playback(self): play_time = 0 last_play_time = int(self.getTime()) last_callback = None while not monitor.waitForAbort(1) and self.isPlaying( ) and self.getPlayingFile() == self._playing_file: play_time = int(self.getTime()) diff = abs(play_time - last_play_time) last_play_time = play_time if diff > 5: #we are jumping around continue play_skips = [] for row in self._play_skips: if play_time >= row['to']: continue diff = play_time - row['from'] if diff < 0: play_skips.append(row) elif diff <= 5: self.seekTime(row['to']) self._play_skips = play_skips diff = 0 if last_callback is not None: diff = abs(play_time - last_callback) if self._callback and self._callback[ 'type'] == 'interval' and last_callback != play_time and ( last_callback is None or diff >= self._callback['interval']): callback = add_url_args(self._callback['callback'], _time=play_time) xbmc.executebuiltin('RunPlugin({})'.format(callback)) last_callback = play_time if self._callback and last_callback != play_time: # Stop playback callback callback = add_url_args(self._callback['callback'], _time=play_time) xbmc.executebuiltin('RunPlugin({})'.format(callback))
def middleware_plugin(response, url, **kwargs): path = 'special://temp/proxy.middleware' real_path = xbmc.translatePath(path) with open(real_path, 'wb') as f: f.write(response.stream.content) if ADDON_DEV: shutil.copy(real_path, real_path + '.in') url = add_url_args(url, _path=path) dirs, files = run_plugin(url, wait=True) if not files: raise Exception('No data returned from plugin') data = json.loads(unquote_plus(files[0])) with open(real_path, 'rb') as f: response.stream.content = f.read() response.headers.update(data.get('headers', {})) if ADDON_DEV: shutil.copy(real_path, real_path + '.out') remove_file(real_path)
def _plugin_request(self, url): data_path = xbmc.translatePath('special://temp/proxy.post') with open(data_path, 'wb') as f: f.write(self._post_data or b'') url = add_url_args(url, _data_path=data_path, _headers=json.dumps(self._headers)) log.debug('PLUGIN REQUEST: {}'.format(url)) dirs, files = run_plugin(url, wait=True) if not files: raise Exception('No data returned from plugin') path = unquote_plus(files[0]) split = path.split('|') url = split[0] if len(split) > 1: self._plugin_headers = dict( parse_qsl(u'{}'.format(split[1]), keep_blank_values=True)) return url