Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an action to check your credentials from the add-on settings. #352

Merged
merged 1 commit into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ msbuild.wrn

# Test caches
*.pyc
*.pyo
.pytest_cache/
.tox/

Expand Down
11 changes: 11 additions & 0 deletions addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ def delete_tokens():
tokenresolver.TokenResolver(kodi).delete_tokens()


@plugin.route('/tokens/check-credentials')
def check_credentials():
''' Check if the credentials are correct '''
from resources.lib import tokenresolver
if tokenresolver.TokenResolver(kodi).check_credentials():
kodi.show_ok_dialog(message=kodi.localize(30980))
else:
kodi.show_ok_dialog(message=kodi.localize(30952))
kodi.open_settings()


@plugin.route('/widevine/install')
def install_widevine():
''' The API interface to install Widevine '''
Expand Down
12 changes: 12 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ msgctxt "#30806"
msgid "Provide your VRT NU account password."
msgstr ""

msgctxt "#30807"
msgid "Check credentials"
msgstr ""

msgctxt "#30808"
msgid "Check if your VRT NU credentials are correct."
msgstr ""

msgctxt "#30820"
msgid "Interface"
msgstr ""
Expand Down Expand Up @@ -672,3 +680,7 @@ msgstr ""
msgctxt "#30979"
msgid "Because of important internal changes, existing Kodi favourites and watched history from VRT NU no longer work.\n[B]Please recreate all your VRT NU favourites.[/B]"
msgstr ""

msgctxt "#30980"
msgid "Login successful!"
msgstr ""
11 changes: 11 additions & 0 deletions resources/language/resource.language.nl_nl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ msgctxt "#30805"
msgid "Password"
msgstr "Wachtwoord"

msgctxt "#30807"
msgid "Check credentials"
msgstr "Controleer inloggegevens"

msgctxt "#30808"
msgid "Check if your VRT NU credentials are correct."
msgstr "Controleer of je VRT NU inloggegevens correct zijn."

msgctxt "#30820"
msgid "Interface"
msgstr "Interface"
Expand Down Expand Up @@ -565,3 +573,6 @@ msgctxt "#30979"
msgid "Because of important internal changes, existing Kodi favourites and watched history from VRT NU no longer work.\n[B]Please recreate all your VRT NU favourites.[/B]"
msgstr "Wegens belangrijke interne wijzigingen werken bestaande Kodi-favorieten en kijkgeschiedenis van VRT NU niet meer.\n[B]Gelieve al uw VRT NU-favorieten opnieuw aan te maken.[/B]"

msgctxt "#30980"
msgid "Login successful!"
msgstr "Inloggen gelukt!"
20 changes: 20 additions & 0 deletions resources/lib/tokenresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ def get_xvrttoken(self, token_variant=None):
token = self._get_new_xvrttoken(token_variant)
return token

def check_credentials(self):
''' Check the credentials '''
cred = Credentials(self._kodi)
if not cred.are_filled_in():
return False

payload = dict(
loginID=cred.username,
password=cred.password,
sessionExpiration='-1',
APIKey=self._API_KEY,
targetEnv='jssdk',
)
data = urlencode(payload).encode('utf8')
self._kodi.log_notice('URL post: ' + unquote(self._LOGIN_URL), 'Verbose')
req = Request(self._LOGIN_URL, data=data)
logon_json = json.load(urlopen(req))

return logon_json.get('errorCode') == 0

def _get_token_path(self, token_name, token_variant):
''' Create token path following predefined file naming rules '''
prefix = token_variant + '_' if token_variant else ''
Expand Down
1 change: 1 addition & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<setting label="30801" type="lsep"/> <!-- VRT NU login -->
<setting label="30803" help="30804" type="text" id="username"/>
<setting label="30805" help="30806" type="text" id="password" option="hidden"/>
<setting label="30807" help="30808" type="action" id="check_credentials" option="close" action="RunPlugin(plugin://plugin.video.vrt.nu/tokens/check-credentials)" subsetting="true" enable="!eq(-2,) + !eq(-1,)"/>
</category>
<category label="30820"> <!-- Interface -->
<setting label="30821" type="lsep"/> <!-- Features -->
Expand Down