def _connection_failure_dialog(): if (g.get_float_setting("general.trakt.failure.timeout") + (2 * 60 * (60 * 60)) < time.time() and not xbmc.Player().isPlaying()): xbmcgui.Dialog().notification( g.ADDON_NAME, g.get_language_string(30024).format("Trakt")) g.set_setting("general.trakt.failure.timeout", g.UNICODE(time.time()))
def store_user_info(self): user_information = self.get_user_info() if user_information is not None: g.set_setting("alldebrid.username", user_information["username"]) g.set_setting( "alldebrid.premiumstatus", "Premium" if user_information.get( "isPremium", False) else "Expired")
def check_for_addon_update(): """ Perform checks for addon updates and notify user of any available updates :return: None :rtype: None """ if not g.get_bool_setting("general.checkAddonUpdates"): return if "-" in g.VERSION: g.set_setting("addon.updateCheckTimeStamp", g.UNICODE(time.time())) return update_timestamp = g.get_float_setting("addon.updateCheckTimeStamp") if time.time() > (update_timestamp + (24 * (60 * 60))): repo_xml = requests.get( "https://github.com/Newf276/Newf276/raw/master/packages/addons.xml" ) if not repo_xml.status_code == 200: g.log( "Could not connect to repo XML, status: {}".format( repo_xml.status_code ), "error", ) return try: xml = tools.ElementTree.fromstring(repo_xml.text) for dir_tag in xml.iterfind("./addon[@id='repository.Newf276']/extension/dir"): minversion = dir_tag.get('minversion') maxversion = dir_tag.get('maxversion') if ( ( minversion is None and maxversion is None ) or ( minversion and maxversion and tools.compare_version_numbers(minversion, g.KODI_FULL_VERSION, include_same=True) and tools.compare_version_numbers(g.KODI_FULL_VERSION, maxversion, include_same=True) ) or ( maxversion is None and minversion and tools.compare_version_numbers(minversion, g.KODI_FULL_VERSION, include_same=True) ) or ( minversion is None and maxversion and tools.compare_version_numbers(g.KODI_FULL_VERSION, maxversion, include_same=True) ) ): repo_version = _get_latest_repo_version(dir_tag.find('info').text) if tools.compare_version_numbers(g.CLEAN_VERSION, repo_version): xbmcgui.Dialog().ok( g.ADDON_NAME, g.get_language_string(30199).format(repo_version) ) except tools.ElementTree.ParseError as pe: g.log("Could not parse repo XML", "error") finally: g.set_setting("addon.updateCheckTimeStamp", str(time.time()))
def toggle_reuselanguageinvoker(forced_state=None): def _store_and_reload(output): with open(file_path, "w+") as addon_xml: addon_xml.writelines(output) xbmcgui.Dialog().ok(g.ADDON_NAME, g.get_language_string(30560)) g.reload_profile() file_path = os.path.join(g.ADDON_DATA_PATH, "addon.xml") with open(file_path, "r") as addon_xml: file_lines = addon_xml.readlines() for i in range(len(file_lines)): line_string = file_lines[i] if "reuselanguageinvoker" in file_lines[i]: if ("false" in line_string and forced_state is None) or ("false" in line_string and forced_state): file_lines[i] = file_lines[i].replace("false", "true") g.set_setting("reuselanguageinvoker.status", "Enabled") _store_and_reload(file_lines) elif ("true" in line_string and forced_state is None) or ("true" in line_string and forced_state is False): file_lines[i] = file_lines[i].replace("true", "false") g.set_setting("reuselanguageinvoker.status", "Disabled") _store_and_reload(file_lines) break
def poll_auth(self, **params): resp = self.get_json("pin/check", **params) if resp["activated"]: g.set_setting(AD_AUTH_KEY, resp["apikey"]) self.apikey = resp["apikey"] return True, 0 return False, int(resp["expires_in"])
def do_version_change(): if g.get_setting("seren.version") == g.CLEAN_VERSION: return g.log("Clearing cache on Seren version change", "info") g.clear_cache(silent=True) g.set_setting("seren.version", g.CLEAN_VERSION)
def do_update_news(): if last_update_required == g.get_setting("update.news.version"): return for msg in [g.get_language_string(30571)]: xbmcgui.Dialog().ok(g.ADDON_NAME, msg) g.set_setting("update.news.version", last_update_required)
def validate_timezone_detected(): if g.LOCAL_TIMEZONE and isinstance( g.LOCAL_TIMEZONE, pytz.BaseTzInfo) and g.LOCAL_TIMEZONE.zone != 'UTC': return else: g.set_setting("general.manualtimezone", True) notify_timezone_not_detected()
def do_update_news(): if last_update_required == g.get_setting("update.news.version"): return for msg in update_messages: xbmcgui.Dialog().ok(g.ADDON_NAME, msg) g.set_setting("update.news.version", last_update_required)
def choose_timezone(): time_zones = [ i for i in pytz.common_timezones if len(i.split('/')) >= 2 and not i.split('/')[0] == 'US' ] # Note we deliberately don't include the US timezones as they have too many assumptions for historic dates tz_index = xbmcgui.Dialog().select(g.get_language_string(30578), time_zones) if not tz_index == -1: g.set_setting("general.localtimezone", time_zones[tz_index])
def set_download_location(): """ Requests new file location from user and stores in settings :return: None """ new_location = xbmcgui.Dialog().browse( 0, g.get_language_string(30480), "video", defaultt=STORAGE_LOCATION ) g.set_setting("download.location", new_location)
def set_download_location(): """ Sets the relevant download location to settings :return: """ storage_location = g.DOWNLOAD_PATH new_location = xbmcgui.Dialog().browse( 0, g.get_language_string(30480), "video", defaultt=storage_location ) g.set_setting("download.location", new_location)
def set_settings_status(debrid_provider, status): """ Ease of use method to set premium status setting :param debrid_provider: setting prefix for debrid provider :type debrid_provider: str :param is_premium: Status of premium status :type is_premium: bool :return: None :rtype: None """ g.set_setting("{}.premiumstatus".format(debrid_provider), status.title())
def set_settings_status(debrid_provider, is_premium): """ Ease of use method to set premium status setting :param debrid_provider: setting prefix for debrid provider :type debrid_provider: str :param is_premium: Status of premium status :type is_premium: bool :return: None :rtype: None """ status = "Premium" if is_premium else "Expired" g.set_setting("{}.premiumstatus".format(debrid_provider), status)
def _mark_skin_active(self, skin_name): self.execute_sql("UPDATE skins SET active=? WHERE active=?", ("0", "1")) self.execute_sql("UPDATE skins SET active=? WHERE skin_name=?", ("1", skin_name)) g.set_setting( "skin.active", "{skin_name} - {version}".format(**self.fetchone( "SELECT skin_name, version FROM skins WHERE skin_name=?", (skin_name, ), )), ) self._active_skin_path = self._get_active_skin_path()
def token_request(self): import time if not self.client_secret: return url = self.oauth_url + self.token_url response = self.session.post( url, data={ "client_id": self.client_id, "client_secret": self.client_secret, "code": self.device_code, "grant_type": "http://oauth.net/grant_type/device/1.0", }, ).json() g.set_setting(RD_AUTH_KEY, response["access_token"]) g.set_setting(RD_REFRESH_KEY, response["refresh_token"]) self.token = response["access_token"] self.session.headers.update( {"Authorization": "Bearer {}".format(self.token)}) self.refresh = response["refresh_token"] g.set_setting(RD_EXPIRY_KEY, str(time.time() + int(response["expires_in"]))) username = self.get_url("user").get("username") g.set_setting(RD_USERNAME_KEY, username) xbmcgui.Dialog().ok(g.ADDON_NAME, "Real Debrid " + g.get_language_string(30021)) g.log("Authorised Real Debrid successfully", "info")
def _auth_loop(self): url = "client_id={}&code={}".format(RD_AUTH_CLIENT_ID, self.device_code) url = self.oauth_url + self.device_credentials_url.format(url) response = self.session.get(url).json() if "error" not in response and response.get("client_secret"): try: g.set_setting(RD_CLIENT_ID_KEY, response["client_id"]) g.set_setting(RD_SECRET_KEY, response["client_secret"]) self.client_secret = response["client_secret"] self.client_id = response["client_id"] return True except Exception: xbmcgui.Dialog().ok(g.ADDON_NAME, g.get_language_string(30065)) raise return False
def update_provider_packages(): """ Perform checks for provider package updates :return: None :rtype: None """ provider_check_stamp = g.get_float_setting("provider.updateCheckTimeStamp", 0) automatic = g.get_bool_setting("providers.autoupdates") if time.time() > (provider_check_stamp + (24 * (60 * 60))): available_updates = ProviderInstallManager().check_for_updates( silent=True, automatic=automatic) if not automatic and len(available_updates) > 0: g.notification(g.ADDON_NAME, g.get_language_string(30278)) g.set_setting("provider.updateCheckTimeStamp", str(time.time()))
def choose_timezone(): current = g.get_setting("general.localtimezone") time_zones = [ i for i in pytz.common_timezones if len(i.split('/')) >= 2 and not i.split('/')[0] == 'US' ] # Note we deliberately don't include the US timezones as they have too many assumptions for historic dates try: preselect = time_zones.index(current) except ValueError: preselect = -1 tz_index = xbmcgui.Dialog().select(g.get_language_string(30548), time_zones, preselect=preselect) if not tz_index == -1: g.set_setting("general.localtimezone", time_zones[tz_index])
def do_version_change(): if g.get_setting("seren.version") == g.CLEAN_VERSION: return g.log("Clearing cache on Seren version change", "info") g.clear_cache(silent=True) g.set_setting("seren.version", g.CLEAN_VERSION) # Reuselanguageinvoker update. This should be last to execute as it can do a profile reload. # Disable the restoration of reuselanguageinvoker addon.xml based on settings value on upgrade. # It can still be toggled in settings, although initially it will be the release default value. # This is due to the fact that we still don't recommend having this enabled due to Kodi hard crashes. # maintenance.toggle_reuselanguageinvoker( # True if g.get_setting("reuselanguageinvoker") == "Enabled" else False) g.set_setting( "reuselanguageinvoker.status", "Disabled" ) # This ensures setting is reflected as disabled on version change
def pre_scrape(): """ Checks whether a item exists in the current playlist after current item and then pre-fetches results :return: :rtype: """ next_position = g.PLAYLIST.getposition() + 1 if next_position >= g.PLAYLIST.size(): return url = g.PLAYLIST[ # pylint: disable=unsubscriptable-object next_position].getPath() if not url: return url = url.replace("getSources", "preScrape") g.set_setting("general.tempSilent", "true") g.log("Running Pre-Scrape: {}".format(url)) xbmc.executebuiltin('RunPlugin("{}")'.format(url))
def do_update_news(): last_update_news_version = g.get_setting("update.news.version") max_update_news_version = max(update_news_versions) if not last_update_news_version: g.set_setting("update.news.version", max_update_news_version) return if max_update_news_version == last_update_news_version: return for msg in [ g.get_language_string(update_news_versions[v]) for v in sorted(update_news_versions) if v > last_update_news_version ]: xbmcgui.Dialog().ok( "{} - {}".format(g.ADDON_NAME, g.get_language_string(30567)), msg) g.set_setting("update.news.version", max_update_news_version)
def toggle_reuselanguageinvoker(): file_path = os.path.join(g.ADDON_DATA_PATH, "addon.xml") with open(file_path, "r") as addon_xml: file_lines = addon_xml.readlines() for i in range(len(file_lines)): if "reuselanguageinvoker" in file_lines[i]: if "false" in file_lines[i]: file_lines[i] = file_lines[i].replace("false", "true") g.set_setting("reuselanguageinvoker.status", "Enabled") else: file_lines[i] = file_lines[i].replace("true", "false") g.set_setting("reuselanguageinvoker.status", "Disabled") break with open(file_path, "w+") as addon_xml: addon_xml.writelines(file_lines) xbmcgui.Dialog().ok(g.ADDON_NAME, g.get_language_string(30572)) g.reload_profile()
def _poll_token(self, device_code): data = { "client_id": self.client_id, "code": device_code, "grant_type": "device_code", } token = self.session.post("https://www.premiumize.me/token", data=data).json() if "error" in token: if token["error"] == "access_denied": return False, False return True, False g.set_setting(PM_TOKEN_KEY, token["access_token"]) self.headers["Authorization"] = "Bearer {}".format( token["access_token"]) account_info = self.account_info() g.set_setting("premiumize.username", account_info["customer_id"]) return False, True
def _save_settings(self, response): self.token = response["access_token"] self.refresh = response["refresh_token"] self.expiry = time.time() + int(response["expires_in"]) g.set_setting(RD_AUTH_KEY, self.token) g.set_setting(RD_REFRESH_KEY, self.refresh) g.set_setting(RD_EXPIRY_KEY, self.expiry)
def _auth_poll(self, device): response = self.post( "oauth/device/token", data={ "code": device, "client_id": self.client_id, "client_secret": self.client_secret, }, ) if response.status_code == 200: response = response.json() self._save_settings(response) username = self.get_username() self.username = username g.set_setting(self.username_setting_key, username) return False elif response.status_code == 404 or response.status_code == 410: xbmcgui.Dialog().ok(g.ADDON_NAME, g.get_language_string(30023)) return True elif response.status_code == 409: return True elif response.status_code == 429: xbmc.sleep(1 * 1000) return False
def check_for_addon_update(): """ Perform checks for addon updates and notify uesr of any available updates :return: None :rtype: None """ if not g.get_bool_setting("general.checkAddonUpdates"): return local_verison = g.VERSION if "-" in local_verison: g.set_setting("addon.updateCheckTimeStamp", str(time.time())) return update_timestamp = g.get_float_setting("addon.updateCheckTimeStamp") if time.time() > (update_timestamp + (24 * (60 * 60))): repo_xml = requests.get( "https://raw.githubusercontent.com/nixgates/nixgates/master/packages/addons.xml" ) if not repo_xml.status_code == 200: g.log( "Could not connect to repo XML, status: {}".format( repo_xml.status_code), "error", ) return repo_version = re.findall( r"<addon id=\"plugin.video.seren\" version=\"(\d*.\d*.\d*)\"", repo_xml.text)[0] if tools.compare_version_numbers(local_verison, repo_version): xbmcgui.Dialog().ok( g.ADDON_NAME, g.get_language_string(30199).format(repo_version)) g.set_setting("addon.updateCheckTimeStamp", str(time.time()))
def _save_settings(self, response): if "access_token" in response: g.set_setting("trakt.auth", response["access_token"]) self.access_token = response["access_token"] if "refresh_token" in response: g.set_setting("trakt.refresh", response["refresh_token"]) self.refresh_token = response["refresh_token"] if "expires_in" in response and "created_at" in response: g.set_setting( "trakt.expires", g.UNICODE(response["created_at"] + response["expires_in"])) self.token_expires = float(response["created_at"] + response["expires_in"])
def try_refresh_token(self): if not self.token or float(time.time()) < (self.expiry - (15 * 60)): return with GlobalLock(self.__class__.__name__, self._threading_lock, True, self.refresh): url = self.oauth_url + "token" response = self.session.post( url, data={ "grant_type": "http://oauth.net/grant_type/device/1.0", "code": self.refresh, "client_secret": self.client_secret, "client_id": self.client_id, }, ) if not self._is_response_ok(response): response = response.json() g.notification( g.ADDON_NAME, "Failed to refresh RD token, please manually re-auth") g.log("RD Refresh error: {}".format(response["error"])) g.log( "Invalid response from Real Debrid - {}".format(response), "error") return False response = response.json() if "access_token" in response: self.token = response["access_token"] if "refresh_token" in response: self.refresh = response["refresh_token"] g.set_setting(RD_AUTH_KEY, self.token) g.set_setting(RD_REFRESH_KEY, self.refresh) g.set_setting(RD_EXPIRY_KEY, str(time.time() + int(response["expires_in"]))) g.log("Real Debrid Token Refreshed") return True
def close(self): g.set_setting("general.filters", ",".join(self.current_filters)) super(FilterSelect, self).close() g.open_addon_settings( 6, 1) # Open settings back where we were launched from