Login

Display Hulu Shows through GeekTool

For those who like GeekTool here is one more way to put it to use. This script parses the Hulu page of each show you feed it and returns the newest shows available.

Instructions Save the script somewhere it won't be deleted or moved and call it from GeekTool like so
/usr/bin/ruby /path/to/this/file.rb

Requirements
hpricot

Here is what it looks like on my desktop. Hulu Update

#!/usr/bin/env ruby -w

#
#  hulu_update.rb
#
#  Created by Craig Williams on 2009-02-04.
#

require 'rubygems'
require 'hpricot'
require 'open-uri'

LISTING_LIMIT = 3
DAYS_TO_RUN   = %w( Mon Tue Wed Thu Fri Sat Sun)     
START_TIME    = 8       
END_TIME      = 8
HULU_SHOWS    = [
  'Psych',
  'Burn Notice',
  'Monk',
  'Warehouse 13',
  'Heroes',
  'Community',
  'Bones',
  'Eastwick',
  'White Collar',
  'Sanctuary',
  'Eureka',
  'Stargate Universe',
  'V',
  'Fringe'
]

def retrieve_show_names(title)
  tvshow = title.downcase.strip.split(/\s/).join('-')
  count = 1
  display_text = "-- #{title} --\n"
  doc = Hpricot(open("http://www.hulu.com/#{tvshow}"))
  #(doc/"table.vex-episode//td.c1/a").each do |item|
  
  (doc/"//div[@class='vslc'][1]/div[@class='vsl vsl-short']/ul/li/a[@class='info_hover']").each do |item|
    return display_text if count == LISTING_LIMIT
    display_text << item.inner_html + "\n"
    count = count + 1
  end

  return display_text
end

def time_to_run?
  time = Time.now
  @hour = time.hour
  day = time.strftime("%a")
  if !DAYS_TO_RUN.include?(day)  
    puts "'#{day}' is not in your days to run parameter"
    return false 
  end
  
  return @hour >= START_TIME && @hour <= END_TIME ? true : false
end

if time_to_run? == false
  puts "'#{@hour}' is not in your hours to run parameter"
  exit
end

time_now = Time.now.strftime("%x at %X")
display = "Last run on: #{time_now}\n\n"

HULU_SHOWS.each do |show|
  display << retrieve_show_names(show) + "\n\n"
end

print display

Add comment


Security code
Refresh

 

Product Categories