Release script.module.thesportsdb - A python module for thesportsdb
#1
script.module.thesportsdb

Image

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...
Image
Image
Image

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 Smile
Use the thread to report errors or bugs, suggestions or questions regarding its usage.

Regards
Reply
#2
Really nice work Big Grin
Reply
#3
Can't wait to see what people come up with... Awesome work!!
Reply
#4
First addon that uses this module has been released: http://forum.kodi.tv/showthread.php?tid=258252

A few more being worked on Smile
Reply
#5
Awesome thanks.

Few random ideas...

Sports Events - Browse each sport, league, season and check for file local file according to the strFilename property on TSDB example: http://www.thesportsdb.com/event/447376
Team stats - Show a team from TSDB last 5 matches. Could be nice for betting research Smile
Next match - Popup when loading Kodi for your teams next match date and time
Reply
#6
(2016-01-30, 15:02)zag Wrote: Awesome thanks.

Few random ideas...

Sports Events - Browse each sport, league, season and check for file local file according to the strFilename property on TSDB example: http://www.thesportsdb.com/event/447376
Team stats - Show a team from TSDB last 5 matches. Could be nice for betting research Smile
Next match - Popup when loading Kodi for your teams next match date and time

My next one is also for livescores but a bit different. Something you can map to a keyboard/remote key to bring a livescores dialog on top of the game you're watching. Match events and lineups available like was planned for sportscenter. But those are nice ideas and pretty easy to implement Smile
Reply
#7
Nice work!
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#8
Another idea..

Something like this page in Kodi. Should be pretty easy with the nextmatch api call.

http://www.thesportsdb.com/nextevents
Reply
#9
New addon up Big Grin -> http://forum.kodi.tv/showthread.php?tid=259894
Reply
#10
Just FYI the module should now be in the official repository. Lowest version supported is Isengard Smile
The screensaver is also on the repository now.
Reply
#11
Nice one, congrats!
Reply
#12
Thanks for this work.

I'm confused though. Why don't we, AFAIK, have a Kodi "Sport" content type, using TSDB API for metadata, yet?
Reply

Logout Mark Read Team Forum Stats Members Help
script.module.thesportsdb - A python module for thesportsdb0