Skip to content

Commit

Permalink
v2.4.3_v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariusz89B committed Feb 25, 2023
1 parent 1179182 commit ff14c4a
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 11 deletions.
8 changes: 6 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon id="plugin.video.viaplay" version="2.4.2" name="Viaplay" provider-name="mariusz89b, emilsvennesson, heppen-dev">
<addon id="plugin.video.viaplay" version="2.4.3-beta.1" name="Viaplay" provider-name="mariusz89b, emilsvennesson, heppen-dev">
<requires>
<import addon="script.module.requests" version="2.9.1" />
<import addon="script.module.iso8601" version="0.1.11" />
Expand All @@ -24,7 +24,11 @@
<platform>all</platform>
<license>GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 and MIT LICENSE.</license>
<source>https://github.com/Mariusz89B/plugin.video.viaplay</source>
<news>v2.4.2 (2023-02-24)
<news>v2.4.3 (2023-02-25)
- Added profile selector.
- Added supported countries.

v2.4.2 (2023-02-24)
- Added playcount for sport events.

v2.4.1 (2023-02-21)
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v2.4.3 (2023-02-25)
- Added profile selector.
- Added supported countries.

v2.4.2 (2023-02-24)
- Added playcount for sport events.

Expand Down
Binary file removed resources/art/fanart.jpg
Binary file not shown.
Binary file removed resources/art/icon.png
Binary file not shown.
36 changes: 36 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,40 @@ msgstr ""

msgctxt "#30081"
msgid "Program search"
msgstr ""

msgctxt "#30082"
msgid "viaplay.ee"
msgstr ""

msgctxt "#30083"
msgid "Estonian"
msgstr ""

msgctxt "#30084"
msgid "viaplay.lv"
msgstr ""

msgctxt "#30085"
msgid "Latvian"
msgstr ""

msgctxt "#30086"
msgid "viaplay.gb"
msgstr ""

msgctxt "#30087"
msgid "English"
msgstr ""

msgctxt "#30088"
msgid "Select profile"
msgstr ""

msgctxt "#30089"
msgid "Kids account"
msgstr ""

msgctxt "#30090"
msgid "Signed in as"
msgstr ""
38 changes: 37 additions & 1 deletion resources/language/resource.language.pl_pl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,40 @@ msgstr "Usuń wyszukiwanie"

msgctxt "#30081"
msgid "Program search"
msgstr "Wyszukiwanie programów"
msgstr "Wyszukiwanie programów"

msgctxt "#30082"
msgid "viaplay.ee"
msgstr "viaplay.ee"

msgctxt "#30083"
msgid "Estonian"
msgstr "Estoński"

msgctxt "#30084"
msgid "viaplay.lv"
msgstr "viaplay.lv"

msgctxt "#30085"
msgid "Latvian"
msgstr "Łotewski"

msgctxt "#30086"
msgid "viaplay.gb"
msgstr "viaplay.gb"

msgctxt "#30087"
msgid "English"
msgstr "Angelski"

msgctxt "#30088"
msgid "Select profile"
msgstr "Wybierz profil"

msgctxt "#30089"
msgid "Kids account"
msgstr "Konto dziecięce"

msgctxt "#30090"
msgid "Signed in as"
msgstr "Zalogowano jako"
38 changes: 37 additions & 1 deletion resources/language/resource.language.sv_se/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,40 @@ msgstr "Ta bort sökning"

msgctxt "#30081"
msgid "Program search"
msgstr "Programsökning"
msgstr "Programsökning"

msgctxt "#30082"
msgid "viaplay.ee"
msgstr "viaplay.ee"

msgctxt "#30083"
msgid "Estonian"
msgstr "Estisk"

msgctxt "#30084"
msgid "viaplay.lv"
msgstr "viaplay.lv"

msgctxt "#30085"
msgid "Latvian"
msgstr "Lettisk"

msgctxt "#30086"
msgid "viaplay.gb"
msgstr "viaplay.gb"

msgctxt "#30087"
msgid "English"
msgstr "Engelsk"

msgctxt "#30088"
msgid "Select profile"
msgstr "Välj profil"

msgctxt "#30089"
msgid "Kids account"
msgstr "Barnkonto"

msgctxt "#30090"
msgid "Signed in as"
msgstr "Inloggad som"
21 changes: 21 additions & 0 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ def generate_m3u():
f.close()
xbmcgui.Dialog().notification('Viaplay', helper.language(30064), xbmcgui.NOTIFICATION_INFO)

@plugin.route('/profiles')
def profiles():
helper.profiles_dialog()
xbmc.executebuiltin('Container.Refresh()')

@plugin.route('/')
def root():
pages = helper.vp.get_root_page()
Expand All @@ -318,6 +323,21 @@ def root():
'channels': channels
}

profiles_dict = helper.vp.get_profiles()

for profile in profiles_dict:
if helper.vp.get_setting('profileid'):
id = helper.vp.get_setting('profileid')
else:
id = helper.vp.get_user_id()['id']

if id == profile['data'].get('id'):
name = '{0} {1}'.format(helper.language(30090), profile['data'].get('name'))
avatar = {
'thumb': profile['embedded']['avatar']['data'].get('url'),
}
helper.add_item(name, plugin.url_for(profiles), art=avatar)

for page in pages:
page['title'] = capitalize(page['title'])

Expand All @@ -331,6 +351,7 @@ def root():
helper.add_item(page['title'], plugin.url_for(supported_pages[page['type']], url=page['href']))
else:
helper.log('Unsupported page found: %s' % page['name'])

