An API for twitter hashtags for TV programmes

Overview
Hacking together an API that returns commonly-used hashtags for the programme you’re watching on the TV

Background
tweets on TVLast April, I wrote a quick-and-dirty Python script that displays tweets for a given hashtag on my TV screen so that I could follow the twitter backchannel about a programme that I watched.

Considering that it was a random idea that was hacked together in a few minutes, I’ve used it a lot since then: it’s made watching a bunch of programmes much more entertaining – Eurovision is probably the best example (the commentary on twitter is hysterical), but there are many others.

But I never made any changes to the script since I first wrote it. If I’m watching something on TV that I know has a hashtag, I ssh to my set-top box and run my hashtags script, giving it the hashtag to filter on in the command.

I was thinking – it’d be much better if it was all automatic. It’d be better if my set-top box automatically showed tweets with the hashtag for whatever programme I’m watching.

To do this, I needed some way of knowing what was the right hashtag for the programme currently on a given TV channel. I could’ve hacked this into my existing script, but I thought it might be a feature that people might find other uses for, so instead I’ve made a stand-alone thing, available as a web-service.

What it does
I’ve made a web feed that returns a blob of either JSON or XML. You can get either:

  • the commonly-used hashtag for the programme currently on a specified channel (e.g. “what is the hashtag for the programme that’s on BBC 1 now?”)
  • the next programme on TV that has a commonly-used hashtag (e.g. “what are the next five programmes on TV that have hashtags?”)

I’ve assumed that discussions on twitter mainly take place the first time that a programme is on, so repeats are generally not included.

How I made it
Rather than write a bunch of code, I’ve made it using Yahoo! Pipes.

It’s a mashup of some BBC Programmes feeds, together with a static CSV file I’ve made that contains a mapping of BBC programme IDs to twitter hashtags. This is a disappointingly manual step – ideally this would be made in a more dynamic or perhaps crowd-sourced way. But for now, it’s a CSV file, that I’m hosting using a public dropbox folder.

(As an aside – it’d be good to add more to this file. If you can think of any programmes which have common hashtags that I might have missed, please do let me know in the comments.)

This does mean that my feed will only work with BBC TV channels. If only other channels put the resources that the BBC do into sharing data and feeds, eh? But for now, it’s not a major issue for my needs… to be honest, other than X Factor, I can’t think of any TV programmes that I follow the twitter back-channel for that isn’t on a BBC channel.

Where to find it
hashtags on now

One required argument :
‘channel’ – the channel name. This is “bbcone”, “bbctwo”, “bbcthree”, etc.

hashtags on next

Two optional filters :
‘limit’ – how many programmes to return – e.g. limit==5 shows you the next five programmes that have a known hashtag
‘channel’ – the name of a channel that you want to see programme(s) for – e.g. “bbcone”, “bbctwo”, “bbcthree”, etc.

Hope someone finds this useful. It doesn’t need any authentication, and is just a straight HTTP GET that returns JSON or XML. Hopefully it’s as simple to use as it was to hack together.

Yahoo! Pipes let you clone other people’s pipes, which is very cool – it means that you can take a copy of what I’ve done, and tweak, extend and improve it to suit your needs.

Warning

I’ve not done any real testing on these, and this was my first real use of Pipes, so… use with caution 🙂

Some examples

hashtags now on BBC 1 – channel=bbcone&_render=json

{
  "count": 1,
  "value": {
    "title": "TV hashtags - now",
    "description": "What are the commonly used hashtags on twitter for the BBC TV programme on now?",
    "items": [
      {
        "hashtag": "eastenders",

        "start": "2010-12-31T20:00:00Z",
        "end": "2010-12-31T20:40:00Z",
        "duration": "2400",

        "programme": {
          "programme": {
            "title": "EastEnders",
            "pid": "b006m86d",
            "type": "brand",
            "ownership": {
              "service": {
                "title": "BBC One",
                "id": "bbc_one",
                "type": "tv",
                "key": "bbcone"
              }
            }
          },
          "display_titles": {
            "title": "EastEnders",
            "subtitle": "31/12/2010"
          },
          "short_synopsis": "Ronnie's grief leads to a momentary act of desperation with devastating consequences.",
          "pid": "b00x2pwx",
          "type": "episode",
          "title": "31/12/2010",
          "ownership": {
            "service": {
              "title": "BBC One",
              "id": "bbc_one",
              "type": "tv",
              "key": "bbcone"
            }
          }
        },

        "src": "http://www.bbc.co.uk/bbcone/programmes/schedules/london/today.json"
      }
    ],
    "link": "http://pipes.yahoo.com/pipes/pipe.info?_id=ef9269bf39bd9d8620356afc3941ee09",
    "pubDate": "Fri, 31 Dec 2010 20:03:15 +0000",
    "generator": "http://pipes.yahoo.com/pipes/"
  }
}

hashtags on next – limit=2&_render=json

