Skip to content

Commit

Permalink
[plugin.video.spursplay] v0.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
LS80 committed Jan 12, 2025
1 parent bc8e8ec commit f4c0a67
Show file tree
Hide file tree
Showing 8 changed files with 478 additions and 0 deletions.
21 changes: 21 additions & 0 deletions plugin.video.spursplay/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Lee Smith

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
179 changes: 179 additions & 0 deletions plugin.video.spursplay/addon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import base64
import json
import sys
from datetime import datetime
import time
from urllib.parse import parse_qsl, urlencode

import xbmc
import xbmcaddon
import xbmcgui
import xbmcplugin

import resources.lib.spursplay as spursplay


plugin_handle = int(sys.argv[1])

api = spursplay.Api()


def router(paramstring):
params = dict(parse_qsl(paramstring[1:]))
if params:
if params["action"] == "play":
play_video(params["id"], "live" in params)
elif params["action"] == "listing":
list_videos(params["id"], params.get("lastSeen"))
elif params["action"] == "playlists":
list_playlists(params["id"], params.get("lastSeen"))
elif params["action"] == "playlist-listing":
list_playlist_videos(params["id"], params.get("page"))
elif params["action"] == "section":
list_section(params["name"])
else:
list_categories()


def build_url(**params):
return f"{sys.argv[0]}?{urlencode(params)}"


def token_expiry(jwt):
payload_base64 = (jwt.split(".")[1] + "==").encode("ascii")
return datetime.fromtimestamp(json.loads(base64.b64decode(payload_base64))["exp"])


def login():
settings = xbmcaddon.Addon().getSettings()

email, password = settings.getString(id="email"), settings.getString(id="password")
token = settings.getString(id="token")

if email and password and (not token or datetime.now() > token_expiry(token)):
xbmc.log("Logging in", level=xbmc.LOGDEBUG)
try:
token = api.login(email, password)
except spursplay.LoginError as exc:
dialog = xbmcgui.Dialog()
dialog.notification("SPURSPLAY", str(exc), xbmcgui.NOTIFICATION_ERROR)
else:
settings.setString("token", token)


def list_categories():
events = api.get_live_events()
listing = list(video_items(events, live=True))

buckets = api.buckets(section="First Team", num_pages=2)
for name, category_id in buckets:
list_item = xbmcgui.ListItem(label=name)
url = build_url(action="listing", id=category_id)
listing.append((url, list_item, True))

playlists = api.playlists()
for name, category_id in playlists:
list_item = xbmcgui.ListItem(label=name)
url = build_url(action="playlists", id=category_id)
listing.append((url, list_item, True))

for section in ["Originals", "Academy", "Players"]:
list_item = xbmcgui.ListItem(label=section)
url = build_url(action="section", name=section)
listing.append((url, list_item, True))

xbmcplugin.addDirectoryItems(plugin_handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin_handle)


def list_section(section):
listing = []
buckets = api.buckets(section)
for name, category_id in buckets:
xbmc.log(name, level=xbmc.LOGDEBUG)
list_item = xbmcgui.ListItem(label=name)
url = build_url(action="listing", id=category_id)
listing.append((url, list_item, True))

xbmcplugin.addDirectoryItems(plugin_handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin_handle)


def list_playlists(category_id, last_seen=None):
playlists, new_last_seen, more_available = api.get_bucket_playlists(category_id, last_seen)
listing = []
for playlist in playlists:
list_item = xbmcgui.ListItem(label=playlist["title"])
thumb = playlist["thumbnail"]
list_item.setArt({"icon": thumb, "thumb": thumb})
url = build_url(action="playlist-listing", id=playlist["id"])
listing.append((url, list_item, True))

if more_available:
list_item = xbmcgui.ListItem(label="Show More")
url = build_url(action="playlists", id=category_id, lastSeen=new_last_seen)
listing.append((url, list_item, True))

xbmcplugin.addDirectoryItems(plugin_handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin_handle, updateListing=last_seen is not None)


