github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

dbr / tvdb_api

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 41
    • 5
  • Source
  • Commits
  • Network (5)
  • Issues (3)
  • Downloads (14)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (14)
    • 1.4
    • 1.3
    • 1.2.2
    • 1.2.1
    • 1.2
    • 1.1
    • 1.0
    • 0.7
    • 0.6
    • 0.5.1
    • 0.5
    • 0.4
    • 0.3
    • 0.2
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Simple to use TVDB (thetvdb.com) API in Python. The automatic TV episode namer "tvnamer" is now in a separate repository http://github.com/dbr/tvnamer — Read more

  cancel

http://dbr.lighthouseapp.com/projects/13342-tvdb_api/tickets

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Reworking logging setup, better use of logging module, no passing around 
self.log, better integration with other projects using logging module. 
dbr (author)
Fri Feb 05 10:31:15 -0800 2010
commit  6dd6f7b23a69872cc7b84667f83fd6970708fbfe
tree    c5a9a3364c70eb14f43dc46a404a4fabf67a6a15
parent  de17e67580e01a0a1639a02af748656c999298ee
tvdb_api /
name age
history
message
file .gitignore Thu May 15 19:12:14 -0700 2008 Added git-ignore [dbr]
file Rakefile Fri Jan 01 10:32:13 -0800 2010 Remove tvnamer, as it's part of a seperate repo... [dbr]
file cache.py Fri Jan 01 10:18:28 -0800 2010 Bump to 1.4, contains fix to show language ID i... [dbr]
file readme.md Fri Jan 01 10:32:13 -0800 2010 Remove tvnamer, as it's part of a seperate repo... [dbr]
file setup.py Fri Jan 01 10:32:13 -0800 2010 Remove tvnamer, as it's part of a seperate repo... [dbr]
directory tests/ Sun Jan 03 13:48:03 -0800 2010 Remove functional tvnamer test [dbr]
file tvdb_api.py Fri Feb 05 10:31:15 -0800 2010 Reworking logging setup, better use of logging ... [dbr]
file tvdb_exceptions.py Fri Jan 01 10:18:28 -0800 2010 Bump to 1.4, contains fix to show language ID i... [dbr]
file tvdb_ui.py Fri Feb 05 10:31:15 -0800 2010 Reworking logging setup, better use of logging ... [dbr]
readme.md

tvdb_api and tvnamer

tvdb_api is an easy to use interface to thetvdb.com

tvnamer has moved to a separate repository: github.com/dbr/tvnamer

tvnamer is a utility which uses tvdb_api to rename files from some.show.s01e03.blah.abc.avi to Some Show - [01x03] - The Episode Name.avi (which works by getting the episode name from tvdb_api)

To install

You can easily install tvdb_api via easy_install

easy_install tvdb_api

You may need to use sudo, depending on your setup:

sudo easy_install tvdb_api

The tvnamer command-line tool can also be installed via easy_install, this installs tvdb_api as a dependancy:

easy_install tvnamer

Basic usage

import tvdb_api
t = tvdb_api.Tvdb()
episode = t['My Name Is Earl'][1][3] # get season 1, episode 3 of show
print episode['episodename'] # Print episode name

Advanced usage

Most of the documentation is in docstrings. The examples are tested (using doctest) so will always be up to date and working.

The docstring for Tvdb.__init__ lists all initialisation arguments, including support for non-English searches, custom "Select Series" interfaces and enabling the retrieval of banners and extended actor information. You can also override the default API key using apikey, recommended if you're using tvdb_api in a larger script or application

Exceptions

There are several exceptions you may catch, these can be imported from tvdb_api:

  • tvdb_error - this is raised when there is an error communicating with www.thetvdb.com (a network error most commonly)
  • tvdb_userabort - raised when a user aborts the Select Series dialog (by ctrl+c, or entering q)
  • tvdb_shownotfound - raised when t['show name'] cannot find anything
  • tvdb_seasonnotfound - raised when the requested series (t['show name][99]) does not exist
  • tvdb_episodenotfound - raised when the requested episode (t['show name][1][99]) does not exist.
  • tvdb_attributenotfound - raised when the requested attribute is not found (t['show name']['an attribute'], t['show name'][1]['an attribute'], or t['show name'][1][1]['an attribute'])

Series data

All data exposed by thetvdb.com is accessible via the Show class. A Show is retrieved by doing..

>>> import tvdb_api
>>> t = tvdb_api.Tvdb()
>>> show = t['scrubs']
>>> type(show)
<class 'tvdb_api.Show'>

For example, to find out what network Scrubs is aired:

>>> t['scrubs']['network']
u'NBC'

The data is stored in an attribute named data, within the Show instance:

>>> t['scrubs'].data.keys()
['networkid', 'rating', 'airs_dayofweek', 'contentrating', 'seriesname', 'id', 'airs_time', 'network', 'fanart', 'lastupdated', 'actors', 'overview', 'status', 'added', 'poster', 'imdb_id', 'genre', 'banner', 'seriesid', 'language', 'zap2it_id', 'addedby', 'firstaired', 'runtime']

Although each element is also accessible via t['scrubs'] for ease-of-use:

>>> t['scrubs']['rating']
u'9.1'

This is the recommended way of retrieving "one-off" data (for example, if you are only interested in "seriesname"). If you wish to iterate over all data, or check if a particular show has a specific piece of data, use the data attribute,

>>> 'rating' in t['scrubs'].data
True

Banners and actors

Since banners and actors are separate XML files, retrieving them by default is undesirable. If you wish to retrieve banners (and other fanart), use the banners Tvdb initialisation argument:

>>> from tvdb_api import Tvdb
>>> t = Tvdb(banners = True)

Then access the data using a Show's _banner key:

>>> t['scrubs']['_banners'].keys()
['fanart', 'poster', 'series', 'season']

The banner data structure will be improved in future versions.

Extended actor data is accessible similarly:

>>> t = Tvdb(actors = True)
>>> actors = t['scrubs']['_actors']
>>> actors[0]
<Actor "Zach Braff">
>>> actors[0].keys()
['sortorder', 'image', 'role', 'id', 'name']
>>> actors[0]['role']
u'Dr. John Michael "J.D." Dorian'

Remember a simple list of actors is accessible via the default Show data:

>>> t['scrubs']['actors']
u'|Zach Braff|Donald Faison|Sarah Chalke|Christa Miller Lawrence|Aloma Wright|Robert Maschio|Sam Lloyd|Neil Flynn|Ken Jenkins|Judy Reyes|John C. McGinley|Eliza Coupe|Dave Franco|'
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server