{
    "count": 2,

    "value": {
        "title": "TV hashtags - next",
        "description": "What are the next BBC TV programmes what have commonly used hashtags on twitter?",

        "items": [
            {
                "hashtag": "eastenders",

                "schedule_date": "2010-12-31",
                "start": "2010-12-31T20:00:00Z",
                "end": "2010-12-31T20:40:00Z",
                "duration": "2400",

                "service": {
                    "title": "BBC One",
                    "id": "bbc_one",
                    "type": "tv",
                    "key": "bbcone"
                },

                "programme": {
                    "programme": {
                        "title": "EastEnders",
                        "pid": "b006m86d",
                        "type": "brand",
                        "ownership": {
                            "service": {
                                "title": "BBC One",
                                "id": "bbc_one",
                                "type": "tv",
                                "key": "bbcone"
                            }
                        }
                    },
                    "display_titles": {
                        "title": "EastEnders",
                        "subtitle": "31/12/2010"
                    },
                    "short_synopsis": "Ronnie's grief leads to a momentary act of desperation with devastating consequences.",
                    "pid": "b00x2pwx",
                    "type": "episode",
                    "title": "31/12/2010",
                    "ownership": {
                        "service": {
                            "title": "BBC One",
                            "id": "bbc_one",
                            "type": "tv",
                            "key": "bbcone"
                        }
                    }
                },

                "src": "http://www.bbc.co.uk/programmes/b006m86d/episodes/upcoming/debut.json"
            },
            {
                "hashtag": "mastermind",

                "schedule_date": "2011-01-03",
                "start": "2011-01-03T20:30:00Z",
                "end": "2011-01-03T21:00:00Z",
                "duration": "1800",

                "service": {
                    "title": "BBC One",
                    "id": "bbc_one",
                    "type": "tv",
                    "key": "bbcone"
                },

                "programme": {
                    "programme": {
                        "programme": {
                            "title": "Celebrity Mastermind",
                            "pid": "b008pc8h",
                            "type": "brand",
                            "ownership": {
                                "service": {
                                    "title": "BBC One",
                                    "id": "bbc_one",
                                    "type": "tv",
                                    "key": "bbcone"
                                }
                            }
                        },
                        "pid": "b00x864x",
                        "title": "2010/2011",
                        "type": "series"
                    },
                    "display_titles": {
                        "subtitle": "2010/2011, Episode 6",
                        "title": "Celebrity Mastermind"
                    },
                    "short_synopsis": "Guests are Robert Webb, Helen Skelton, Stephen Mangan and Sir Clive Sinclair.",
                    "pid": "b00xc86z",
                    "type": "episode",
                    "title": "Episode 6",
                    "ownership": {
                        "service": {
                            "title": "BBC One",
                            "id": "bbc_one",
                            "type": "tv",
                            "key": "bbcone"
                        }
                    }
                },

                "src": "http://www.bbc.co.uk/programmes/b008pc8h/episodes/upcoming/debut.json"
            }
        ],
        "link": "http://pipes.yahoo.com/pipes/pipe.info?_id=614c245ff4100207cd833c31bb7dde50",
        "pubDate": "Fri, 31 Dec 2010 20:08:16 +0000",
        "generator": "http://pipes.yahoo.com/pipes/"
    }
}

Tags: , , , ,

7 Responses to “An API for twitter hashtags for TV programmes”

  1. Sarah says:

    Get yourself signed up to datasift.net trust me you’ll love it and it’ll make stuff like this so easy & much less time consuming enabling you to spend more time on the fun stuff 🙂

  2. Tony Hirst says:

    Nice app 🙂 FWIW, here’s another bit of pipework built around OU/BBC progs that uses delicious as a database source, rather than a CSV file, and parses the Linked Data programme pages for programme info:
    http://blog.ouseful.info/2010/12/03/linked-data-without-the-sparql/

    With Yahoo undergoing all sorts of cuts atm, you may also be interested in Greg Gaughan’s pipe2py compiler, which generates a python equivalent of a yahoo pipe (almost… not all pipes modules are supported (yet..): https://github.com/ggaughan/pipe2py

  3. dale says:

    Thanks for the links – interesting to see what else people are doing with Pipes. It’s pretty impressive.

    I like the idea of exporting it to Python that you can run yourself – that’s neat.

  4. Greg Gaughan says:

    I’ve made a few improvements and enhancements to pipe2py and these pipes are now runnable locally and on Google App Engine.

    hashtags on now: http://pipes-engine.appspot.com/info/ef9269bf39bd9d8620356afc3941ee09?channel=bbcone

    hashtags on next: http://pipes-engine.appspot.com/info/614c245ff4100207cd833c31bb7dde50?channel=bbcone

  5. dale says:

    Greg – That’s awesome, thanks! 🙂

  6. dale says:

    Thanks for the pointer, Paul – I hadn’t spotted that. That’s very cool 🙂