From cd3117124f60e380e23655d638d23699bec860c4 Mon Sep 17 00:00:00 2001 From: CaptainT Date: Sat, 18 Nov 2023 16:51:20 +0100 Subject: [PATCH] [plugin.video.iplayerwww] 4.0.17 --- plugin.video.iplayerwww/addon.xml | 6 +- plugin.video.iplayerwww/changelog.txt | 3 + plugin.video.iplayerwww/default.py | 201 +++++++++--------- .../resource.language.en_gb/strings.po | 5 +- .../resources/lib/ipwww_common.py | 38 +--- .../resources/lib/ipwww_radio.py | 25 ++- .../resources/lib/ipwww_video.py | 10 +- 7 files changed, 141 insertions(+), 147 deletions(-) diff --git a/plugin.video.iplayerwww/addon.xml b/plugin.video.iplayerwww/addon.xml index 6d1cb1589b..72e31c7f07 100644 --- a/plugin.video.iplayerwww/addon.xml +++ b/plugin.video.iplayerwww/addon.xml @@ -1,5 +1,5 @@ - + @@ -22,8 +22,8 @@ resources/fanart.jpg -v4.0.16 -Live radio now needs an authentication token. Credits to dimkroon/kereltje once again. +v4.0.17 +Live radio authentication token fixes and simplifications. Known issues: - No Red Button diff --git a/plugin.video.iplayerwww/changelog.txt b/plugin.video.iplayerwww/changelog.txt index 39388f92ad..d50e59a247 100644 --- a/plugin.video.iplayerwww/changelog.txt +++ b/plugin.video.iplayerwww/changelog.txt @@ -1,3 +1,6 @@ +v4.0.17 +Live radio authentication token fixes and simplifications. + v4.0.16 Live radio now needs an authentication token. Credits to dimkroon/kereltje once again. diff --git a/plugin.video.iplayerwww/default.py b/plugin.video.iplayerwww/default.py index bf75859ae2..2d939b4dd0 100644 --- a/plugin.video.iplayerwww/default.py +++ b/plugin.video.iplayerwww/default.py @@ -87,150 +87,153 @@ def get_params(): except: pass -# These are the modes which tell the plugin where to go. -if mode == 1: - Common.KidsMode() - -elif mode is None or url is None or len(url) < 1: - Common.CreateBaseDirectory(content_type) +try: + # These are the modes which tell the plugin where to go. + if mode == 1: + Common.KidsMode() -# Modes 101-119 will create a main directory menu entry -elif mode == 101: - Video.ListLive() + elif mode is None or url is None or len(url) < 1: + Common.CreateBaseDirectory(content_type) -elif mode == 102: - Video.ListAtoZ() + # Modes 101-119 will create a main directory menu entry + elif mode == 101: + Video.ListLive() -elif mode == 103: - Video.ListCategories() + elif mode == 102: + Video.ListAtoZ() -elif mode == 104: - Video.Search(keyword) + elif mode == 103: + Video.ListCategories() -elif mode == 105: - Video.ListMostPopular() + elif mode == 104: + Video.Search(keyword) -elif mode == 106: - Video.ListHighlights(url) + elif mode == 105: + Video.ListMostPopular() -elif mode == 107: - Video.ListWatching() + elif mode == 106: + Video.ListHighlights(url) -elif mode == 108: - Video.ListFavourites() + elif mode == 107: + Video.ListWatching() -elif mode == 109: - Video.ListChannelHighlights() + elif mode == 108: + Video.ListFavourites() -elif mode == 112: - Radio.ListAtoZ() + elif mode == 109: + Video.ListChannelHighlights() -elif mode == 113: - Radio.ListLive() + elif mode == 112: + Radio.ListAtoZ() -elif mode == 114: - Radio.ListGenres() + elif mode == 113: + Radio.ListLive() -elif mode == 115: - Radio.Search(keyword) + elif mode == 114: + Radio.ListGenres() -elif mode == 116: - Radio.ListMostPopular() + elif mode == 115: + Radio.Search(keyword) -elif mode == 117: - Radio.ListListenList() + elif mode == 116: + Radio.ListMostPopular() -elif mode == 199: - Radio.ListFollowing() + elif mode == 117: + Radio.ListListenList() -elif mode == 118: - Video.RedButtonDialog() + elif mode == 199: + Radio.ListFollowing() -elif mode == 119: - Common.SignOutBBCiD() + elif mode == 118: + Video.RedButtonDialog() -elif mode == 120: - Video.ListChannelAtoZ() + elif mode == 119: + Common.SignOutBBCiD() - # Modes 121-199 will create a sub directory menu entry -elif mode == 121: - Video.GetEpisodes(url) + elif mode == 120: + Video.ListChannelAtoZ() -elif mode == 122: - Video.GetAvailableStreams(name, url, iconimage, description) + # Modes 121-199 will create a sub directory menu entry + elif mode == 121: + Video.GetEpisodes(url) -elif mode == 123: - Video.AddAvailableLiveStreamsDirectory(name, url, iconimage) + elif mode == 122: + Video.GetAvailableStreams(name, url, iconimage, description) -elif mode == 124: - Video.GetAtoZPage(url) + elif mode == 123: + Video.AddAvailableLiveStreamsDirectory(name, url, iconimage) -elif mode == 125: - Video.ListCategoryFilters(url) + elif mode == 124: + Video.GetAtoZPage(url) -elif mode == 126: - Video.GetFilteredCategory(url) + elif mode == 125: + Video.ListCategoryFilters(url) -elif mode == 127: - Video.GetGroup(url) + elif mode == 126: + Video.GetFilteredCategory(url) -elif mode == 128: - Video.ScrapeEpisodes(url) + elif mode == 127: + Video.GetGroup(url) -elif mode == 129: - Video.AddAvailableRedButtonDirectory(name, url) + elif mode == 128: + Video.ScrapeEpisodes(url) -elif mode == 131: - Radio.GetEpisodes(url) + elif mode == 129: + Video.AddAvailableRedButtonDirectory(name, url) -elif mode == 132: - Radio.GetAvailableStreams(name, url, iconimage, description) + elif mode == 131: + Radio.GetEpisodes(url) -elif mode == 133: - Radio.AddAvailableLiveStreamsDirectory(name, url, iconimage) + elif mode == 132: + Radio.GetAvailableStreams(name, url, iconimage, description) -elif mode == 134: - Video.ScrapeAtoZEpisodes(url) + elif mode == 133: + Radio.AddAvailableLiveStreamsDirectory(name, url, iconimage) -elif mode == 136: - Radio.GetPage(url) + elif mode == 134: + Video.ScrapeAtoZEpisodes(url) -elif mode == 137: - Radio.GetCategoryPage(url) + elif mode == 136: + Radio.GetPage(url) -elif mode == 138: - Radio.GetAtoZPage(url) + elif mode == 137: + Radio.GetCategoryPage(url) -elif mode == 139: - Video.ScrapeEpisodes(url) + elif mode == 138: + Radio.GetAtoZPage(url) -# Modes 201-299 will create a playable menu entry, not a directory -elif mode == 201: - Video.PlayStream(name, url, iconimage, description, subtitles_url) + elif mode == 139: + Video.ScrapeEpisodes(url) -elif mode == 202: - Video.AddAvailableStreamItem(name, url, iconimage, description) + # Modes 201-299 will create a playable menu entry, not a directory + elif mode == 201: + Video.PlayStream(name, url, iconimage, description, subtitles_url) -elif mode == 203: - Video.AddAvailableLiveStreamItemSelector(name, url, iconimage) + elif mode == 202: + Video.AddAvailableStreamItem(name, url, iconimage, description) -elif mode == 204: - Video.AddAvailableRedButtonItem(name, url) + elif mode == 203: + Video.AddAvailableLiveStreamItemSelector(name, url, iconimage) -elif mode == 205: - Video.AddAvailableUHDTrialItem(name, url) + elif mode == 204: + Video.AddAvailableRedButtonItem(name, url) -elif mode == 211: - Radio.PlayStream(name, url, iconimage, description, subtitles_url) + elif mode == 205: + Video.AddAvailableUHDTrialItem(name, url) -elif mode == 212: - Radio.AddAvailableStreamItem(name, url, iconimage, description) + elif mode == 211: + Radio.PlayStream(name, url, iconimage, description, subtitles_url) -elif mode == 213: - Radio.AddAvailableLiveStreamItem(name, url, iconimage) + elif mode == 212: + Radio.AddAvailableStreamItem(name, url, iconimage, description) -elif mode == 197: - Video.ListUHDTrial() + elif mode == 213: + Radio.AddAvailableLiveStreamItem(name, url, iconimage) + elif mode == 197: + Video.ListUHDTrial() +except Common.IpwwwError as err: + xbmcgui.Dialog().ok(Common.translation(30400), str(err)) + sys.exit(1) xbmcplugin.endOfDirectory(int(sys.argv[1])) diff --git a/plugin.video.iplayerwww/resources/language/resource.language.en_gb/strings.po b/plugin.video.iplayerwww/resources/language/resource.language.en_gb/strings.po index bfd8475b24..8a6ece324b 100644 --- a/plugin.video.iplayerwww/resources/language/resource.language.en_gb/strings.po +++ b/plugin.video.iplayerwww/resources/language/resource.language.en_gb/strings.po @@ -392,6 +392,10 @@ msgctxt "#30413" msgid "Please check you installed this plugin correctly." msgstr "" +msgctxt "#30414" +msgid "This BBC Sounds programme is available to play in the UK only." +msgstr "" + msgctxt "#30500" msgid "Display" msgstr "" @@ -475,4 +479,3 @@ msgstr "" msgctxt "#30529" msgid "iPlayer: UHD Trial Channels" msgstr "" - diff --git a/plugin.video.iplayerwww/resources/lib/ipwww_common.py b/plugin.video.iplayerwww/resources/lib/ipwww_common.py index 7391c1e9ef..311541f44b 100644 --- a/plugin.video.iplayerwww/resources/lib/ipwww_common.py +++ b/plugin.video.iplayerwww/resources/lib/ipwww_common.py @@ -11,7 +11,6 @@ import html import codecs import time -import json import xbmc import xbmcvfs @@ -28,6 +27,14 @@ ADDON = xbmcaddon.Addon(id='plugin.video.iplayerwww') +class IpwwwError(Exception): + pass + + +class GeoBlockedError(IpwwwError): + pass + + def tp(path): return xbmcvfs.translatePath(path) @@ -395,35 +402,6 @@ def OpenURLPost(url, post_data): return r -def GetJWT(url): - with requests.Session() as session: - session.cookies = cookie_jar - session.headers = headers - try: - r = session.get(url, allow_redirects=False) - except requests.exceptions.RequestException as e: - dialog = xbmcgui.Dialog() - dialog.ok(translation(30400), "%s" % e) - sys.exit(1) - try: - #Set ignore_discard to overcome issue of not having session - #as cookie_jar is reinitialised for each action. - # Refreshed token cookies are set on intermediate requests. - # Only save if there have been any. - if r.history: - cookie_jar.save(ignore_discard=True) - if r.text: - match = re.search(r'', r.text, re.DOTALL) - if match: - json_data = json.loads(match[1]) - if 'smp' in json_data: - if 'liveStreamJwt' in json_data['smp']: - return json_data['smp']['liveStreamJwt'] - except: - pass - return None - - def GetCookieJar(): return cookie_jar diff --git a/plugin.video.iplayerwww/resources/lib/ipwww_radio.py b/plugin.video.iplayerwww/resources/lib/ipwww_radio.py index 5fde861f2f..8e35bade01 100644 --- a/plugin.video.iplayerwww/resources/lib/ipwww_radio.py +++ b/plugin.video.iplayerwww/resources/lib/ipwww_radio.py @@ -5,7 +5,7 @@ import re from operator import itemgetter from resources.lib.ipwww_common import translation, AddMenuEntry, OpenURL, \ - CheckLogin, CreateBaseDirectory, GetJWT + CheckLogin, CreateBaseDirectory, GeoBlockedError import xbmc import xbmcvfs @@ -17,6 +17,21 @@ ADDON = xbmcaddon.Addon(id='plugin.video.iplayerwww') + +def GetJWT(url): + html = OpenURL(url) + try: + match = re.search(r'', html, re.DOTALL) + if match: + json_data = json.loads(match[1]) + if 'smp' in json_data: + if 'liveStreamJwt' in json_data['smp']: + return json_data['smp']['liveStreamJwt'] + except: + pass + return None + + def GetAtoZPage(page_url, just_episodes=False): """ Generic Radio page scraper. """ @@ -378,9 +393,7 @@ def PlayStream(name, url, iconimage, description, subtitles_url): '

Access Denied

', html) if check_geo or not html: # print "Geoblock detected, raising error message" - dialog = xbmcgui.Dialog() - dialog.ok(translation(30400), translation(30401)) - raise + raise GeoBlockedError(translation(30414)) liz = xbmcgui.ListItem(name) liz.setArt({'icon':'DefaultVideo.png', 'thumb':iconimage}) @@ -874,9 +887,7 @@ def ParseStreams(stream_id, jwt): elif 'result' in json_data: if json_data['result'] == 'geolocation': # print "Geoblock detected, raising error message" - dialog = xbmcgui.Dialog() - dialog.ok(translation(30400), translation(30401)) - raise + raise GeoBlockedError(translation(30414)) return retlist diff --git a/plugin.video.iplayerwww/resources/lib/ipwww_video.py b/plugin.video.iplayerwww/resources/lib/ipwww_video.py index dac35217ed..33f31469a8 100644 --- a/plugin.video.iplayerwww/resources/lib/ipwww_video.py +++ b/plugin.video.iplayerwww/resources/lib/ipwww_video.py @@ -11,7 +11,7 @@ from operator import itemgetter from resources.lib.ipwww_common import translation, AddMenuEntry, OpenURL, \ CheckLogin, CreateBaseDirectory, GetCookieJar, \ - ParseImageUrl, download_subtitles + ParseImageUrl, download_subtitles, GeoBlockedError import xbmc import xbmcvfs @@ -986,9 +986,7 @@ def PlayStream(name, url, iconimage, description, subtitles_url): '

Access Denied

', html) if check_geo or not html: # print "Geoblock detected, raising error message" - dialog = xbmcgui.Dialog() - dialog.ok(translation(30400), translation(30401)) - raise + raise GeoBlockedError(translation(30401)) liz = xbmcgui.ListItem(name) liz.setArt({'icon':'DefaultVideo.png', 'thumb':iconimage}) liz.setInfo(type='Video', infoLabels={'Title': name}) @@ -1067,9 +1065,7 @@ def ParseMediaselector(stream_id): elif 'result' in json_data: if json_data['result'] == 'geolocation': # print "Geoblock detected, raising error message" - dialog = xbmcgui.Dialog() - dialog.ok(translation(30400), translation(30401)) - raise + raise GeoBlockedError(translation(30401)) # print("Found streams:") # print(streams) # print(subtitles)