Skip to content

Commit

Permalink
Merge pull request #2469 from bossanova808/weather.ozweather@matrix
Browse files Browse the repository at this point in the history
[weather.ozweather@matrix] 2.0.9
  • Loading branch information
basrieter authored Jun 11, 2023
2 parents cb56d9e + f320c43 commit 59c7e32
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
6 changes: 3 additions & 3 deletions weather.ozweather/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="weather.ozweather" name="Oz Weather" version="2.0.8" provider-name="Bossanova808">
<addon id="weather.ozweather" name="Oz Weather" version="2.0.9" provider-name="Bossanova808">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests" version="2.22.0+matrix.1"/>
Expand All @@ -22,8 +22,8 @@
<icon>icon.png</icon>
<fanart>fanart.jpg</fanart>
</assets>
<news>v2.0.8
- Fix for moved ABC weather videos, update list of radars
<news>2.0.9
- Better fix for ABC weather video
</news>
</extension>
</addon>
3 changes: 3 additions & 0 deletions weather.ozweather/changelog.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Binary file removed weather.ozweather/resources/ABC.png
Binary file not shown.
28 changes: 17 additions & 11 deletions weather.ozweather/resources/lib/abc/abc_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
Expand All @@ -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 ""


Expand Down
6 changes: 2 additions & 4 deletions weather.ozweather/resources/lib/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 59c7e32

Please sign in to comment.