Skip to content

Commit 51e2c18

Browse files
author
bossanova808
committed
[weather.ozweather] 2.1.9
1 parent 0b5b058 commit 51e2c18

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

weather.ozweather/addon.xml

Lines changed: 4 additions & 4 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="weather.ozweather" name="OzWeather" version="2.1.8" provider-name="Bossanova808">
2+
<addon id="weather.ozweather" name="OzWeather" version="2.1.9" provider-name="Bossanova808">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0"/>
55
<import addon="script.module.requests" version="2.22.0+matrix.1"/>
@@ -16,15 +16,15 @@
1616
<language>en</language>
1717
<license>GPL-3.0-only</license>
1818
<forum>https://forum.kodi.tv/showthread.php?tid=116905</forum>
19-
<website>https://kodi.wiki/index.php?title=Add-on:Oz_Weather</website>
19+
<website>https://kodi.wiki/index.php?title=Add-on:OzWeather</website>
2020
<email>bossanova808@gmail.com</email>
2121
<source>https://github.com/bossanova808/weather.ozweather</source>
2222
<assets>
2323
<icon>icon.png</icon>
2424
<fanart>fanart.jpg</fanart>
2525
</assets>
26-
<news>v2.1.8
27-
- Add RadarRange label
26+
<news>v2.1.9
27+
- Fix ABC weather video scraping due to upstream changes
2828
</news>
2929
</extension>
3030
</addon>

weather.ozweather/changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
v2.1.9
2+
- Fix ABC weather video scraping due to upstream changes
3+
14
v2.1.8
25
- Add RadarRange label
36

weather.ozweather/resources/lib/abc/abc_video.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import requests
2+
import re
23
import sys
34
import xbmc
45
import xbmcgui
@@ -35,7 +36,6 @@ def scrape_and_play_abc_weather_video():
3536
pass
3637

3738

38-
# See bottom of this file for notes on matching the video links (& Store.py for the regex)
3939
def get_abc_weather_video_link():
4040
try:
4141
r = requests.get(Store.ABC_URL, timeout=15)
@@ -45,16 +45,47 @@ def get_abc_weather_video_link():
4545
error_msg = "ABC __NEXT_DATA__ script not found on page, couldn't extract ABC weather video link"
4646
Logger.error(error_msg)
4747
raise ValueError(error_msg)
48+
4849
json_object = json.loads(json_string.string)
50+
4951
# Logger.debug(json_object)
5052
# Put the json blob into: https://jsonhero.io/j/JU0I9LB4AlLU
5153
# Gives a path to the needed video as:
5254
# $.props.pageProps.channelpage.components.0.component.props.list.3.player.config.sources.1.file
5355
# Rather than grab the URL directly (as place in array might change), grab all the available URLs and get the best quality from it
5456
# See: https://github.com/bossanova808/weather.ozweather/commit/e6158d704fc160808bf66220da711805860d85c7
55-
data = json_object['props']['pageProps']['channelpage']['components'][0]['component']['props']['list'][3]
56-
urls = [x for x in data['player']['config']['sources'] if x['type'] == 'video/mp4']
57-
return sorted(urls, key=lambda x: x['bitrate'], reverse=True)[0]['file']
57+
58+
items = json_object['props']['pageProps']['channelpage']['components'][0]['component']['props']['list']
59+
60+
data = next((item for item in items if item.get('player', {}).get('config', {}).get('sources')), None)
61+
if not data:
62+
Logger.error("No player sources found in ABC JSON")
63+
return ""
64+
65+
# urls_all = data['player']['config']['sources']
66+
# Logger.debug(f"ALL ABC video sources (unfiltered): {urls_all}")
67+
68+
urls = [x for x in data['player']['config']['sources'] if x.get('type') == 'video/mp4']
69+
if not urls:
70+
Logger.error("No MP4 sources found in ABC player config")
71+
return ""
72+
73+
Logger.debug(f"ABC video sources available: {[{k: v for k, v in u.items() if k != 'type'} for u in urls]}")
74+
75+
def quality_key(source):
76+
if 'fileSize' in source:
77+
return source['fileSize']
78+
match = re.search(r'(\d+)p', source.get('label', '0'))
79+
return int(match.group(1)) if match else 0
80+
81+
url = sorted(urls, key=quality_key, reverse=True)[0].get('file', '')
82+
83+
if not url or not re.match(r'^https?://[^/\s]+', url):
84+
Logger.error(f"ABC returned a weird video URL?!: {url}")
85+
return ""
86+
87+
Logger.debug(f"Selected ABC video: {url} (from {len(urls)} sources)")
88+
return url
5889

5990
except Exception as inst:
6091
Logger.error(f"Couldn't get ABC video URL from scraped page: {inst}")

0 commit comments

Comments
 (0)