Skip to content

Instantly share code, notes, and snippets.

@ward
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save ward/088b8ce2077eb89b88f4 to your computer and use it in GitHub Desktop.

Select an option

Save ward/088b8ce2077eb89b88f4 to your computer and use it in GitHub Desktop.
List trakt watchlist by popularity
#!/usr/bin/env ruby
# Lists the movies in your watchlist by their trakt popularity.
# Made this since it is broken for me on trakt.
require 'open-uri'
require 'json'
# You can find this in your profile
API_KEY = ''
USERNAME = ''
# Needed if your profile is not public. If it is, then also comment out the
# line with http_basic_authentication
PASSWORD = ''
def watchlist type
result = open(
"http://api.trakt.tv/user/watchlist/#{type}.json/#{API_KEY}/#{USERNAME}",
:http_basic_authentication => [USERNAME, PASSWORD]
)
watchables = JSON.load(result)
watchables.sort! { |a, b| b['ratings']['percentage'] <=> a['ratings']['percentage'] }
watchables.each_with_index do |watchable, idx|
puts "#{'%3.3s' % (1+idx)}) #{watchable['title']} - #{watchable['ratings']['percentage']}%"
end
end
case ARGV[0]
when "movie"
watchlist "movies"
when "show"
watchlist "shows"
else
puts "Invalid option"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment