diff --git a/weather.ozweather/addon.xml b/weather.ozweather/addon.xml index 1a1dfc689..2e65baa31 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.6 - - Update list of radars + v2.0.8 + - Fix for moved ABC weather videos, update list of radars diff --git a/weather.ozweather/changelog.txt b/weather.ozweather/changelog.txt index ce20ddbec..819ea7bc2 100644 --- a/weather.ozweather/changelog.txt +++ b/weather.ozweather/changelog.txt @@ -1,3 +1,6 @@ +2.0.8 +- Fix for moved ABC weather videos, update list of radars + 2.0.6 - Update list of radars diff --git a/weather.ozweather/resources/ABC.png b/weather.ozweather/resources/ABC.png new file mode 100644 index 000000000..5753e290a Binary files /dev/null and b/weather.ozweather/resources/ABC.png differ diff --git a/weather.ozweather/resources/lib/abc/abc_video.py b/weather.ozweather/resources/lib/abc/abc_video.py index 3a02a7c7c..3bfa17d6e 100644 --- a/weather.ozweather/resources/lib/abc/abc_video.py +++ b/weather.ozweather/resources/lib/abc/abc_video.py @@ -12,17 +12,33 @@ from resources.lib.common import * -def get_abc_weather_video_link(quality): +def scrape_and_play_abc_weather_video(): + """ + On-demand scrape the current ABC video URL and then play it back, with appropriate metadata/art etc. + """ + url = get_abc_weather_video_link() + # Construct an offscreen list item with metadata... + 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'}) + # ...and then play it, fullscreen + xbmc.Player().play(url, item, False) + pass - # Seems like the best/trw option has been removed, so just map these to 1000k - if quality == "Best" or quality == "trw": - quality = "1000k" + +# See bottom of this file for notes on matching the video links (& Store.py for the regex) +def get_abc_weather_video_link(): try: r = requests.get(Store.ABC_URL) - video = re.findall(Store.ABC_WEATHER_VIDEO_PATTERN, r.text) + videos = re.findall(Store.ABC_WEATHER_VIDEO_PATTERN, r.text) + + # for video in videos: + # log(video) + try: - url = f'{Store.ABC_STUB}{video[0][0]}/WIN{video[0][1]}_{quality}.mp4' + 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)) @@ -36,14 +52,21 @@ def get_abc_weather_video_link(quality): # UNIT TESTING if __name__ == "__main__": log("\nTesting scraping of ABC Weather Video - here's the 'Best' link:\n") - log(get_abc_weather_video_link("Best") + "\n") + log(get_abc_weather_video_link()) -# ABC VIDEO URL NOTES +# > 2023_05 - CURRENT ABC VIDEO URL NOTES +# view the source on: https://www.abc.net.au/news/weather +# search for 'mp4' +# Regex in Store.py used to match the URL format +# Multiple matches will be found - first is a definition/download link (.mpg) +# 2nd is the highest quality stream (720p) - the one we want. +# https://mediacore-live-production.akamaized.net/video/01/im/Z/0m.mp4 + +# < 2023_05 - LEGACY INFO # note date and quality level variables... -# view source on https://www.abc.net.au/news/newschannel/weather-in-90-seconds/ and find mp4 to see this list, +# view source on https://www.abc.net.au/news/newschannel/weather-in-90-seconds/ and find mp4 to see this list, # the end of the URL can change regularly - # {'url': 'https://abcmedia.akamaized.net/news/news24/wins/201403/WINs_Weather1_0703_1000k.mp4', 'contentType': 'video/mp4', 'codec': 'AVC', 'bitrate': '928', 'width': '1024', 'height': '576', 'filesize': '11657344'} # {'url': 'https://abcmedia.akamaized.net/news/news24/wins/201403/WINs_Weather1_0703_256k.mp4', 'contentType': 'video/mp4', 'codec': 'AVC', 'bitrate': '170', 'width': '320', 'height': '180', 'filesize': '2472086'} # {'url': 'https://abcmedia.akamaized.net/news/news24/wins/201403/WINs_Weather1_0703_512k.mp4', 'contentType': 'video/mp4', 'codec': 'AVC', 'bitrate': '400', 'width': '512', 'height': '288', 'filesize': '5328218'} @@ -51,4 +74,3 @@ def get_abc_weather_video_link(quality): # Other URLs - should match any of these # https://abcmedia.akamaized.net/news/news24/wins/201409/WINm_Update1_0909_VSB03WF2_512k.mp4& # https://abcmedia.akamaized.net/news/news24/wins/201409/WINs_Weather2_0209_trw.mp4 - diff --git a/weather.ozweather/resources/lib/bom/bom_forecast.py b/weather.ozweather/resources/lib/bom/bom_forecast.py index 27fa99cae..5039d1590 100644 --- a/weather.ozweather/resources/lib/bom/bom_forecast.py +++ b/weather.ozweather/resources/lib/bom/bom_forecast.py @@ -18,8 +18,9 @@ """ -# This is a hack fix for a wicked long standing Python bug... +# This is a hack fix for a wicked long-standing Python bug... # See: https://forum.kodi.tv/showthread.php?tid=112916 +# noinspection PyMethodOverriding,PyShadowingBuiltins,SpellCheckingInspection class ProxyDatetime(datetime.datetime): @staticmethod def strptime(date_string, format): @@ -30,6 +31,7 @@ def strptime(date_string, format): datetime.datetime = ProxyDatetime +# noinspection PyShadowingNames def set_key(weather_data, index, key, value): """ Set a key - for old and new weather label support @@ -50,6 +52,7 @@ def set_key(weather_data, index, key, value): weather_data['Daily.' + str(index + 1) + '.' + key] = value.strip() +# noinspection PyShadowingNames def set_keys(weather_data, index, keys, value): """ Set a group of keys at once - for old and new weather label support @@ -91,6 +94,7 @@ def utc_str_to_local_str(utc_str: str, utc_format: str = '%Y-%m-%dT%H:%M:%SZ', l return local_time.strftime(local_format).lstrip('0').lower() +# noinspection PyBroadException,PyShadowingNames def bom_forecast(geohash): """ Return are information, current observations, warnings, and forecast for the given geohash @@ -102,8 +106,6 @@ def bom_forecast(geohash): # Gather the weather data into a dict from which we will later set all the Kodi labels weather_data = {} - - # The areahash is the geohash minus the last character areahash = geohash[:-1] @@ -116,18 +118,18 @@ def bom_forecast(geohash): bom_api_current_observations_url = f'{bom_api_url_areahash}/observations' bom_api_forecast_seven_days_url = f'{bom_api_url_areahash}/forecasts/daily' # FUTURE? - these API end points exist, but are not yet used by OzWeather - bom_api_forecast_three_hourly_url = f'{bom_api_url_areahash}/forecasts/3-hourly' - bom_api_forecast_rain = f'{bom_api_url_areahash}/forecast/rain' + # bom_api_forecast_three_hourly_url = f'{bom_api_url_areahash}/forecasts/3-hourly' + # bom_api_forecast_rain = f'{bom_api_url_areahash}/forecast/rain' # Holders for the BOM JSON API results... area_information = None - current_observations = None + # current_observations = None warnings = None - forecast_seven_days = None + # forecast_seven_days = None # forecast_three_hourly = None # forecast_rain = None - # Get the AREA INFORMATION, including the location's timezone so we can correctly show the location local times + # Get the AREA INFORMATION, including the location's timezone, so we can correctly show the location local times location_timezone = "" # In case we can't get the localised now time, below... now = datetime.datetime.now() @@ -143,7 +145,7 @@ def bom_forecast(geohash): # For any date comparisons - this is the localised now... now = datetime.datetime.now(location_timezone) - except Exception as inst: + except: log(f'Error retrieving area information from {bom_api_area_information_url}') # Get CURRENT OBSERVATIONS @@ -154,7 +156,7 @@ def bom_forecast(geohash): weather_data['ObservationsStation'] = r.json()["data"]['station']['name'] log(current_observations) - except Exception as inst: + except: log(f'Error retrieving current observations from {bom_api_current_observations_url}') return False @@ -164,10 +166,10 @@ def bom_forecast(geohash): warnings = r.json()["data"] log(warnings) - except Exception as inst: + except: log(f'Error retrieving warnings from {bom_api_warnings_url}') - # Get 7 DAY FORECAST + # Get 7-DAY FORECAST try: r = requests.get(bom_api_forecast_seven_days_url) forecast_seven_days = r.json()["data"] @@ -176,7 +178,7 @@ def bom_forecast(geohash): weather_data['ForecastType'] = r.json()["metadata"]["forecast_type"].title() log(forecast_seven_days) - except Exception as inst: + except: log(f'Error retrieving seven day forecast from {bom_api_forecast_seven_days_url}') return False @@ -203,11 +205,11 @@ def bom_forecast(geohash): # CURRENT OBSERVATIONS - # IMPORTANT - to avoid issues with Kodi malforming weather values due to 'magic' - # (the magic is presumably because Kodi seeks to support both farenheit and celsius, so unofrtunately tends to return 0 - # for any non-numeric value in these labels... + # IMPORTANT - to avoid issues with Kodi mal-forming weather values due to 'magic' + # (the magic is presumably because Kodi seeks to support both Fahrenheit and Celsius, so unfortunately tends to return 0 + # for any non-numeric value in these labels...) # ...So, we set the normal Kodi weather labels as best we can. - # ...But, we also set a version with OzW_ prepended to the label name, which is used in OzWeather Skin files to avoid this. + # ...But, we also set a version with OzW_ prepended to the label name, which is used in OzWeather Skin files, to avoid this. if current_observations: weather_data['Current.Temperature'] = current_observations['temp'] @@ -247,7 +249,7 @@ def bom_forecast(geohash): warnings_text = "" if warnings: for i, warning in enumerate(warnings): - # Warnings body...only major warnings as we don't need every little message about sheep grazing etc.. + # Warnings body...only major warnings as we don't need every little message about sheep grazing etc... if warning['warning_group_type'] == 'major': # Don't really care when it was issue, if it hasn't expired, it's current, so show it.. # warning_issued = utc_str_to_local_str(warning['issue_time'], local_format='%d/%m %I:%M%p', time_zone=location_timezone) @@ -311,6 +313,7 @@ def bom_forecast(geohash): # However, preferentially try and use the short text, to cope with BOM madness like: # "icon_descriptor":"mostly_sunny","short_text":"Mostly cloudy." icon_descriptor = forecast_seven_days[i]['icon_descriptor'] + descriptor_from_short_text = None if forecast_seven_days[i]['short_text']: descriptor_from_short_text = forecast_seven_days[i]['short_text'].lower() descriptor_from_short_text = descriptor_from_short_text.replace(' ', '_').replace('.', '').strip() @@ -393,7 +396,7 @@ def bom_forecast(geohash): # TESTING for skin scrolling - DON'T LEAVE THIS UNCOMMENTED! # for j in range(0, 5): - # extended_text += "add some more random text on the end so it just goes on and on\n" + # extended_text += "add some more random text on the end, so it just goes on and on\n" set_key(weather_data, i, "OutlookLong", extended_text) set_key(weather_data, i, "ConditionLong", extended_text) @@ -415,12 +418,12 @@ def bom_forecast(geohash): geohashes_to_test = ['r1r11df', 'r1f94ew'] for geohash in geohashes_to_test: log(f'Getting weather data from BOM for geohash "{geohash}"') - weather_data = bom_forecast(geohash) + test_data = bom_forecast(geohash) - for key in sorted(weather_data): - if weather_data[key] == "?" or weather_data[key] == "na": + for key in sorted(test_data): + if test_data[key] == "?" or test_data[key] == "na": log("**** MISSING: ") - log(f'{key}: "{weather_data[key]}"') + log(f'{key}: "{test_data[key]}"') """ BOM API diff --git a/weather.ozweather/resources/lib/bom/bom_location.py b/weather.ozweather/resources/lib/bom/bom_location.py index 812b22b9f..9e1e13699 100644 --- a/weather.ozweather/resources/lib/bom/bom_location.py +++ b/weather.ozweather/resources/lib/bom/bom_location.py @@ -6,8 +6,6 @@ if not xbmc.getUserAgent(): sys.path.insert(0, '../../..') -from resources.lib.store import Store -from resources.lib.common import * from resources.lib.bom.bom_radar import * @@ -31,7 +29,7 @@ def get_bom_locations_for(text): return locations, location_geohashes except Exception as inst: - log(f'Exception getting locations from {bom_locations_api} for search term {text}') + log(f'Exception getting locations from {Store.BOM_API_LOCATIONS_URL} for search term {text}') log(str(inst)) raise diff --git a/weather.ozweather/resources/lib/bom/bom_radar.py b/weather.ozweather/resources/lib/bom/bom_radar.py index 41da3e579..f5dfd0789 100644 --- a/weather.ozweather/resources/lib/bom/bom_radar.py +++ b/weather.ozweather/resources/lib/bom/bom_radar.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -import datetime import ftplib import glob import os @@ -9,7 +8,6 @@ import urllib.error import urllib.parse import urllib.request -import urllib3 from math import sin, cos, sqrt, atan2, radians import xbmc @@ -21,6 +19,7 @@ from resources.lib.common import * +# noinspection PyPep8Naming def get_distance(point1, point2): """ Given two (lat,long) tuples return the distance between them @@ -71,12 +70,12 @@ def dump_all_radar_backgrounds(all_backgrounds_path=None): time.sleep(0.5) -def download_background(radar_code, file_name, backgrounds_path): +def download_background(radar_code, file_name, path): """ Downloads a radar background given a BOM radar code like IDR023 & an output filename - :param radar_code: BOM radar code e.g. 'IDRO023' + :param radar_code: BOM radar code e.g. 'IDR0023' :param file_name: File name to download, e.g. 'locations.png' (see special cases below) - :param backgrounds_path: Path to save the background images + :param path: Path to save the background images """ # Needed due to bug in python 2.7 urllib, doesn't hurt anything else, so leave it in... @@ -109,7 +108,7 @@ def download_background(radar_code, file_name, backgrounds_path): # log("Using cached background - " + out_file_name) # Download the backgrounds only if we don't have them yet - if not os.path.isfile(backgrounds_path + out_file_name): + if not os.path.isfile(path + out_file_name): log("Downloading missing background image....[%s] as [%s]" % (file_name, out_file_name)) @@ -120,7 +119,7 @@ def download_background(radar_code, file_name, backgrounds_path): try: radar_image = urllib.request.urlopen(url_to_get) - with open(backgrounds_path + "/" + out_file_name, "wb") as fh: + with open(path + "/" + out_file_name, "wb") as fh: fh.write(radar_image.read()) except Exception as e: @@ -130,43 +129,43 @@ def download_background(radar_code, file_name, backgrounds_path): log(f"Using cached {out_file_name}") -def prepare_backgrounds(radar_code, backgrounds_path): +def prepare_backgrounds(radar_code, path): """ Download backgrounds for given radar """ log("Calling prepareBackgrounds on [%s]" % radar_code) - download_background(radar_code, "IDR.legend.0.png", backgrounds_path) - download_background(radar_code, "background.png", backgrounds_path) + download_background(radar_code, "IDR.legend.0.png", path) + download_background(radar_code, "background.png", path) # these images don't exist for the national radar, so don't try and get them if radar_code != "IDR00004": - download_background(radar_code, "locations.png", backgrounds_path) - download_background(radar_code, "range.png", backgrounds_path) - download_background(radar_code, "topography.png", backgrounds_path) - download_background(radar_code, "waterways.png", backgrounds_path) + download_background(radar_code, "locations.png", path) + download_background(radar_code, "range.png", path) + download_background(radar_code, "topography.png", path) + download_background(radar_code, "waterways.png", path) -def build_images(radar_code, backgrounds_path, overlay_loop_path): +def build_images(radar_code, path, loop_path): """ Builds the radar images given a BOM radar code like IDR023 The radar images are stored for maximum two hours, backgrounds forever (user can purge the radar background in the addon settings if need be, will force a re-download on next refresh) :param radar_code: BOM Radar code, e.g. 'IDR023' - :param backgrounds_path: path to store the radar backgrounds - :param overlay_loop_path: path to store the radar loop images + :param path: path to store the radar backgrounds + :param loop_path: path to store the radar loop images """ - # grab the current time as as 12 digit 0 padded string + # grab the current time as 12 digit 0 padded string time_now = format(int(time.time()), '012d') log("build_images(%s)" % radar_code) - log("Overlay loop path: " + overlay_loop_path) - log("Backgrounds path: " + backgrounds_path) + log("Overlay loop path: " + loop_path) + log("Backgrounds path: " + path) log("Deleting any radar overlays older than an hour, that's long enough to see what has passed plus not take too long to loop") - current_files = glob.glob(overlay_loop_path + "/*.png") + current_files = glob.glob(loop_path + "/*.png") for count, file in enumerate(current_files): filetime = os.path.getmtime(file) two_hours_ago = time.time() - (1 * 60 * 60) @@ -175,20 +174,21 @@ def build_images(radar_code, backgrounds_path, overlay_loop_path): log("Deleted aged radar image " + str(os.path.basename(file))) # rename the currently kept radar backgrounds to prevent Kodi caching from displaying stale images - current_files = glob.glob(overlay_loop_path + "/*.png") + current_files = glob.glob(loop_path + "/*.png") for file in current_files: os.rename(file, os.path.dirname(file) + "/" + time_now + "." + os.path.basename(file)[13:]) # create the folder for the backgrounds path if it does not yet exist - if not os.path.exists(backgrounds_path): + if not os.path.exists(path): attempts = 0 success = False while not success and (attempts < 20): + # noinspection PyBroadException try: - os.makedirs(backgrounds_path) + os.makedirs(path) success = True - log("Successfully created " + backgrounds_path) - except Exception: + log("Successfully created " + path) + except: attempts += 1 time.sleep(0.1) if not success: @@ -196,15 +196,16 @@ def build_images(radar_code, backgrounds_path, overlay_loop_path): return # ...and create the folder for the radar loop if it does not yet exist - if not os.path.exists(overlay_loop_path): + if not os.path.exists(loop_path): attempts = 0 success = False while not success and (attempts < 20): + # noinspection PyBroadException try: - os.makedirs(overlay_loop_path) + os.makedirs(loop_path) success = True - log("Successfully created " + overlay_loop_path) - except Exception: + log("Successfully created " + loop_path) + except: attempts += 1 time.sleep(0.1) if not success: @@ -212,7 +213,7 @@ def build_images(radar_code, backgrounds_path, overlay_loop_path): return # If for any reason we're missing any background images, this will go get them... - prepare_backgrounds(radar_code, backgrounds_path) + prepare_backgrounds(radar_code, path) # Ok so we should have the backgrounds...now it is time get the current radar loop # first we retrieve a list of the available files via ftp @@ -227,6 +228,7 @@ def build_images(radar_code, backgrounds_path, overlay_loop_path): # Try up to 3 times, with a seconds pause between each, to connect to BOM FTP # (to try and get past very occasional 'too many users' errors) while not ftp and attempts < 3: + # noinspection PyBroadException try: ftp = ftplib.FTP("ftp.bom.gov.au") except: @@ -269,7 +271,7 @@ def build_images(radar_code, backgrounds_path, overlay_loop_path): # which is why we can test here with the current time_now to see if we already have the images) if loop_pic_names: for f in loop_pic_names: - if not os.path.isfile(overlay_loop_path + time_now + "." + f): + if not os.path.isfile(loop_path + time_now + "." + f): # ignore the composite gif... if f[-3:] == "png": image_to_retrieve = Store.BOM_RADAR_FTPSTUB + f @@ -279,7 +281,7 @@ def build_images(radar_code, backgrounds_path, overlay_loop_path): try: radar_image = urllib.request.urlopen(image_to_retrieve) - with open(overlay_loop_path + "/" + output_file, "wb") as fh: + with open(loop_path + "/" + output_file, "wb") as fh: fh.write(radar_image.read()) except Exception as e: @@ -295,10 +297,11 @@ def build_images(radar_code, backgrounds_path, overlay_loop_path): # Run this with a 'clean' argument to first wipe any test files that exist if len(sys.argv) > 1 and sys.argv[1] == "clean": + # noinspection PyBroadException try: log("\n\nCleaning test-outputs folder") shutil.rmtree(os.getcwd() + "/test-outputs/") - except Exception as inst: + except: pass log("\nCurrent files in test-outputs:\n") diff --git a/weather.ozweather/resources/lib/bom/bom_radar_scrape_latest.py b/weather.ozweather/resources/lib/bom/bom_radar_scrape_latest.py index 1358b7ded..6ccc22ef7 100644 --- a/weather.ozweather/resources/lib/bom/bom_radar_scrape_latest.py +++ b/weather.ozweather/resources/lib/bom/bom_radar_scrape_latest.py @@ -2,6 +2,7 @@ import re import requests +# noinspection PyUnresolvedReferences from pprint import pprint from bs4 import BeautifulSoup diff --git a/weather.ozweather/resources/lib/common.py b/weather.ozweather/resources/lib/common.py index f30b65ed0..81c8a2707 100644 --- a/weather.ozweather/resources/lib/common.py +++ b/weather.ozweather/resources/lib/common.py @@ -25,6 +25,7 @@ LANGUAGE = ADDON.getLocalizedString PROFILE = xbmcvfs.translatePath(ADDON.getAddonInfo('profile')) KODI_VERSION = xbmc.getInfoLabel('System.BuildVersion') +# noinspection SpellCheckingInspection USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" HOME_WINDOW = xbmcgui.Window(10000) WEATHER_WINDOW = xbmcgui.Window(12600) @@ -58,9 +59,9 @@ print("\nNo user agent, must be unit testing.\n") def log(message, exception_instance=None, level=None): - print(f'DEBUG: {message}') + print(f'DEBUG {level}: {message}') if exception_instance: - print(f'EXCPT: {traceback.format_exc(exception_instance)}') + print(f'EXCEPTION: {traceback.format_exc(exception_instance)}') else: @@ -150,7 +151,7 @@ def get_setting_as_bool(setting): Helper function to get bool type from settings @param setting: - @return: setting value as boolen + @return: setting value as boolean """ return get_setting(setting).lower() == "true" diff --git a/weather.ozweather/resources/lib/forecast.py b/weather.ozweather/resources/lib/forecast.py index d4ebd65af..33cdbad60 100644 --- a/weather.ozweather/resources/lib/forecast.py +++ b/weather.ozweather/resources/lib/forecast.py @@ -1,9 +1,9 @@ -import xbmcplugin - +# noinspection PyPackages from .abc.abc_video import * +# noinspection PyPackages from .bom.bom_radar import * +# noinspection PyPackages from .bom.bom_forecast import * -from pathlib import Path def clear_properties(): @@ -118,6 +118,7 @@ def clear_properties(): log("********** Oz Weather Couldn't clear all the properties, sorry!!", inst) +# noinspection PyShadowingNames def forecast(geohash, radar_code): """ The main weather data retrieval function @@ -162,19 +163,17 @@ def forecast(geohash, radar_code): time_oldest = utc_str_to_local_str(utc_oldest, "%Y%m%d%H%M") time_newest = utc_str_to_local_str(utc_newest, "%Y%m%d%H%M") - oldest_dt = datetime.datetime.fromtimestamp(os.path.getctime(oldest_file)) - newest_dt = datetime.datetime.fromtimestamp(os.path.getctime(newest_file)) set_property(WEATHER_WINDOW, 'RadarOldest', time_oldest) set_property(WEATHER_WINDOW, 'RadarNewest', time_newest) # Get all the weather & forecast data from the BOM API - weather_data = False + weather_data = None if geohash: log(f'Using the BOM API. Getting weather data for {geohash}') weather_data = bom_forecast(geohash) - # At this point, we should have _something_ - if not, log the issue and we're done... + # At this point, we should have _something_ - if not, log the issue, and we're done... if not weather_data: log("Unable to get weather_data from BOM - internet connection issue or addon not configured?", level=xbmc.LOGINFO) return @@ -186,7 +185,7 @@ def forecast(geohash, radar_code): # Get the ABC 90-second weather video link if extended features is enabled if extended_features: log("Getting the ABC weather video link") - url = get_abc_weather_video_link(ADDON.getSetting("ABCQuality")) + url = get_abc_weather_video_link() if url: set_property(WEATHER_WINDOW, 'Video.1', url) @@ -197,6 +196,7 @@ def forecast(geohash, radar_code): set_property(WEATHER_WINDOW, 'Forecast.Updated', time.strftime("%d/%m/%Y %H:%M")) +# noinspection PyShadowingNames def get_weather(): """ Gets the latest observations, forecast and radar images for the currently chosen location @@ -210,6 +210,7 @@ def get_weather(): # This is/was an attempt to use conditions in skins to basically auto-adapt the MyWeather.xml and all OzWeather # components to the currently-in-use skin. However, no matter what I try I can't get the conditions to work # in the skin files. + # noinspection PyBroadException try: skin_in_use = xbmc.getSkinDir().split('.')[1] set_property(WEATHER_WINDOW, 'SkinInUse', skin_in_use) diff --git a/weather.ozweather/resources/lib/locations.py b/weather.ozweather/resources/lib/locations.py index c84b28a96..1fa471a19 100644 --- a/weather.ozweather/resources/lib/locations.py +++ b/weather.ozweather/resources/lib/locations.py @@ -1,3 +1,4 @@ +# noinspection PyPackages from .common import * @@ -17,7 +18,7 @@ def refresh_locations(): locations = 0 - # If either the main location or the fall back is set, then enable the location + # If either the main location or the fallback is set, then enable the location # This is to cope with the transition period where folks will have the fallbacks set from their legacy settings # But not the new BOM locations if location1 != '': diff --git a/weather.ozweather/resources/lib/ozweather.py b/weather.ozweather/resources/lib/ozweather.py index ac9181226..bdcdda9cc 100644 --- a/weather.ozweather/resources/lib/ozweather.py +++ b/weather.ozweather/resources/lib/ozweather.py @@ -1,9 +1,14 @@ # -*- coding: utf-8 -*- import socket +# noinspection PyPackages from .forecast import * +# noinspection PyPackages from .locations import * +# noinspection PyPackages from .bom.bom_location import * +# noinspection PyPackages +from .abc.abc_video import * def run(args): @@ -22,13 +27,18 @@ def run(args): if args[1].startswith('Location'): find_bom_location() + # RUN MODE - ADDON CALLED FORM Kodi SETTINGS + # the addon is being called from the settings section where the user enters their postcodes + elif args[1].startswith('ABC'): + scrape_and_play_abc_weather_video() + # RUN MODE - GET WEATHER OBSERVATIONS AND FORECAST # script is being called in general use, not from the settings page # sys.argv[1] has the current location number (e.g. '1'), so fetch the weather data else: get_weather() - # If location settings have changed, this kick starts an update + # If location settings have changed, this kick-starts an update refresh_locations() # and close out... diff --git a/weather.ozweather/resources/lib/store.py b/weather.ozweather/resources/lib/store.py index ca906ae7a..166d691c8 100644 --- a/weather.ozweather/resources/lib/store.py +++ b/weather.ozweather/resources/lib/store.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# noinspection SpellCheckingInspection class Store: """ Helper class to provide a centralised store for CONSTANTS and globals @@ -9,9 +10,10 @@ class Store: # CONSTANTS # ABC WEATHER VIDEO - scraping - ABC_URL = "https://www.abc.net.au/news/newschannel/weather-in-90-seconds/" - ABC_WEATHER_VIDEO_PATTERN = "//abcmedia.akamaized.net/news/news24/wins/(.+?)/WIN(.*?)_512k.mp4" - ABC_STUB = "https://abcmedia.akamaized.net/news/news24/wins/" + 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" # 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/settings.xml b/weather.ozweather/resources/settings.xml index b47b63030..d7d5aefdc 100644 --- a/weather.ozweather/resources/settings.xml +++ b/weather.ozweather/resources/settings.xml @@ -351,23 +351,6 @@ 0 false - - - 0 - 1000k - - - - - - - - - - false - - -