Skip to content

Instantly share code, notes, and snippets.

@houshuang
Created May 20, 2010 17:59
Show Gist options
  • Save houshuang/407863 to your computer and use it in GitHub Desktop.
Save houshuang/407863 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'youtube_g'
require 'pp'
client = YouTubeG::Client.new
allvids = Array.new
count = 1
begin
while true
videos = client.videos_by(:user => 'vu', :page => count)
allvids = allvids + videos.videos
count = videos.next_page
$stderr << count
break unless count
end
rescue Exception=>e
end
keywords = Hash.new
courses = Hash.new
allvids.each do |vid|
unless courses[vid.description]
courses[vid.description] = Array.new
keywords[vid.description] = vid.keywords
end
courses[vid.description] << vid
end
puts "<h1>Course titles</h1><ul>"
courses.sort.each do |element|
puts "<li><a href=\##{element[0]}>#{element[0]}</a></li>"
end
puts "</li><p>"
# puts "<h1>Categories</h1>"
puts "<h1>Individual courses</h1><ul>"
courses.each_pair do |desc,vids|
uniq_ary=[]
puts "<a name=#{desc}>"
puts "<li><b>#{desc}</b> - <i>#{keywords[desc].join(", ")}</i></li><ul>"
vids.sort! {|a,b| a.title.downcase <=> b.title.downcase}
vids.each do |vid|
next if uniq_ary.index(vid.title)
uniq_ary << vid.title
puts "<li><a href=#{vid.player_url}>#{vid.title}</a></li>"
end
uniq_ary = []
puts "</ul><p>"
end
puts "</ul><p>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment