Skip to content

Commit a696816

Browse files
authored
[plugin.video.viwx] v1.6.1 (#4668)
1 parent bf6522f commit a696816

9 files changed

Lines changed: 93 additions & 42 deletions

File tree

plugin.video.viwx/addon.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="plugin.video.viwx" name="viwX" version="1.6.0" provider-name="Dimitri Kroon">
2+
<addon id="plugin.video.viwx" name="viwX" version="1.6.1" provider-name="Dimitri Kroon">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0"/>
55
<import addon="inputstream.adaptive" version="19.0.5"/>
@@ -30,15 +30,14 @@
3030
<fanart>resources/fanart.png</fanart>
3131
</assets>
3232
<news>
33-
[B]v 1.6.0[/B]
33+
[B]v 1.6.1[/B]
3434
[B]Fixes:[/B]
35-
- 'Continue watching' items could sometimes have and incorrect resume point.
36-
- Another attempt to fix issues with signing in with email and password.
35+
- NO IPTV EPG.
3736

38-
[B]New Features:[/B]
39-
- Possibility to import authentication tokens copied from a web browser or another instance of
40-
viwX as an alternative method to authenticate when signing in with email and password fails.
41-
Visit https://github.com/dimkroon/itvx-for-kodi/wiki/Sign-in-to-your-ITV-account for more info.
37+
[B]Changes:[/B]
38+
- An attempt to correct some mistakes that are easily made when copying authentication tokens from a web browser.
39+
- More informative error messages and logs when importing tokens fails.
40+
- Some other minor changes.
4241
</news>
4342
<reuselanguageinvoker>true</reuselanguageinvoker>
4443
</extension>

plugin.video.viwx/changelog.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
v 1.6.1
2+
Fixes:
3+
- NO IPTV EPG.
4+
5+
Changes:
6+
- An attempt to correct some mistakes that are easily made when copying authentication tokens from a web browser.
7+
- More informative error messages and logs when importing tokens fails.
8+
- Some other minor changes.
9+
110
v 1.6.0
211
Fixes:
312
- 'Continue watching' items could sometimes have and incorrect resume point.

plugin.video.viwx/resources/language/resource.language.en_gb/strings.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ msgid "Import failed.\nThe file has invalid data."
262262
msgstr ""
263263

264264
msgctxt "#30628"
265-
msgid "Cookie import succeeded, but signing in failed.\nCheck the log for more info"
265+
msgid "Import succeeded, but the token was rejected by ITV.\nEnsure to copy all data exactly as is.\nEnsure the data is not older than 6 months."
266266
msgstr ""
267267

268268
# Generic button texts

plugin.video.viwx/resources/lib/iptvmanager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
# ----------------------------------------------------------------------------------------------------------------------
3-
# Copyright (c) 2024 Dimitri Kroon.
3+
# Copyright (c) 2024-2025 Dimitri Kroon.
44
# This file is part of plugin.video.viwx.
55
# SPDX-License-Identifier: GPL-2.0-or-later
66
# See LICENSE.txt
@@ -15,8 +15,8 @@
1515

1616
# Logo URLs from now/next.
1717
CHANNELS = {
18-
'ITV': {'id': 'viwx.itv',
19-
'name': 'ITV',
18+
'ITV1': {'id': 'viwx.itv1',
19+
'name': 'ITV1',
2020
'logo': 'https://images.ctfassets.net/bd5zurrrnk1g/54OefyIkbiHPMJUYApbuUX/7dfe2176762fd8ec10f77cd61a318b07/itv1.png?w=512',
2121
'preset': 1},
2222
'ITV2': {'id': 'viwx.itv2',

plugin.video.viwx/resources/lib/itv_account.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,10 @@ def refresh(self):
170170
logger.debug("Refreshing ITV account tokens...")
171171
try:
172172
token = self.account_data['itv_session']['refresh_token']
173-
url = 'https://auth.prd.user.itv.com/token?grant_type=refresh_token&' \
174-
'token=content_token refresh_token&refresh=' + token
175173
# Refresh requests require no authorization header and no cookies at all
176174
resp = fetch.get_json(
177-
url,
175+
'https://auth.prd.user.itv.com/token',
176+
params={'refresh': token},
178177
headers={'Accept': 'application/vnd.user.auth.v2+json'},
179178
timeout=10
180179
)

plugin.video.viwx/resources/lib/itvx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def get_full_schedule():
140140
141141
These are from the html pages that the website uses to show schedules.
142142
"""
143-
today = datetime.utcnow()
143+
today = datetime.now(timezone.utc)
144144
all_days = (today + timedelta(i) for i in range(-7, 8))
145145
# schedules = (get_page_data('watch/tv-guide/' + day.strftime('%Y-%m-%d')) for day in all_days)
146146
schedule = {}

plugin.video.viwx/resources/lib/parsex.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,13 @@ def parse_item_type_collection(item_data):
449449
url += '?ind'
450450

451451
title = item_data['title']
452+
descr = '\n\n'.join(txt for txt in (item_data.get('ctaLabel', 'Collection'), item_data.get('description')) if txt)
452453
item = {
453454
'label': title,
454455
'art': {'thumb': item_data['imageTemplate'].format(**IMG_PROPS_THUMB),
455456
'fanart': item_data['imageTemplate'].format(**IMG_PROPS_FANART)},
456457
'info': {'title': '[B]{}[/B]'.format(title),
457-
'plot': item_data.get('ctaLabel', 'Collection'),
458+
'plot': descr,
458459
'sorttitle': sort_title(title)},
459460
'params': {'url': url}
460461
}

plugin.video.viwx/resources/lib/settings.py

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,48 +75,91 @@ def logout(_):
7575

7676
@Script.register()
7777
def import_tokens(_):
78-
"""Import authentication tokens from a web browser or an existing viwx session file."""
79-
session = itv_account.itv_session()
78+
"""Import authentication tokens from a web browser or an existing viwx session file.
8079
81-
file_path = xbmcgui.Dialog().browseSingle(1, 'Open cookie file', 'files')
80+
"""
81+
file_path = xbmcgui.Dialog().browseSingle(1, 'Open token file', 'files')
8282
if not file_path:
83-
logger.info("Importing browser cookie canceled.")
83+
logger.info("Importing auth tokens canceled.")
8484
return
8585

86-
logger.info("Importing browser cookie from %s.", file_path)
86+
logger.info("Importing auth tokens from %s.", file_path)
8787
with xbmcvfs.File(file_path, 'r') as f:
88-
data = f.read()
88+
raw_data = f.read()
89+
check_token_data(raw_data)
90+
8991

90-
data = data.strip()
92+
def check_token_data(raw_data: str):
93+
data_type = "Unknown"
94+
data = raw_data.strip()
95+
# Just in case some editor has inserted hard wraps.
96+
data = data.replace('\n', '')
97+
data = data.replace('\r', '')
9198
try:
92-
if data.startswith('Itv.Session:"{"tokens":'):
93-
logger.info("Found Firefox cookie data...")
94-
data = data[13:-1]
95-
session_data = json.loads(data)['tokens']['content']
96-
elif data.startswith('{"tokens":'):
97-
logger.info("Found Chromium cookie data...")
98-
session_data = json.loads(data)['tokens']['content']
99+
if '.Session:"{' in data[:16]:
100+
data_type = "Firefox cookie"
101+
if not data.startswith('Itv'):
102+
raise errors.ParseError("Firefox cookie data should start with 'ITV.Session'.")
103+
if not data.endswith('"'):
104+
raise errors.ParseError('Firefox cookie data should end with a double quote (").')
105+
token_data = _parse_cookie(data[13:-1])
106+
elif 'tokens":' in data[:11]:
107+
data_type = "Chromium cookie"
108+
if not data.startswith('{'):
109+
raise errors.ParseError("Chromium cookie data should start with a '{'.")
110+
if not data.endswith('}'):
111+
raise errors.ParseError("Chromium cookie data should end with a '}'.")
112+
token_data = _parse_cookie(data)
113+
elif '"vers": 2' in data:
114+
data_type = "viwX export"
115+
try:
116+
token_data = json.loads(data)['itv_session']
117+
except (json.JSONDecodeError, KeyError):
118+
raise errors.ParseError("This is not a valid viwX token export file.")
99119
else:
100-
logger.info("Expecting viwX data...")
101-
session_data = json.loads(data)['itv_session']
102-
# Just to check its presence
103-
_ = session_data['refresh_token']
104-
except (json.JSONDecodeError, KeyError, TypeError):
105-
logger.error("Invalid auth cookie data:\n", exc_info=True)
106-
kodi_utils.msg_dlg(TXT_IMPORT_INVALID_DATA)
120+
raise errors.ParseError("Unknown file format.\n"
121+
"Ensure to copy all data exactly as is.")
122+
except errors.ParseError as err:
123+
logger.error("Invalid token data\n\t\tFile format: %s\n\t\tstart: '%s'\n\t\tend: '%s'\n",
124+
data_type, raw_data[:20], raw_data[-20:], exc_info=True)
125+
kodi_utils.msg_dlg('\n'.join((Script.localize(TXT_IMPORT_INVALID_DATA), str(err))))
107126
return
108127

109-
logger.debug('Successfully read auth cookie file.')
128+
try:
129+
# Just to check its presence
130+
_ = token_data['refresh_token']
131+
except KeyError:
132+
logger.error("Failed to import' refresh token not present.")
133+
kodi_utils.msg_dlg('\n'.join((
134+
Script.localize(TXT_IMPORT_INVALID_DATA),
135+
"Missing token.Are you sure you were signed in when copying the cookie?"))
136+
)
137+
return
110138

111-
session.account_data['itv_session'] = session_data
139+
logger.debug('Successfully read auth tokens file.')
140+
session = itv_account.itv_session()
141+
session.account_data['itv_session'] = token_data
112142
session.account_data['cookies'] = {}
113143
if session.refresh():
114144
kodi_utils.msg_dlg(TXT_IMPORT_SUCCESS, nickname=session.user_nickname)
115145
else:
116-
session.save_account_data()
117146
kodi_utils.msg_dlg(TXT_IMPORT_FAILED_REFRESH)
118147

119148

149+
def _parse_cookie(data: str) -> dict:
150+
"""Read tokens from cookie data and try to show an informative message on failure."""
151+
try:
152+
tokens = json.loads(data)['tokens']['content']
153+
return tokens
154+
except (json.JSONDecodeError, TypeError):
155+
logger.error("Error importing tokens from cookie:\n", exc_info=True)
156+
raise errors.ParseError('Invalid, or a incomplete authentication cookie.')
157+
except KeyError:
158+
logger.error("Error importing tokens from cookie:\n", exc_info=True)
159+
raise errors.ParseError('The cookie data is invalid, or incomplete.\n'
160+
'Are you sure you were signed in when copying the cookie?')
161+
162+
120163
@Script.register()
121164
def export_tokens(_):
122165
import datetime

plugin.video.viwx/resources/lib/telemetry_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def get_data(self):
112112
apply some unpredictability as to what data is returned.
113113
"""
114114
data_len = len(telemetry_data)
115-
new_idx = int(min(random.random(), 0.9) * data_len)
115+
new_idx = int(min(random.random(), 0.999) * data_len)
116116
while new_idx in self.used_indices:
117117
new_idx += 1
118118
if new_idx >= data_len:

0 commit comments

Comments
 (0)