Skip to main content

python client for the XML API

Project description


python-tvrage is a python based object oriented client interface for’s XML based api feeds.


Install from sources:

$ python install

The easiest way to get started with python-tvrage is to use easy_install or pip:

$ easy_install -U python-tvrage

For pip you have to replace ‘easy_install’ with ‘pip install’. Also your platform may require the use of sudo


The tvrage package consists of three modules

  • the tvrage.feeds module provides a wrapper function for each of tvrage’s XML-feeds

  • the tvrage.api module provides an clean and object oriented interface on top of those services

  • the tvrage.quickinfo module is a simple pythonic wrapper for tvrage’s quickinfo api. Values are returned as python dictionaries rather than dedicated objects for tv shows and episodes

Fetching XML data

The tvrage.feeds module provides very basic and low level access to the data feeds. For more complex use cases it is recomended to use the object oriented module tvrage.api. Note: All functions in the tvrage.feeds module return XML data as ElementTree objects.

searching for TV shows using the general search feed (returns fuzzy search results):

$ python
>>> from tvrage import feeds
>>> from xml.etree.ElementTree import tostring
>>> doctor_who ='doctorwho2005')
>>> for node in doctor_who:
...     print(tostring(node))
<name>Doctor Who (2005)</name>
<status>Returning Series</status>

<name>Doctor Who</name>

using full_search includes all availabe meta data about the shows into the search results:

>>> doctor_who = feeds.full_search('doctorwho2005')
>>> print(tostring(doctor_who[0]))
<name>Doctor Who (2005)</name>
<ended />
<status>Returning Series</status>
<network country="UK">BBC One</network>
<aka country="FR">Docteur Who</aka>
<aka attr="Alternative Spelling" country="UK">Dr. Who</aka>
<aka country="IS">T&#237;maflakk</aka>
<aka attr="Fake Working Title" country="UK">Torchwood</aka>
<aka country="BG">&#1044;&#1086;&#1082;&#1090;&#1086;&#1088; &#1050;&#1086;&#1081;</aka>
<aka country="RU">&#1044;&#1086;&#1082;&#1090;&#1086;&#1088; &#1050;&#1090;&#1086;</aka>
<aka country="IL">&#1491;&#1493;&#1511;&#1496;&#1493;&#1512; &#1492;&#1493;</aka>
<aka country="IN">&#2337;&#2377;&#2325;&#2381;&#2335;&#2352; &#2361;&#2370;</aka>
<aka country="CN">&#30064;&#19990;&#22855;&#20154;</aka></akas>

The showinfo feed retrieves all meta data about one single show using the given showid. The result is identical to one element from the full_search results.

The episode_list feed returns all meta data about episodes of a TV show sorted by season. The optional node argument causes the function to return the desired XML node as ElementTree object:

>>> doctor_who_eps = feeds.episode_list('3332', node='Episodelist')
>>> print(tostring(doctor_who_eps[0]))
<Season no="1">
<title>The End of the World</title></episode>

The full_show_info feed combines the results of both showinfo and episode_list.

Using objects

The module tvrage.api provides wrapper classes for’s data feeds. It contains the following classes: Show, Season and Episode.

Working with TV show objects:

$ python
>>> import tvrage.api
>>> doctor_who = tvrage.api.Show('doctorwho2005')
>>> doctor_who.current_season
{1: Doctor Who (2005) 5x01 The Eleventh Hour, 2: Doctor Who (2005) 5x02 The Beast... }
>>> doctor_who.ended
>>> doctor_who.episodes
{1: {1: Doctor Who (2005) 1x01 Rose, 2: Doctor Who (2005) 1x02 The End of the World, ... }}
>>> doctor_who.genres
['Action', 'Adventure', 'Sci-Fi']
>>> doctor_who.latest_episode
Doctor Who (2005) 5x04 The Time of Angels (1)
>>> doctor_who.next_episode
Doctor Who (2005) 5x05 Flesh and Stone (2)
'Doctor Who (2005)'
>>> doctor_who.pilot
Doctor Who (2005) 1x01 Rose
>>> doctor_who.season(2)
{1: Doctor Who (2005) 2x01 New Earth, 2: Doctor Who (2005) 2x02 Tooth and Claw, ... }
>>> doctor_who.seasons
>>> doctor_who.shortname
>>> doctor_who.showid
>>> doctor_who.started
>>> doctor_who.status
'Returning Series'
>>> doctor_who.upcoming_episodes
<generator object upcoming_episodes at 0x152f0a8>

The Season object is a python dict with additional properties:

>>> s4 = doctor_who.season(4)
>>> s4.is_current
>>> s4.premiere
Doctor Who (2005) 4x01 Partners in Crime
>>> s4.finale
Doctor Who (2005) 4x13 Journey's End (3)
>>> s4.episode(3)
Doctor Who (2005) 4x03 Planet of the Ood
>>> s4.values()
[Doctor Who (2005) 4x01 Partners in Crime, Doctor Who (2005) 4x02 The Fires of... ]
>>> s4.keys()
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

The Episode object contains all information related to an certain episode:

>>> rose = doctor_who.season(1).episode(1)
>>> rose.airdate, 3, 26)
>>> rose.number
>>> rose.prodnumber
>>> rose.season
'Doctor Who (2005)'
>>> rose.title

For some episodes there is detailed summary information available. This information is not provided by the XML feeds, so it has to be extracted from the episode’s overview page via web scraping. Since it would be quite slow to load all those web pages for entire seasons upfront, the summary information is only loaded when the Episode.summary property is actually beeing read:

>>> nextff = tvrage.api.Show('flashforward').next_episode
>>> nextff
FlashForward 1x18 Goodbye Yellow Brick Road
>>> nextff.summary # spoilers alert!... you have to try this one for your self ;)

Using the Quickinfo Feed

The modul tvrage.quickinfo provides easy access to the tvrage’s quickinfo feed.

You can fetch meta data about a tv show alone:

>>> from tvrage import quickinfo
>>> quickinfo.fetch('doctor who 2005')
{'Status': 'Returning Series', 'Genres': ['Action', 'Adventure', 'Sci-Fi'], 'Network': 'BBC One (United Kingdom)',
'Classification': 'Scripted', 'Started': 'Mar/26/2005', 'Show Name': 'Doctor Who (2005)', 'Show URL':
'', 'Premiered': '2005', 'Airtime': 'Saturday at 07:00 pm', 'Ended': '',
'Show ID': '3332', 'Country': 'United Kingdom', 'Runtime': '50', 'Latest Episode': ['05x13', 'The Big Bang (2)', 'Jun/26/2010']}

or you can fetch informations about an specific episode combined with the show’s meta data:

>>> epinfo = quickinfo.fetch('doctor who 2005', ep='1x01')
>>> epinfo
{'Status': 'Returning Series', 'Genres': ['Action', 'Adventure', 'Sci-Fi'], ...
>>> epinfo['Episode Info']
['01x01', 'Rose', '26/Mar/2005']
>>> epinfo['Episode URL']

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-tvrage-0.4.1.tar.gz (10.6 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page