• Stars
    star
    338
  • Rank 124,931 (Top 3 %)
  • Language
    Python
  • License
    The Unlicense
  • Created over 16 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple to use interface to TheTVDB.com API in Python

tvdb_api

PyPI Build Status codecov

tvdb_api is an easy to use interface to thetvdb.com

It supports Python 2.7, and 3.5 onwards

tvnamer has moved to a separate repository: github.com/dbr/tvnamer - it 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 pip

pip install --upgrade tvdb_api

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

sudo pip install --upgrade tvdb_api

Basic usage

First initialise an instance of the Tvdb class with your API key:

import tvdb_api
t = tvdb_api.Tvdb() 

Note you must specify the apikey argument here, for example:

t = Tvdb(apikey="ENTER YOUR API KEY HERE") # doctest:+SKIP

See https://thetvdb.com/api-information to register a key.

Then to use the API:

episode = t['My Name Is Earl'][1][3] # get season 1, episode 3 of show
print episode['episodename'] # Print episode name

Registering an API key

You must have an API key from http://thetvdb.com in order to use this module.

Registering for a key is easy to do and can be done within a few minutes - see the following page for details:

https://thetvdb.com/api-information

Note: In tvdb_api v2 a default key was included for convenience. However over time this key became very heavily used and this causes problems for TheTVDB.com admins. This old shared key will be deprecated and removed at some point soon.

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 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'ABC'

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', 'ratingcount', 'status', 'added', 'poster', 'tms_wanted_old', 'imdb_id', 'genre', 'banner', 'seriesid', 'language', 'zap2it_id', 'addedby', 'firstaired', 'runtime', 'overview']

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

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

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|Judy Reyes|John C. McGinley|Neil Flynn|Ken Jenkins|Christa Miller|Aloma Wright|Robert Maschio|Sam Lloyd|Travis Schuldt|Johnny Kastl|Heather Graham|Michael Mosley|Kerry Bish\xe9|Dave Franco|Eliza Coupe|'

More Repositories

1

tvnamer

Automatic TV episode file renamer, uses data from thetvdb.com via tvdb_api
Python
909
star
2

tabtabtab-nuke

A replacement for Nuke's "tab" node creator
Python
36
star
3

themoviedb

Python wrapper to themoviedb.org API [Not actively maintained]
Python
33
star
4

shortcuteditor-nuke

Keyboard shortcut editor for The Foundry's Nuke compositing software
Python
29
star
5

stravathings

A random bunch of tools using old V1 API for www.strava.com (cycle-mapping thing)
Python
18
star
6

colourstuff

Various colour-related stuff (tools for transforms, profiles, LUT's etc)
Python
15
star
7

webtools

A web interface to youtube-dl, and maybe more [no longer developed - replaced by dbr/vidl-rs]
JavaScript
15
star
8

nuke_misc_plugins

Various Nuke plugins
C++
13
star
9

checktveps

Misc tools to check the naming of recorded/downloaded TV Episodes
Python
13
star
10

IMDb-Python-API

A JSON API for IMDb.com written in Python [Not actively maintained]
Python
12
star
11

thingsweb

A web interface to Things, http://culturedcode.com/ [Not actively maintained]
Ruby
12
star
12

nukeBullet

Nuke interface to the Bullet physics library
C++
11
star
13

qltorrent

Not actively maintained, see this fork instead: https://github.com/sillage/qltorrent
Objective-C
9
star
14

tvdb-rs

TheTVDB.com interface for Rust
Rust
7
star
15

so_scripts

Random StackoverFlow.com scripts
Python
7
star
16

stereoergo-rv

More ergonomic stereo-review shortcuts for Tweak Software's RV
Python
7
star
17

appletrailers

Python interface to Apple's HD trailers
Python
6
star
18

pyfeedproc

Simple framework for modifying RSS/Atom feeds, in Python [Not actively maintained]
Python
6
star
19

tvnamergui_osx

A GUI to tvnamer for OS X [Not actively maintained]
Objective-C
6
star
20

pyopenexr

A parser for OpenEXR image files, implemented purely in Python [Not actively maintained]
Python
6
star
21

vedirect-rs

Victron Energy VE.Direct parser library
Rust
6
star
22

pyerweb

An absurdly small web-framework in Python [Not actively maintained]
Python
6
star
23

imgui-docking-rs

A prototype of docking support in imgui-rs, now merged into main imgui-rs/imgui-re repo
Rust
6
star
24

dotemacs

Emacs configuration, structured as an org-mode file
Emacs Lisp
5
star
25

couchdb-python-utils

Python utilities to make CouchDB more pleasant. [Not actively maintained]
Python
5
star
26

vidl-rs

Video Downloader
Rust
4
star
27

QLfit

Quicklook plugin for .FIT files from Garmin devices and such
C++
4
star
28

zp_grabber

Grabs the .flv links for Zero Punctuation episodes
Python
3
star
29

imgui-filedialog-rs

Rust language bindings to ImGuiFileDialog [not currently maintained]
Rust
3
star
30

rstvnamer

Command line TV episode file renamer, loosely based on dbr/tvnamer
Rust
3
star
31

TrailerGrabber

An OS X application to download trailers from apple.com/trailers/ [Not actively maintained]
Objective-C
3
star
32

lisp.tmbundle

Lisp bundle for TextMate, with some snippets, help for current word, and run script [Not actively maintained]
2
star
33

filmdb

Rails film database - very basic database to list films I have watched, and to learn Rails [Not actively maintained]
Ruby
2
star
34

easyrand-rs

Simpler to use random number library for the Rust language
Rust
2
star
35

garminsyncier

A simple-but-robust Garmin Connect to Strava tool
Python
2
star
36

remoterepl

A remote REPL, to easily send stuff from emacs to a random Python process
Python
1
star
37

testosterone

The manly python unittest interface [renamed and moved to https://github.com/whit537/assertEquals ]
Python
1
star
38

pyautotest

Quick notifications of unitest failures, like ZenTest for Python [Not actively maintained]
Python
1
star
39

juke-rs

Jukebox music queue system based around Spotify
Rust
1
star