2016-01-28, 23:29
script.module.thesportsdb
A python module packaged as a Kodi script module to wrap all thesportsdb API calls and for you to use on your own addon. An API key is required, please visit thesportsdb for more information. It has been re-written from scratch and provides an easy and intuitive way of accessing the data presented in the website.
For issues or suggestions regarding the website please post on the thesportsdb.com forum thread here on the forum.. Donations for the website are also appreciated contact Zag if interested.
Usage
Addon.xml
The module most be imported in the addon.xml of your addon and pointing to the correct version of the module
Pythonic usage
The module follows the API structure described Here. Every group method (Search,Lookups,Schedules,Livescores) is a Python class and all the endpoints (eg: lookupleague) is part of a class method. The module maps the json data to objects as much as possible, so each call returns one or more Team objects, League objects, Player objects, Livescores objects, Table objects, etc. I have made an extra effort to document the module properly, all the methods and objects available can be consulted here .
Download, Source Code & Licence
The module will be submitted to the official repository soon.
Current Version: 1.0.0
Source code: https://github.com/enen92/script.module.thesportsdb
Licence: GPL V2
A simple example...
A full Kodi addon that uses the script.module.thesportsdb:
Below is the code for an addon that uses the module. Its goal is to obtain all the teams in the British Premier League, list the teams as directory items (with artwork and information) and link to the youtube channel of each team. All possible with only a few lines of python code.
addon.xml
addon.py
A few screenshots of the resulting plugin...
I plan to develop a few scripts using the module now that it is really simple to maintain and to use.
Good luck making your own creations
Use the thread to report errors or bugs, suggestions or questions regarding its usage.
Regards
A python module packaged as a Kodi script module to wrap all thesportsdb API calls and for you to use on your own addon. An API key is required, please visit thesportsdb for more information. It has been re-written from scratch and provides an easy and intuitive way of accessing the data presented in the website.
For issues or suggestions regarding the website please post on the thesportsdb.com forum thread here on the forum.. Donations for the website are also appreciated contact Zag if interested.
Usage
Addon.xml
The module most be imported in the addon.xml of your addon and pointing to the correct version of the module
PHP Code:
<import addon="script.module.thesportsdb" version="1.0.0"/>
Pythonic usage
The module follows the API structure described Here. Every group method (Search,Lookups,Schedules,Livescores) is a Python class and all the endpoints (eg: lookupleague) is part of a class method. The module maps the json data to objects as much as possible, so each call returns one or more Team objects, League objects, Player objects, Livescores objects, Table objects, etc. I have made an extra effort to document the module properly, all the methods and objects available can be consulted here .
Download, Source Code & Licence
The module will be submitted to the official repository soon.
Current Version: 1.0.0
Source code: https://github.com/enen92/script.module.thesportsdb
Licence: GPL V2
A simple example...
PHP Code:
import thesportsdb
api = thesportsdb.Api(key="1")
players = api.Search().Players(team="Arsenal")
for player in players:
print(player.strPlayer)
A full Kodi addon that uses the script.module.thesportsdb:
Below is the code for an addon that uses the module. Its goal is to obtain all the teams in the British Premier League, list the teams as directory items (with artwork and information) and link to the youtube channel of each team. All possible with only a few lines of python code.
addon.xml
PHP Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.tsdbdummy" name="TSDB Dummy plugin" version="1.0.0" provider-name="enen92">
<requires>
<import addon="xbmc.python" version="2.1.0"/>
<import addon="script.module.thesportsdb" version="1.0.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">A dummy plugin that uses script.module.thesportsdb</summary>
<description lang="en">A dummy video plugin to exemplify the use of script.module.thesportsdb</description>
<disclaimer lang="en"></disclaimer>
<forum>Your forum post</forum>
<source>Yout source code</source>
<website>your website</website>
<platform>all</platform>
</extension>
</addon>
addon.py
PHP Code:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import xbmc
import xbmcgui
import xbmcplugin
import sys
import thesportsdb
api = thesportsdb.Api(key="1")
teams = api.Search().Teams(league="English Premier League")
if teams:
items = []
for team in teams:
item = xbmcgui.ListItem(team.strTeam)
item.setArt({"thumb" : team.strTeamBadge, "banner" : team.strTeamBanner, "fanart" : team.RandomFanart})
item.setInfo('video',{"year": team.intFormedYear, "genre": team.strSport, "plot": team.strDescription })
if "/user/" in team.strYoutube:
url = "plugin://plugin.video.youtube/user/" + team.strYoutube.split("/")[-1] + "/"
elif "/channel/" in team.strYoutube:
url = "plugin://plugin.video.youtube/channel/" + team.strYoutube.split("/")[-1] + "/"
else:
url = ""
items.append((url,item,True))
xbmcplugin.addDirectoryItems(int(sys.argv[1]),items,totalItems=len(teams))
xbmcplugin.setContent(int(sys.argv[1]), 'movies')
xbmcplugin.endOfDirectory(int(sys.argv[1]))
A few screenshots of the resulting plugin...
I plan to develop a few scripts using the module now that it is really simple to maintain and to use.
Good luck making your own creations
Use the thread to report errors or bugs, suggestions or questions regarding its usage.
Regards