Skip to content

Commit

Permalink
Allow choosing 'channel' on live event
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDevFreak committed Mar 26, 2021
1 parent 15455c2 commit a02b931
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
30 changes: 30 additions & 0 deletions resources/lib/F1TVParser/F1TV_Minimal_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,36 @@ def getLiveEvent(self):
# f"{sub_item['id']} - LIVE EVENT - {sub_item['metadata']['title']}",
# )

def check_additional_streams(self, content_id):
"""Method to check if contendId has additional streams (IE: Onboards, PLC, Data)"""
url = f"{self.f1tvapi}ALL/CONTENT/VIDEO/{content_id}/F1_TV_Pro_Monthly/14"
content_data = self.account_manager.getSession().get(url).json()

additional_streams = []
additional_streams.append({
"content_id": content_id,
"channel_id": None,
"title": "Main Feed"
})

if "additionalStreams" in content_data["resultObj"]["containers"][0]["metadata"]:
# There are some additional streams - print them out and give a choice
for additional_stream in content_data["resultObj"]["containers"][0]["metadata"]["additionalStreams"]:
# Get channel id
channel_id = (
additional_stream["playbackUrl"]
.split("CONTENT/PLAY?")[1]
.split("&")[0]
.split("=")[1]
)
#Add stream data to array
additional_streams.append({
"content_id": content_id,
"channel_id": channel_id,
"title": additional_stream['title']
})
return additional_streams

def getM3U8(self, content_id, channel_id=None):
url = "https://f1tv.formula1.com/1.0/R/ENG/BIG_SCREEN_HLS/ALL/CONTENT/PLAY"
params = {
Expand Down
39 changes: 30 additions & 9 deletions resources/lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ def get_mainpage():
#There is a live event, add it to the menu
if live_event:
list_item = xbmcgui.ListItem(label=f"Live Now - {live_event['metadata']['title']}")
url = get_url(action="playVideo", content_id=live_event['id'])
list_item.setProperty('IsPlayable', 'true')
list_item.setInfo("video", {"title": f"Live Now - {live_event['metadata']['title']}"})
#Build image url
image_url = f"https://ott.formula1.com/image-resizer/image/{live_event['metadata']['pictureUrl']}?w=1280&h=720"
list_item.setArt({'thumb': image_url,
'icon': image_url,
'fanart': image_url})
xbmcplugin.addDirectoryItem(_handle, url, list_item, False)
# url = get_url(action="playVideo", content_id=live_event['id'])
# list_item.setProperty('IsPlayable', 'true')
# list_item.setInfo("video", {"title": f"Live Now - {live_event['metadata']['title']}"})
# #Build image url
# image_url = f"https://ott.formula1.com/image-resizer/image/{live_event['metadata']['pictureUrl']}?w=1280&h=720"
# list_item.setArt({'thumb': image_url,
# 'icon': image_url,
# 'fanart': image_url})
url = get_url(action="additional_streams", content_id=live_event['id'])
xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

#Add Archive To Menu
list_item = xbmcgui.ListItem(label="Archive")
Expand All @@ -83,6 +84,24 @@ def get_mainpage():
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)

def additional_streams_folder(content_id):
additional_streams = _api_manager.check_additional_streams(content_id=content_id)
for additional_stream in additional_streams:
list_item = xbmcgui.ListItem(label=f"{additional_stream['title']}")
url = get_url(action="playVideo", content_id=additional_stream['content_id'], channel_id=additional_stream['channel_id'])
list_item.setProperty('IsPlayable', 'true')
list_item.setInfo("video", {"title": additional_stream['title']})
# #Build image url
# image_url = f"https://ott.formula1.com/image-resizer/image/{live_event['metadata']['pictureUrl']}?w=1280&h=720"
# list_item.setArt({'thumb': image_url,
# 'icon': image_url,
# 'fanart': image_url})
xbmcplugin.addDirectoryItem(_handle, url, list_item, False)
# Add a sort method for the virtual folder items (alphabetically, ignore articles)
xbmcplugin.addSortMethod(_handle, xbmcplugin.SORT_METHOD_UNSORTED)
# Finish creating a virtual folder.
xbmcplugin.endOfDirectory(_handle)

def archive():
archive_page_data = _api_manager.getPage(493)
for container in archive_page_data["resultObj"]["containers"]:
Expand Down Expand Up @@ -598,6 +617,8 @@ def router(paramstring):
playVideo(params['content_id'], params['channel_id'])
except KeyError:
playVideo(params['content_id'])
elif params['action'] == "additional_streams":
additional_streams_folder(params['content_id'])
elif params['action'] == 'settings':
_ADDON.openSettings()
else:
Expand Down

0 comments on commit a02b931

Please sign in to comment.