helper.eod()

@plugin.route('/start')
Expand Down
46 changes: 44 additions & 2 deletions resources/lib/kodihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def get_country_code(self):
country_code = 'lt'
elif country_id == '6':
country_code = 'nl'
elif country_id == '7':
country_code = 'ee'
elif country_id == '8':
country_code = 'lv'
elif country_id == '9':
country_code = 'gb'

return country_code

Expand All @@ -87,14 +93,14 @@ def get_tld(self):
return "com"
return country_code

def dialog(self, dialog_type, heading, message=None, options=None, nolabel=None, yeslabel=None):
def dialog(self, dialog_type, heading, message=None, options=None, nolabel=None, yeslabel=None, useDetails=False):
dialog = xbmcgui.Dialog()
if dialog_type == 'ok':
dialog.ok(heading, message)
elif dialog_type == 'yesno':
return dialog.yesno(heading, message, nolabel=nolabel, yeslabel=yeslabel)
elif dialog_type == 'select':
ret = dialog.select(heading, options)
ret = dialog.select(heading, options, useDetails=useDetails)
if ret > -1:
return ret
else:
Expand All @@ -108,6 +114,42 @@ def dialog(self, dialog_type, heading, message=None, options=None, nolabel=None,
elif dialog_type == 'notification':
dialog.notification(heading, message)

def ensure_profile(self):
if not self.vp.get_user_id():
self.vp.validate_session()
if not self.vp.get_setting('profile_id'):
self.profiles_dialog()

def profiles_dialog(self):
profiles = self.vp.get_profiles()

options = []
ids = []

for profile in profiles:
profile_type = profile['data'].get('type')
if profile_type != 'adult':
profile_type = self.language(30089)
else:
profile_type = ''

listitem = xbmcgui.ListItem(
label=profile['data'].get('name'),
label2=profile_type
)

listitem.setArt({
'thumb': profile['embedded']['avatar']['data'].get('url'),
})

options.append(listitem)
ids.append(profile['data'].get('id'))

idx = self.dialog('select', self.language(30088), options=options, useDetails=True)

if idx >= 0:
self.set_setting('profileid', ids[idx])

def log_out(self):
confirm = self.dialog('yesno', self.language(30042), self.language(30043))
if confirm:
Expand Down
46 changes: 45 additions & 1 deletion resources/lib/viaplay.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
A Kodi-agnostic library for Viaplay
"""
Expand Down Expand Up @@ -56,8 +56,10 @@ def __init__(self, settings_folder, country, debug=False):
self.deviceid_file = os.path.join(settings_folder, 'deviceId')
self.http_session = requests.Session()
self.device_key = 'xdk-%s' % self.country
self.profile_url = 'https://viaplay.mtg-api.com'
self.base_url = 'https://content.viaplay.{0}/{1}'.format(self.tld, self.device_key)
self.login_api = 'https://login.viaplay.%s/api' % self.tld

try:
self.cookie_jar.load(ignore_discard=True, ignore_expires=True)
except IOError:
Expand Down Expand Up @@ -94,6 +96,12 @@ def get_country_code(self):
country_code = 'lt'
elif country_id == '6':
country_code = 'nl'
elif country_id == '7':
country_code = 'ee'
elif country_id == '8':
country_code = 'lv'
elif country_id == '9':
country_code = 'gb'

return country_code

Expand Down Expand Up @@ -146,6 +154,13 @@ def parse_url(self, url):

def make_request(self, url, method, params=None, payload=None, headers=None, status=False):
"""Make an HTTP request. Return the response."""
if not params:
params = {}

id = self.get_setting('profileid')
if id:
params['profileId'] = id

try:
return self._make_request(url, method, params=params, payload=payload, headers=headers)
except self.ViaplayError:
Expand Down Expand Up @@ -179,6 +194,35 @@ def _make_request(self, url, method, params=None, payload=None, headers=None, st
else:
return self.parse_response(req.content)

def get_user_id(self):
url = self.login_api + '/persistentLogin/v1'
params = {
'deviceKey': self.device_key
}
data = self.make_request(url=url, method='get', params=params)

return {'id': data['userData']['userId'], 'token': data['userData']['accessToken']}

def get_profiles(self):
url = self.profile_url + '/user-profiles/users/{0}/profiles/'.format(self.get_user_id()['id'])

headers = {
'authorization': 'MTG-AT {0}'.format(self.get_user_id()['token'])
}

params = {
'language': self.get_country_code()
}

data = self.make_request(url=url, method='get', params=params, headers=headers)

profiles = None

if data['embedded'].get('profiles'):
profiles = data['embedded']['profiles']

return profiles

def parse_response(self, response):
"""Try to load JSON data into dict and raise potential errors."""
try:
Expand Down
11 changes: 7 additions & 4 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
<default>0</default>
<constraints>
<options>
<option label="30008">0</option>
<option label="30009">1</option>
<option label="30010">2</option>
<option label="30009">1</option>
<option label="30082">7</option>
<option label="30011">3</option>
<option label="30054">4</option>
<option label="30086">9</option>
<option label="30065">5</option>
<option label="30084">8</option>
<option label="30067">6</option>
<option label="30010">2</option>
<option label="30054">4</option>
<option label="30008">0</option>
</options>
</constraints>
<control format="string" type="list">
Expand Down

0 comments on commit ff14c4a

Please sign in to comment.