def first_boot(): if gui.yes_no(message=_.SET_IPTV): try: plugin._set_settings_iptv() except: pass if gui.yes_no(message=_.SET_KODI): try: plugin._set_settings_kodi() except: pass settings.setBool(key='_first_boot', value=False)
def first_boot(): if gui.yes_no(message=_.SET_IPTV): try: plugin._set_settings_iptv() except: pass if gui.yes_no(message=_.SET_KODI): try: plugin._set_settings_kodi() except: pass query = "UPDATE `vars` SET `first_boot`='{first_boot}' WHERE profile_id={profile_id}".format(first_boot=0, profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True)
def logout(**kwargs): if not gui.yes_no(message=_.LOGOUT_YES_NO): return query = "UPDATE `vars` SET `pswd`='', `username`='' WHERE profile_id={profile_id}".format(profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) gui.refresh()
def _reset(**kwargs): if not gui.yes_no(_.PLUGIN_RESET_YES_NO): return _close() try: xbmc.executeJSONRPC( '{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":false}}}}' .format(ADDON_ID)) proxyport = settings.getInt(key='_proxyserver_port') shutil.rmtree(ADDON_PROFILE) settings.setInt(key='_proxyserver_port', value=proxyport) system, arch = get_system_arch() settings.set(key="_system", value=system) settings.set(key="_arch", value=arch) download_files() update_settings() change_icon() except: pass xbmc.executeJSONRPC( '{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":true}}}}' .format(ADDON_ID)) gui.notification(_.PLUGIN_RESET_OK) signals.emit(signals.AFTER_RESET) gui.refresh()
def _reset(**kwargs): if not gui.yes_no(_.PLUGIN_RESET_YES_NO): return _close() try: xbmc.executeJSONRPC( '{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":false}}}}' .format(ADDON_ID)) profile_settings = load_profile(profile_id=1) proxyserver_port = int(profile_settings['proxyserver_port']) system = profile_settings['system'] arch = profile_settings['arch'] shutil.rmtree(ADDON_PROFILE) directory = os.path.dirname(ADDON_PROFILE + os.sep + "images") try: if not os.path.exists(directory): os.makedirs(directory) except: pass directory = os.path.dirname(ADDON_PROFILE + os.sep + "cache") try: if not os.path.exists(directory): os.makedirs(directory) except: pass query = "UPDATE `vars` SET `arch`='{arch}', `system`='{system}', `test_running`=0, `proxyserver_port`={proxyserver_port} WHERE profile_id={profile_id}".format( arch=arch, system=system, proxyserver_port=proxyserver_port, profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) download_files() update_settings() update_prefs() except: pass xbmc.executeJSONRPC( '{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":true}}}}' .format(ADDON_ID)) gui.notification(_.PLUGIN_RESET_OK) signals.emit(signals.AFTER_RESET) gui.refresh()
def logout(delete=True, **kwargs): if delete == True: if not gui.yes_no(message=_.LOGOUT_YES_NO): return settings.remove(key='_username') settings.remove(key='_pswd') api.clear_session() api.new_session(force=True, channels=True) plugin.logged_in = api.logged_in gui.refresh()
def _reset(**kwargs): if not gui.yes_no(_.PLUGIN_RESET_YES_NO): return _close() try: xbmc.executeJSONRPC( '{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":false}}}}' .format(ADDON_ID)) shutil.rmtree(ADDON_PROFILE) except: pass xbmc.executeJSONRPC( '{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":true}}}}' .format(ADDON_ID)) gui.notification(_.PLUGIN_RESET_OK) signals.emit(signals.AFTER_RESET) gui.refresh()
def play_video(type=None, channel=None, id=None, from_beginning=0, **kwargs): from_beginning = int(from_beginning) profile_settings = load_profile(profile_id=1) properties = {} if not type and not len(unicode(type)) > 0: return False if type == 'program': properties['seekTime'] = 1 playdata = api.play_url(type=type, channel=channel, id=id, from_beginning=from_beginning) if not playdata or not check_key(playdata, 'path'): return False CDMHEADERS = { 'User-Agent': profile_settings['user_agent'], 'X_CSRFToken': profile_settings['csrf_token'], 'Cookie': playdata['license']['cookie'], } if check_key(playdata, 'license') and check_key(playdata['license'], 'triggers') and check_key(playdata['license']['triggers'][0], 'licenseURL'): item_inputstream = inputstream.Widevine( license_key = playdata['license']['triggers'][0]['licenseURL'], ) if check_key(playdata['license']['triggers'][0], 'customData'): CDMHEADERS['AcquireLicense.CustomData'] = playdata['license']['triggers'][0]['customData'] CDMHEADERS['CADeviceType'] = 'Widevine OTT client' else: item_inputstream = inputstream.MPD() itemlabel = '' label2 = '' description = '' program_image = '' program_image_large = '' duration = 0 cast = [] director = [] writer = [] credits = [] if check_key(playdata['info'], 'startTime') and check_key(playdata['info'], 'endTime'): startT = datetime.datetime.fromtimestamp((int(playdata['info']['startTime']) / 1000)) startT = convert_datetime_timezone(startT, "UTC", "UTC") endT = datetime.datetime.fromtimestamp((int(playdata['info']['endTime']) / 1000)) endT = convert_datetime_timezone(endT, "UTC", "UTC") duration = int((endT - startT).total_seconds()) if xbmc.getLanguage(xbmc.ISO_639_1) == 'nl': itemlabel = '{weekday} {day} {month} {yearhourminute} '.format(weekday=date_to_nl_dag(startT), day=startT.strftime("%d"), month=date_to_nl_maand(startT), yearhourminute=startT.strftime("%Y %H:%M")) else: itemlabel = startT.strftime("%A %d %B %Y %H:%M ").capitalize() itemlabel += " - " if check_key(playdata['info'], 'name'): itemlabel += playdata['info']['name'] label2 = playdata['info']['name'] if type == 'channel': if from_beginning == 1: properties['seekTime'] = 1 elif settings.getBool(key='ask_start_from_beginning'): if gui.yes_no(message=_.START_FROM_BEGINNING, heading=label2): properties['seekTime'] = 1 if check_key(playdata['info'], 'introduce'): description = playdata['info']['introduce'] if check_key(playdata['info'], 'picture'): program_image = playdata['info']['picture']['posters'][0] program_image_large = playdata['info']['picture']['posters'][0] query = "SELECT name FROM `channels` WHERE id='{channel}'".format(channel=channel) data = query_epg(query=query, return_result=True, return_insert=False, commit=False) if data: for row in data: label2 += " - " + row['name'] query = "UPDATE `vars` SET `stream_duration`='{stream_duration}' WHERE profile_id={profile_id}".format(stream_duration=duration, profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) listitem = plugin.Item( label = itemlabel, label2 = label2, art = { 'thumb': program_image, 'fanart': program_image_large }, info = { 'credits': credits, 'cast': cast, 'writer': writer, 'director': director, 'plot': description, 'duration': duration, 'mediatype': 'video', }, properties = properties, path = playdata['path'], headers = CDMHEADERS, inputstream = item_inputstream, ) return listitem
def _download(url, dst, dst_path, arch, md5=None): filename = url.split('/')[-1] tmp = ADDON_PROFILE + "tmp" + os.sep + "widevine" downloaded = 0 if os.path.exists(dst_path): if md5 and md5sum(dst_path) == md5: log.debug('MD5 of local file {} same. Skipping download'.format( filename)) return True elif not gui.yes_no(_.NEW_IA_VERSION): return False else: if os.path.exists(dst_path): os.remove(dst_path) from .session import Session with gui.progress(_(_.IA_DOWNLOADING_FILE, url=filename), heading=_.IA_WIDEVINE_DRM) as progress: resp = Session().get(url, stream=True) if resp.status_code != 200: raise InputStreamError( _(_.ERROR_DOWNLOADING_FILE, filename=filename)) total_length = float(resp.headers.get('content-length', 1)) with open(tmp, 'wb') as f: for chunk in resp.iter_content(chunk_size=SESSION_CHUNKSIZE): f.write(chunk) downloaded += len(chunk) downloadperc = int(downloaded) * 100 downloadperc2 = int(downloadperc) // int(total_length) percent = int(downloadperc2) if progress.iscanceled(): progress.close() resp.close() progress.update(percent) if os.path.isfile(tmp): if 'arm' in arch: with open(tmp, "rb") as encoded_file: decoded_string = base64.b64decode(encoded_file.read()) with open(dst_path, "wb") as decoded_file: decoded_file.write(decoded_string) else: with ZipFile(tmp, 'r') as zipObj: zipObj.extractall(ADDON_PROFILE + "tmp" + os.sep) if os.path.isfile(ADDON_PROFILE + "tmp" + os.sep + dst): shutil.copy(ADDON_PROFILE + "tmp" + os.sep + dst, dst_path) for file in glob.glob(ADDON_PROFILE + "tmp" + os.sep + "*"): os.remove(file) if progress.iscanceled(): return False checksum = md5sum(dst_path) if checksum != md5: if os.path.exists(dst_path): os.remove(dst_path) raise InputStreamError( _(_.MD5_MISMATCH, filename=filename, local_md5=checksum, remote_md5=md5)) return True
def play_url(self, type, channel=None, id=None, test=False, from_beginning=False): if not self.get_session(): return None profile_settings = load_profile(profile_id=1) headers = CONST_BASE_HEADERS headers.update( {'Authorization': 'Bearer ' + profile_settings['session_token']}) playdata = {'path': '', 'license': '', 'info': ''} if not test: counter = 0 while not self._abortRequested and not xbmc.Monitor( ).abortRequested() and counter < 5: profile_settings = load_profile(profile_id=1) if profile_settings['test_running'] == 0: break counter += 1 query = "UPDATE `vars` SET `last_playing`={last_playing} WHERE profile_id={profile_id}".format( last_playing=int(time.time()), profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) if self._abortRequested or xbmc.Monitor().waitForAbort(1): self._abortRequested = True break if self._abortRequested or xbmc.Monitor().abortRequested(): return playdata if type == 'channel': info_url = '{api_url}/assets/{channel}'.format( api_url=CONST_DEFAULT_API, channel=channel) else: info_url = '{api_url}/assets/{id}'.format( api_url=CONST_DEFAULT_API, id=id) play_url = info_url + '/play' playfrombeginning = False if not test: download = self.download(url=info_url, type='get', headers=headers, data=None, json_data=False, return_json=True) data = download['data'] resp = download['resp'] if not resp or not resp.status_code == 200 or not data or not check_key( data, 'id'): return playdata session_post_data = { "player": { "name": "Bitmovin", "version": "8.22.0", "capabilities": { "mediaTypes": ["DASH", "HLS", "MSSS", "Unspecified"], "drmSystems": ["Widevine"], }, "drmSystems": ["Widevine"], }, } if type == 'channel' and check_key(data, 'params') and check_key( data['params'], 'now') and check_key( data['params']['now'], 'id'): if settings.getBool(key='ask_start_from_beginning'): play_url2 = '{api_url}/assets/{id}/play'.format( api_url=CONST_DEFAULT_API, id=data['params']['now']['id']) info = data['params']['now'] download = self.download(url=play_url2, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True) data = download['data'] resp = download['resp'] if resp and resp.status_code == 200 and data and check_key( data, 'url'): if gui.yes_no(message=_.START_FROM_BEGINNING, heading=info['title']): playfrombeginning = True if self._abortRequested or xbmc.Monitor().abortRequested(): return playdata if not playfrombeginning: download = self.download(url=play_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True) data = download['data'] resp = download['resp'] if not resp or not resp.status_code == 200 or not data or not check_key( data, 'url'): return playdata if check_key(data, 'drm') and check_key(data['drm'], 'licenseUrl'): license = data['drm']['licenseUrl'] path = data['url'] if not test: real_url = "{hostscheme}://{netloc}".format( hostscheme=urlparse(path).scheme, netloc=urlparse(path).netloc) proxy_url = "http://127.0.0.1:{proxy_port}".format( proxy_port=settings.getInt(key='_proxyserver_port')) query = "UPDATE `vars` SET `stream_hostname`='{stream_hostname}' WHERE profile_id={profile_id}".format( stream_hostname=real_url, profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) playdata = {'path': path, 'license': license, 'info': info} return playdata
def play_url(self, type, channel=None, id=None, test=False, from_beginning='False'): self._session.headers = CONST_BASE_HEADERS self._session.headers.update({'Authorization': 'Bearer ' + self._session_token}) if self._debug_mode: log.debug('Executing: api.play_url') log.debug('Vars: type={type}, channel={channel}, id={id}, test={test}'.format(type=type, channel=channel, id=id, test=test)) log.debug('Request Session Headers') log.debug(self._session.headers) playdata = {'path': '', 'license': None, 'info': None} if not type or not len(unicode(type)) > 0: if self._debug_mode: log.debug('Failure executing api.play_url, no type set') log.debug('Execution Done: api.play_url') return playdata if not test: while not self._abortRequested and not xbmc.Monitor().abortRequested() and settings.getBool(key='_test_running'): settings.setInt(key='_last_playing', value=time.time()) if self._abortRequested or xbmc.Monitor().waitForAbort(1): self._abortRequested = True break if self._abortRequested or xbmc.Monitor().abortRequested(): return playdata if type == 'channel': info_url = '{api_url}/assets/{channel}'.format(api_url=CONST_DEFAULT_API, channel=channel) else: info_url = '{api_url}/assets/{id}'.format(api_url=CONST_DEFAULT_API, id=id) play_url = info_url + '/play' if not test: data = self.download(url=info_url, type="get", code=[200], data=None, json_data=False, data_return=True, return_json=True, retry=True, check_data=True, allow_redirects=True) if not data or not check_key(data, 'id'): if self._debug_mode: log.debug('Failure to retrieve expected data') log.debug('Execution Done: api.play_url') return playdata session_post_data = { "player": { "name":"Bitmovin", "version":"8.22.0", "capabilities": { "mediaTypes": ["DASH","HLS","MSSS","Unspecified"], "drmSystems": ["Widevine"], }, "drmSystems": ["Widevine"], }, } if type == 'channel' and check_key(data, 'params') and check_key(data['params'], 'now') and check_key(data['params']['now'], 'id'): play_url2 = '{api_url}/assets/{id}/play'.format(api_url=CONST_DEFAULT_API, id=data['params']['now']['id']) info = data['params']['now'] data = self.download(url=play_url2, type="post", code=[200], data=session_post_data, json_data=True, data_return=True, return_json=True, retry=True, check_data=True, allow_redirects=True) if data and check_key(data, 'url'): if not settings.getBool(key='ask_start_from_beginning') or not gui.yes_no(message=_.START_FROM_BEGINNING, heading=info['title']): data = self.download(url=play_url, type="post", code=[200], data=session_post_data, json_data=True, data_return=True, return_json=True, retry=True, check_data=True, allow_redirects=True) else: data = self.download(url=play_url, type="post", code=[200], data=session_post_data, json_data=True, data_return=True, return_json=True, retry=True, check_data=True, allow_redirects=True) else: info = data data = self.download(url=play_url, type="post", code=[200], data=session_post_data, json_data=True, data_return=True, return_json=True, retry=True, check_data=True, allow_redirects=True) else: if self._abortRequested or xbmc.Monitor().abortRequested(): return playdata data = self.download(url=play_url, type="post", code=[200], data=session_post_data, json_data=True, data_return=True, return_json=True, retry=True, check_data=True, allow_redirects=True) if not data or not check_key(data, 'url'): if self._debug_mode: log.debug('Failure to retrieve expected data') log.debug('Execution Done: api.play_url') return playdata if check_key(data, 'drm') and check_key(data['drm'], 'licenseUrl'): license = data['drm']['licenseUrl'] path = data['url'] if not test: real_url = "{hostscheme}://{netloc}".format(hostscheme=urlparse(path).scheme, netloc=urlparse(path).netloc) proxy_url = "http://127.0.0.1:{proxy_port}".format(proxy_port=settings.getInt(key='_proxyserver_port')) if self._debug_mode: log.debug('Real url: {real_url}'.format(real_url=real_url)) log.debug('Proxy url: {proxy_url}'.format(proxy_url=proxy_url)) settings.set(key='_stream_hostname', value=real_url) path = path.replace(real_url, proxy_url) playdata = {'path': path, 'license': license, 'info': info} if self._debug_mode: log.debug('Returned Playdata: {playdata}'.format(playdata=playdata)) log.debug('Execution Done: api.play_url') return playdata