def check_first(): profile_settings = load_profile(profile_id=1) if not check_key(profile_settings, 'setup_complete'): if gui.yes_no(message=_.DISABLE_EROTICA) == False: settings.setBool(key='disableErotica', value=False) else: settings.setBool(key='disableErotica', value=True) if gui.yes_no(message=_.MINIMAL_CHANNELS) == False: settings.setBool(key='minimalChannels', value=False) else: settings.setBool(key='minimalChannels', value=True) if gui.yes_no(message=_.DISABLE_REGIONAL) == False: settings.setBool(key='disableRegionalChannels', value=False) else: settings.setBool(key='disableRegionalChannels', value=True) if PROVIDER_NAME == 'kpn': if gui.yes_no(message=_.HOME_CONNECTION) == True: settings.setBool(key='homeConnection', value=True) else: settings.setBool(key='homeConnection', value=False) profile_settings['setup_complete'] = 1 save_profile(profile_id=1, profile=profile_settings)
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(**kwargs): if not gui.yes_no(message=_.LOGOUT_YES_NO): return profile_settings = load_profile(profile_id=1) profile_settings['pswd'] = '' profile_settings['username'] = '' save_profile(profile_id=1, profile=profile_settings) gui.refresh()
def reset_settings(**kwargs): if not gui.yes_no(_.PLUGIN_RESET_YES_NO): return files = [ 'profile.json', 'prefs.json', 'order.json', 'radio_prefs.json', 'radio_order.json' ] for file in files: try: os.remove(os.path.join(ADDON_PROFILE, file)) except: pass
def remove_group(type, name, **kwargs): if not gui.yes_no(_.REMOVE_GROUP + '?'): return groups = load_file(type + '_groups.json', ext=False, isJSON=True) if not groups: groups = [] else: groups = list(groups) groups.remove(name) write_file(type + '_groups.json', data=groups, ext=False, isJSON=True) xbmc.executeJSONRPC( '{"jsonrpc":"2.0","id":1,"method":"GUI.ActivateWindow","params":{"window":"videos","parameters":["plugin://' + str(ADDON_ID) + '/?_=groups_menu&type=' + str(type) + '"]}}')
def _reset(**kwargs): if not gui.yes_no(_.PLUGIN_RESET_YES_NO): return _close() try: method = 'Addons.SetAddonEnabled' json_rpc(method, {"addonid": ADDON_ID, "enabled": "false"}) remove_dir(directory="cache", ext=False) remove_dir(directory="tmp", ext=False) for file in glob.glob(os.path.join(ADDON_PROFILE, "stream*")): remove_file(file=file, ext=True) for file in glob.glob(os.path.join(ADDON_PROFILE, "*.json")): remove_file(file=file, ext=True) for file in glob.glob(os.path.join(ADDON_PROFILE, "*.xml")): remove_file(file=file, ext=True) if not os.path.isdir(os.path.join(ADDON_PROFILE, "cache")): os.makedirs(os.path.join(ADDON_PROFILE, "cache")) if not os.path.isdir(os.path.join(ADDON_PROFILE, "tmp")): os.makedirs(os.path.join(ADDON_PROFILE, "tmp")) if not os.path.isdir(os.path.join(ADDON_PROFILE, "movies")): os.makedirs(os.path.join(ADDON_PROFILE, "movies")) if not os.path.isdir(os.path.join(ADDON_PROFILE, "shows")): os.makedirs(os.path.join(ADDON_PROFILE, "shows")) except: pass method = 'Addons.SetAddonEnabled' json_rpc(method, {"addonid": ADDON_ID, "enabled": "true"}) 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)) shutil.rmtree(ADDON_PROFILE) directory = os.path.dirname(ADDON_PROFILE + os.sep + "images/empty.jpg") try: if not os.path.exists(directory): os.makedirs(directory) except: pass directory = os.path.dirname(ADDON_PROFILE + os.sep + "cache/empty.json") try: if not os.path.exists(directory): os.makedirs(directory) except: pass 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 remove_group(type, name, **kwargs): type = str(type) if not gui.yes_no(_.REMOVE_GROUP + '?'): return groups = load_file(type + '_groups.json', ext=False, isJSON=True) if not groups: groups = [] else: groups = list(groups) groups.remove(name) write_file(type + '_groups.json', data=groups, ext=False, isJSON=True) method = 'GUI.ActivateWindow' json_rpc( method, { "window": "videos", "parameters": ["plugin://" + ADDON_ID + "/?_=groups_menu&type=" + type] })
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) 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: import base64 decoded_string = base64.b64decode(encoded_file.read()) with open(dst_path, "wb") as decoded_file: decoded_file.write(decoded_string) else: from zipfile import ZipFile 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_video(type=None, channel=None, id=None, data=None, title=None, from_beginning=0, pvr=0, **kwargs): profile_settings = load_profile(profile_id=1) from_beginning = int(from_beginning) pvr = int(pvr) if not type or not len(unicode(type)) > 0: return False proxy_url = "http://127.0.0.1:11189/{provider}".format(provider=PROVIDER_NAME) code = 0 try: test_proxy = api_download(url=proxy_url + "/status", type='get', headers=None, data=None, json_data=False, return_json=False) code = test_proxy['code'] except: code = 404 if not code or not code == 200: gui.ok(message=_.PROXY_NOT_SET) return False playdata = api_play_url(type=type, channel=channel, id=id, video_data=data, from_beginning=from_beginning, pvr=pvr) if not playdata or not check_key(playdata, 'path'): return False playdata['channel'] = channel playdata['title'] = title if check_key(playdata, 'alt_path') and (from_beginning == 1 or (settings.getBool(key='ask_start_from_beginning') and gui.yes_no(message=_.START_FROM_BEGINNING, heading=playdata['title']))): path = playdata['alt_path'] license = playdata['alt_license'] else: path = playdata['path'] license = playdata['license'] real_url = "{hostscheme}://{netloc}".format(hostscheme=urlparse(path).scheme, netloc=urlparse(path).netloc) path = path.replace(real_url, proxy_url) playdata['path'] = path playdata['license'] = license item_inputstream, CDMHEADERS = plugin_process_playdata(playdata) info = plugin_process_info(playdata) write_file(file='stream_hostname', data=real_url, isJSON=False) write_file(file='stream_duration', data=info['duration'], isJSON=False) listitem = plugin.Item( label = unicode(info['label1']), label2 = unicode(info['label2']), art = { 'thumb': unicode(info['image']), 'fanart': unicode(info['image_large']) }, info = { 'credits': info['credits'], 'cast': info['cast'], 'writer': info['writer'], 'director': info['director'], 'genre': info['genres'], 'plot': unicode(info['description']), 'duration': info['duration'], 'mediatype': 'video', 'year': info['year'], 'sorttitle': unicode(info['label1']).upper(), }, path = path, headers = CDMHEADERS, inputstream = item_inputstream, ) return listitem