def video_items(videos, live=False):
for video in videos:
list_item = xbmcgui.ListItem(label=video["title"])
thumb = video["thumbnail"]
if live:
timestamp = round(time.time() / 60) * 60
thumb += f"?ts={timestamp}" # Add a timestamp to bust the live thumbnail cache every minute
list_item.setProperty("IsPlayable", "true")
list_item.setArt({"icon": thumb, "thumb": thumb, "poster": video["poster"], "fanart": video["cover"]})
list_item.setInfo(type="video", infoLabels={"plot": video["description"]})
video_info = list_item.getVideoInfoTag()
video_info.setTitle(video["title"])
if video["duration"] is not None:
video_info.setDuration(video["duration"])
params = {"action": "play", "id": video["id"]}
if live:
params["live"] = "true"
url = build_url(**params)
yield (url, list_item, False)


def list_playlist_videos(playlist_id, page=None):
videos, more_available = api.get_playlist_videos(playlist_id, page)

listing = list(video_items(videos))

if more_available:
list_item = xbmcgui.ListItem(label="Show More")
url = build_url(action="playlist-listing", id=playlist_id, page=int(page or 1) + 1)
listing.append((url, list_item, True))

xbmcplugin.addDirectoryItems(plugin_handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin_handle, updateListing=page is not None)


def list_videos(category_id="J34p", last_seen=None):
videos, new_last_seen, more_available = api.get_bucket_videos(category_id, last_seen)

listing = list(video_items(videos))

if more_available:
list_item = xbmcgui.ListItem(label="Show More")
url = build_url(action="listing", id=category_id, lastSeen=new_last_seen)
listing.append((url, list_item, True))

xbmcplugin.addDirectoryItems(plugin_handle, listing, len(listing))
xbmcplugin.endOfDirectory(plugin_handle, updateListing=last_seen is not None)


def play_video(video_id, live):
url = api.get_video_url(video_id, live)
play_item = xbmcgui.ListItem(path=url)

xbmcplugin.setResolvedUrl(plugin_handle, True, listitem=play_item)


if __name__ == "__main__":
login()
router(sys.argv[2])
26 changes: 26 additions & 0 deletions plugin.video.spursplay/addon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.spursplay" name="SPURSPLAY" version="0.2.6" provider-name="LS80">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests" version="2.31.0"/>
</requires>
<extension point="xbmc.python.pluginsource" library="addon.py">
<provides>video</provides>
</extension>
<extension point="xbmc.addon.metadata">
<platform>all</platform>
<summary lang="en_GB">Video content from https://play.tottenhamhotspur.com.</summary>
<description lang="en_GB">SPURSPLAY is the official streaming platform of Tottenham Hotspur Football Club, offering fans exclusive access to a wide range of content, including live and on-demand videos.</description>
<disclaimer lang="en_GB">This is an UNOFFICIAL plugin NOT endorsed by Tottenham Hotspur. Some content requires a SPURSPLAY subscription.</disclaimer>
<language>en</language>
<platform>all</platform>
<license>MIT</license>
<forum>https://forum.kodi.tv/showthread.php?tid=380119</forum>
<website>https://play.tottenhamhotspur.com</website>
<source>https://github.com/LS80/plugin.video.spursplay</source>
<assets>
<icon>resources/icon.png</icon>
<fanart>resources/fanart.jpg</fanart>
</assets>
</extension>
</addon>
Binary file added plugin.video.spursplay/resources/fanart.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin.video.spursplay/resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Kodi Media Center language file
# Addon Name: SPURSPLAY
# Addon id: plugin.video.spursplay
# Addon Provider: Leopold
msgid ""
msgstr ""
"Project-Id-Version: Kodi Addons\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Kodi Translation Team\n"
"Language-Team: English (https://kodi.weblate.cloud/languages/en_gb/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: en\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgctxt "#30001"
msgid "Credentials"
msgstr ""

msgctxt "#30002"
msgid "Email or CRN"
msgstr ""

msgctxt "#30003"
msgid "Password"
msgstr ""
Loading

0 comments on commit f4c0a67

Please sign in to comment.