From 04a998d7dd85ed1646e55144cf9d9eb1932220f3 Mon Sep 17 00:00:00 2001 From: Tom Bell Date: Fri, 19 Apr 2024 15:32:55 +1200 Subject: [PATCH] store stream names and ids in a dict nhltv can give multiple options for which stream to watch for any given game, and the names given to the streams can vary. This commit allows any number of streams with any stream name to be presented to the user. Resolves: #53 --- addon.py | 23 ++++------------------- resources/lib/game.py | 21 +++------------------ resources/lib/globals.py | 2 +- resources/lib/nhl_tv.py | 26 +++++++------------------- 4 files changed, 15 insertions(+), 57 deletions(-) diff --git a/addon.py b/addon.py index a5f5eb2..ad649b4 100644 --- a/addon.py +++ b/addon.py @@ -5,12 +5,7 @@ name = None mode = None game_day = None -stream1_id = None -stream2_id = None -stream3_id = None -stream1_name = None -stream2_name = None -stream3_name = None +stream_ids = None highlight_id = None teams_stream = None stream_date = None @@ -23,18 +18,8 @@ mode = int(params["mode"]) if "game_day" in params: game_day = urllib.unquote_plus(params["game_day"]) -if "stream1_id" in params: - stream1_id = urllib.unquote_plus(params["stream1_id"]) -if "stream2_id" in params: - stream2_id = urllib.unquote_plus(params["stream2_id"]) -if "stream3_id" in params: - stream3_id = urllib.unquote_plus(params["stream3_id"]) -if "stream1_name" in params: - stream1_name = urllib.unquote_plus(params["stream1_name"]) -if "stream2_name" in params: - stream2_name = urllib.unquote_plus(params["stream2_name"]) -if "stream3_name" in params: - stream3_name = urllib.unquote_plus(params["stream3_name"]) +if "stream_ids" in params: + stream_ids = ast.literal_eval(params["stream_ids"]) if "highlight_id" in params: highlight_id = urllib.unquote_plus(params["highlight_id"]) @@ -46,7 +31,7 @@ todays_games(game_day) elif mode == 104: - stream_select(stream1_id, stream2_id, stream3_id, stream1_name, stream2_name, stream3_name, highlight_id) + stream_select(stream_ids, highlight_id) elif mode == 105: # Yesterday"s Games diff --git a/resources/lib/game.py b/resources/lib/game.py index f7217dc..9bf6dd5 100644 --- a/resources/lib/game.py +++ b/resources/lib/game.py @@ -8,12 +8,7 @@ def __init__(self, game_json): self.home_team = game_json["homeCompetitor"] self.away_team = game_json["awayCompetitor"] self.content = game_json["content"] - self.stream1_id = "" - self.stream2_id = "" - self.stream3_id = "" - self.stream1_name = "" - self.stream2_name = "" - self.stream3_name = "" + self.stream_ids = {} self.highlight_id = "" def create_listitem(self): @@ -43,21 +38,11 @@ def create_listitem(self): # add_stream(name, '', title, self.home_id, self.away_id, icon, fanart, info, video_info, audio_info) - add_stream(name, title, icon, fanart, info, stream1_id=self.stream1_id, stream2_id=self.stream2_id, stream3_id=self.stream3_id, \ - stream1_name=self.stream1_name, stream2_name=self.stream2_name, stream3_name=self.stream3_name, highlight_id=self.highlight_id) + add_stream(name, title, icon, fanart, info, stream_ids=self.stream_ids, highlight_id=self.highlight_id) def set_ids(self): for item in self.content: if str(item["contentType"]["name"]).upper() == "FULL GAME" and len(item["clientContentMetadata"]): - broadcast = str(item["clientContentMetadata"][0]["name"]).upper() - if broadcast == "HOME" or broadcast == "NATIONAL": - self.stream1_id = str(item["id"]) - self.stream1_name = broadcast - elif broadcast == "AWAY": - self.stream2_id = str(item["id"]) - self.stream2_name = broadcast - else: - self.stream3_id = str(item["id"]) - self.stream3_name = broadcast + self.stream_ids[str(item["clientContentMetadata"][0]["name"]).upper()] = str(item["id"]) elif str(item["contentType"]["name"]).upper() == "HIGHLIGHTS": self.highlight_id = str(item["id"]) diff --git a/resources/lib/globals.py b/resources/lib/globals.py index 0a7b072..6c8192a 100644 --- a/resources/lib/globals.py +++ b/resources/lib/globals.py @@ -1,5 +1,5 @@ import sys -import re, os, time +import re, os, time, ast import calendar, pytz import requests, urllib from datetime import datetime, timedelta diff --git a/resources/lib/nhl_tv.py b/resources/lib/nhl_tv.py index afde2d4..b1da397 100644 --- a/resources/lib/nhl_tv.py +++ b/resources/lib/nhl_tv.py @@ -47,37 +47,25 @@ def todays_games(game_day): add_dir('[B]%s >>[/B]' % LOCAL_STRING(30011), '/live', 101, NEXT_ICON, FANART, next_day.strftime("%Y-%m-%d")) -def stream_select(stream1_id, stream2_id, stream3_id, stream1_name, stream2_name, stream3_name, highlight_id): - xbmc.log(f"stream1_id: {stream1_id}, stream1_name: {stream1_name}") - xbmc.log(f"stream2_id: {stream2_id}, stream2_name: {stream2_name}") - xbmc.log(f"stream3_id: {stream3_id}, stream3_name: {stream3_name}") +def stream_select(stream_ids, highlight_id): + for stream_name in stream_ids.keys(): + xbmc.log(f"stream id for {stream_name}: {stream_ids[stream_name]}") xbmc.log(f"highlight_id: {highlight_id}") - options = [] - if stream1_id != "": - options.append(stream1_name) - if stream2_id != "": - options.append(stream2_name) - if stream3_id != "": - options.append(stream3_name) + options = list(stream_ids.keys()) if highlight_id != "": options.append("Highlights") dialog = xbmcgui.Dialog() n = dialog.select('Choose Stream', options) if n > -1: - if options[n] == stream1_name: - id = stream1_id - elif options[n] == stream2_name: - id = stream2_id - elif options[n] == stream3_name: - id = stream3_id - elif options[n] == "Highlights": + if options[n] == "Highlights": id = highlight_id + else: + id = stream_ids[options[n]] else: sys.exit() - if options[n] != "Highlights": update_user_token()