Skip to content

Instantly share code, notes, and snippets.

@voidet
Created July 25, 2012 10:39
Show Gist options
  • Save voidet/3175485 to your computer and use it in GitHub Desktop.
Save voidet/3175485 to your computer and use it in GitHub Desktop.
Trakt.tv currently playing to text file
require "net/http"
require "uri"
require 'json'
require 'yaml'
uri = URI.parse("http://api.trakt.tv/user/watching.json/your_api_key/targetusername")
response = Net::HTTP.get_response(uri)
result = JSON.parse response.body
if result.is_a?(Hash)
#puts result.to_yaml
if result["show"]
title = "<div style=\"padding-left: 20px;\"><h3>ON MY TV</h3><h5 style=\"margin-bottom: 10px;\">#{result['show']['title']} - #{result['episode']['title']} (s#{result['episode']['season']}e#{result['episode']['number']})</h5>"
poster = result['show']['images']['poster'].gsub('.jpg', '-138.jpg')
title << "<img src=\"#{poster}\" /></div>"
elsif result["movie"]
title = "<div style=\"padding-left: 20px;\"><h3>ON MY TV</h3><h5 style=\"margin-bottom: 10px;\">#{result['movie']['title']} (#{result['movie']['year']}</h5>"
poster = result['movie']['images']['poster'].gsub('.jpg', '-138.jpg')
title << "<img src=\"#{poster}\" /></div>"
end
trakt = File.new("playing.txt", "w")
trakt.write(title)
trakt.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment