diff --git a/weather.ozweather/addon.xml b/weather.ozweather/addon.xml index 2e65baa313..7f5e62ffe2 100644 --- a/weather.ozweather/addon.xml +++ b/weather.ozweather/addon.xml @@ -1,5 +1,5 @@ - + @@ -22,8 +22,8 @@ icon.png fanart.jpg - v2.0.8 - - Fix for moved ABC weather videos, update list of radars + 2.0.9 + - Better fix for ABC weather video diff --git a/weather.ozweather/changelog.txt b/weather.ozweather/changelog.txt index 819ea7bc25..19820c4174 100644 --- a/weather.ozweather/changelog.txt +++ b/weather.ozweather/changelog.txt @@ -1,3 +1,6 @@ +2.0.9 +- Better fix for ABC weather video + 2.0.8 - Fix for moved ABC weather videos, update list of radars diff --git a/weather.ozweather/resources/ABC.png b/weather.ozweather/resources/ABC.png deleted file mode 100644 index 5753e290a1..0000000000 Binary files a/weather.ozweather/resources/ABC.png and /dev/null differ diff --git a/weather.ozweather/resources/lib/abc/abc_video.py b/weather.ozweather/resources/lib/abc/abc_video.py index 3bfa17d6ee..3877b70e83 100644 --- a/weather.ozweather/resources/lib/abc/abc_video.py +++ b/weather.ozweather/resources/lib/abc/abc_video.py @@ -3,6 +3,8 @@ import re import sys import xbmc +import json +from bs4 import BeautifulSoup # Small hack to allow for unit testing - see common.py for explanation if not xbmc.getUserAgent(): @@ -21,7 +23,7 @@ def scrape_and_play_abc_weather_video(): item = xbmcgui.ListItem(path=url) item.setProperty('mimetype', 'video/mpeg') item.setInfo('Video', { 'title' : 'ABC Weather In 90 Seconds'}) - item.setArt({'thumb': f'{CWD}/resources/ABC.png'}) + item.setArt({'thumb': f'{CWD}/resources/weather-in-90-seconds.png'}) # ...and then play it, fullscreen xbmc.Player().play(url, item, False) pass @@ -32,20 +34,24 @@ def get_abc_weather_video_link(): try: r = requests.get(Store.ABC_URL) - videos = re.findall(Store.ABC_WEATHER_VIDEO_PATTERN, r.text) - # for video in videos: - # log(video) + bs = BeautifulSoup(r.text, "html.parser") + json_string = bs.find("script", {'type': 'application/json',"id": "__NEXT_DATA__"}) - try: - url = f'{Store.ABC_STUB}/{videos[1][0]}/{videos[1][1]}/{videos[1][2]}/{videos[1][3]}.mp4' - return url - except Exception as inst: - log("Couldn't get ABC video URL from scraped page: " + str(inst)) - return "" + json_object = json.loads(json_string.string) + + # log(json_object) + # Put the json blob into: https://jsonhero.io/j/JU0I9LB4AlLU + # Gives a path to the needed video as: + # $.props.pageProps.channelpage.components.0.component.props.list.3.player.config.sources.1.file + # Rather than grab the URL directly (as place in array might change), grab all the available URLs and get the best quality from it + # See: https://github.com/bossanova808/weather.ozweather/commit/e6158d704fc160808bf66220da711805860d85c7 + data = json_object['props']['pageProps']['channelpage']['components'][0]['component']['props']['list'][3] + urls = [x for x in data['player']['config']['sources'] if x['type'] == 'video/mp4'] + return sorted(urls, key=lambda x: x['bitrate'], reverse=True)[0]['file'] except Exception as inst: - log("********** Couldn't get ABC video page at all: " + str(inst)) + log("Couldn't get ABC video URL from scraped page: " + str(inst)) return "" diff --git a/weather.ozweather/resources/lib/store.py b/weather.ozweather/resources/lib/store.py index 166d691c8f..da3e9e3f0e 100644 --- a/weather.ozweather/resources/lib/store.py +++ b/weather.ozweather/resources/lib/store.py @@ -10,10 +10,8 @@ class Store: # CONSTANTS # ABC WEATHER VIDEO - scraping - ABC_URL = "https://www.abc.net.au/news/weather" - ABC_STUB = "https://mediacore-live-production.akamaized.net/video" - # 2023 version - E.g. https://mediacore-live-production.akamaized.net/video/01/im/Z/0m.mp4 - ABC_WEATHER_VIDEO_PATTERN = r"https://mediacore-live-production.akamaized.net/video/(.+?)/(.+?)/(.+?)/(.+?)\.mp" + ABC_URL = "https://www.abc.net.au/news/newschannel/news-in-90-seconds" + # BOM - JSON API BOM_URL = 'http://www.bom.gov.au' BOM_API_URL = 'https://api.weather.bom.gov.au/v1' diff --git a/weather.ozweather/resources/weather-in-90-seconds.png b/weather.ozweather/resources/weather-in-90-seconds.png new file mode 100644 index 0000000000..abcde43c1f Binary files /dev/null and b/weather.ozweather/resources/weather-in-90-seconds.png differ