May 6

Overview

TheTVDB.com is user contributed TV show and episode database which is used by many popular home theatre applications, such as XBMC to look up details of TV shows.

I’ve written a simple Python interface to their Programmer’s API which makes it possible for developers to extract the TV data they need from TheTVDB with minimal effort.

Let me know if you find this useful, or you use it in any real projects!

Dependencies

This module uses cElementTree (available in Python 2.5+) to traverse XML, so you’ll need Python 2.5 available. Alternatively if you have an older version of Python you can install cElementTree or ElementTree yourself, and modify the import line at the top of the file.

Usage

I’m not going to go into great detail about the interface because the module is fairly self explanatory, but here are a few of the main functions:

Classes

There are 2 classes, the Show class and the Episode class. Most functions in this API return either a Show object, an Episode object, or a list of IDs. I’m not going to document all of the properties in each object as these are visible in the module itself, but you’d usually access the public variables directly, e.g. episode.overview.

Functions

  • get_matching_shows(show_name)
    Returns a list of tuples (id, name) of all matching shows in thetvdb
  • get_show(show_id)
    Get the show object matching this show_id.
  • get_episode(episode_id)
    Get the episode object matching this episode_id.
  • get_show_and_episodes(show_id)
    Get the show object and all matching episode objects for this show_id.
  • get_updated_shows(period)
    Get a list of show ids which have been updated within this period (day/week/month).
  • get_updated_episodes(period)
    Get a list of episode ids which have been updated within this period (day/week/month).
  • get_show_image_choices(show_id)
    Get a list of image urls and types relating to this show.

License

I’m releasing this under the GPL2 license. If you reuse it or improve it, please let me know!

Download

http://loopj.com/thetvdbapi/thetvdbapi.py

Apr 25

Version 1.1 Released!

  • Updated the license to jQuery standard GPL/MIT dual license
  • Moved the plugin to github by popular demand
  • Escape and tab keys now work (Thanks Dirk Bergstrom)
  • Can use settings.minChars to specify how many characters need to be type before a search is started (Thanks Dirk Bergstrom)
  • Can now prepopulate the list by settings settings.prePopulate with an array of {id: n, name: blah} (Thanks Nathan Edminster)
  • Can now change the name of the query param using settings.queryParam (Thanks Elijah Insua)
  • Can now preprocess the returned search results by specifying a settings.onResult function (Thanks Elijah Insua)
  • Can now set the content-type of returned data using settings.contentType (Thanks Elijah Insua)
  • Can now specify the maximum number of tokens allowed using settings.tokenLimit (Thanks Chris Dary and Paul)
  • Can now grab results from anywhere in the json using settings.jsonContainer (Thanks Richard G)
  • Can now fetch results using POST as well as GET with settings.method = “POST” (Thanks ellisgl)

Overview

This is a jQuery plugin to allow users to select multiple items from a predefined list, using autocompletion as they type to find each item. You may have seen a similar type of text entry when filling in the recipients field sending messages on facebook.

Features

  • Intuitive UI for selecting multiple items from a large list
  • Layout controlled fully in CSS, easily customisable
  • Result caching reduces server load
  • No images required, just the plugin’s .js file and some CSS
  • Handles json search data for autocompletion
  • Smooth animations when results load
  • Select items using the mouse or keyboard

Screenshots

Vertical list style item selection
Vertical list style item selection

Facebook style item selection
Facebook style item selection

Demo

A live demo of the token input is available here.

Usage

  • Make sure you have jquery script included on your page
  • Include jquery.tokeninput.js on your page
  • Include one of the provided stylesheets, or make your own
  • Create a server-side script (php/rails/django anything goes) to generate the search results.
    The script itself can fetch data from wherever you like, for example a database or a hardcoded list, but it must do the following:

    • Take exactly one GET parameter named “q” which will contain the query string. E.g. http://www.example.com/myscript?q=query
    • Output JSON search results in the following format:
      [{"id":"856","name":"House"},
       {"id":"1035","name":"Desperate Housewives"},
       {"id":"1048","name":"Dollhouse"},
       {"id":"1113","name":"Full House"}
      ]
  • Turn text inputs into tokeninputs using jQuery and point them to your results script:
    <script type="text/javascript">
    $(document).ready(function () {
      $("#my-text-input").tokenInput("/url/to/your/script/");
    });
    </script>
  • A list of selected item ids is created inside the original text entry, process them as usual when the form is submitted.

License

This plugin is released under a dual license. You can choose either the GPL or MIT license depending on the project you are using it in and how you wish to use it.

Download

Quick Download

Please don’t use these links directly in your scripts, I might change their location at any time. Instead, download them and use your own local copy.

Github Project

If you would like to contribute to this plugin, check out the github repository here:
http://github.com/loopj/jQuery-Tokenizing-Autocomplete-Plugin/tree/master

Jun 16

CSS veterans will probably already know this, but here’s a fix to a problem which has been bugging me for ages.

Problem:

If you have something like:

<div>
    <img src=... />
</div>

You may see a gap below the image on some browsers, a gap which cannot be removed by setting the padding/margins to 0:

Solution:

<img> tags are rendered using display: inline by default, which means they act and flow like text does on a page. In order to stop spaces being added (caused by spaces next to the img tag in your html), you should set your img to use display: block.

<img style="display: block" src="..." alt="" />

This means your image will no longer act like flowing text and will no longer have a gap below it!

Caveats:

Changing from display: inline means your img tag will ignore things like text-align: center, and other alignments specific to displaying elements inline.

Image credit: buhsnarf on flickr