Skip to content

Commit

Permalink
Implement parental control
Browse files Browse the repository at this point in the history
  • Loading branch information
emilsvennesson committed Sep 8, 2016
1 parent cd855c0 commit d01bc77
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ This plugin supports Kodi Jarvis or later. While it may work fine on older versi
* Subtitles
* Search
* A-Ö alphabetical listing
* Parental control

Currently unsupported features:

* Viasat TV To Go
* Starred
* Activity list
* Parental control
* ... And quite possibly more that I'm forgetting about!

## Known issues: ##
Expand Down
36 changes: 26 additions & 10 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,15 @@ def get_userinput(title):
addon_log('User input string: %s' % query)
return query


def get_numeric_input(heading):
dialog = xbmcgui.Dialog()
numeric_input = dialog.numeric(0, heading)
if len(numeric_input) > 0:
return str(numeric_input)
else:
return None


def search(url):
try:
Expand All @@ -457,23 +466,16 @@ def search(url):
pass


def play_video(input, streamtype, content):
def play_video(input, streamtype, content, pincode=None):
if streamtype == 'url':
url = input
guid = vp.get_products(input=url, method='url')['system']['guid']
else:
guid = input

try:
video_urls = vp.get_video_urls(guid)
except vp.AuthFailure as error:
show_auth_error(error.value)
video_urls = False
except vp.LoginFailure:
show_dialog(dialog_type='ok', heading=language(30005), message=language(30006))
video_urls = False

if video_urls:
video_urls = vp.get_video_urls(guid, pincode=pincode)

if content == 'sport':
# sports uses HLS v4 so we can't parse the manifest as audio is supplied externally
stream_url = video_urls['manifest_url']
Expand All @@ -490,6 +492,20 @@ def play_video(input, streamtype, content):
if addon.getSetting('subtitles') == 'true':
playitem.setSubtitles(vp.download_subtitles(video_urls['subtitle_urls']))
xbmcplugin.setResolvedUrl(_handle, True, listitem=playitem)

except vp.AuthFailure as error:
if error.value == 'ParentalGuidancePinChallengeNeededError':
if pincode:
show_dialog(dialog_type='ok', heading=language(30033), message=language(30034))
else:
pincode = get_numeric_input(language(30032))
if pincode:
play_video(input, streamtype, content, pincode)
else:
show_auth_error(error.value)

except vp.LoginFailure:
show_dialog(dialog_type='ok', heading=language(30005), message=language(30006))


def sports_menu(url):
Expand Down
12 changes: 12 additions & 0 deletions resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,15 @@ msgstr ""
msgctxt "#30031"
msgid "Archived events"
msgstr ""

msgctxt "#30032"
msgid "Enter your PIN code"
msgstr ""

msgctxt "#30033"
msgid "Parental control"
msgstr ""

msgctxt "#30034"
msgid "The PIN code you have entered is incorrect."
msgstr ""
12 changes: 12 additions & 0 deletions resources/language/Swedish/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,15 @@ msgstr "Kommande evenemang"
msgctxt "#30031"
msgid "Archived events"
msgstr "Arkiverade evenemang"

msgctxt "#30032"
msgid "Enter your PIN code"
msgstr "Skriv din PIN-kod"

msgctxt "#30033"
msgid "Parental control"
msgstr "Barnlås"

msgctxt "#30034"
msgid "The PIN code you have entered is incorrect."
msgstr "PIN-koden du angav är felaktig."
5 changes: 3 additions & 2 deletions resources/lib/vialib.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def verify_login_status(self, data):

return True

def get_video_urls(self, guid):
def get_video_urls(self, guid, pincode=None):
"""Return a dict with the stream URL:s and available subtitle URL:s."""
video_urls = {}
url = 'https://play.viaplay.%s/api/stream/byguid' % self.country
Expand All @@ -138,7 +138,8 @@ def get_video_urls(self, guid):
'deviceType': 'pc',
'userAgent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0',
'deviceKey': 'pchls-%s' % self.country,
'guid': guid
'guid': guid,
'pgPin': pincode
}

data = self.make_request(url=url, method='get', payload=payload)
Expand Down

0 comments on commit d01bc77

Please sign in to comment.