Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created October 23, 2009 09:52
Show Gist options
  • Save hitode909/216786 to your computer and use it in GitHub Desktop.
Save hitode909/216786 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'open-uri'
require 'pp'
class Video
attr_accessor :title, :url
def setup
source = open(self.url).read
xml = Nokogiri.parse(source, nil)
@media_url = xml.at('src').content
end
end
class Episode
def initialize
@videos = []
end
attr_accessor :title, :thumbnail, :url
def self.parse(node)
episode = self.new
img = node.at('img')
episode.title = img['alt']
episode.thumbnail = img['src']
episode.url = node['href']
# XXX: onair
episode
end
def key
self.url.scan(/\d+/).first
end
def meta_url
"http://media.mtvnservices.com/video/feed.jhtml?ref=http%3A//www.southparkstudios.com&type=network&uri=mgid%3Acms%3Acontent%3Asouthparkstudios.com%3A#{self.key}&geo=US&orig=&mode=fe&franchise=&dist="
end
def setup
source = open(self.meta_url).read
xml = Nokogiri.parse(source, nil)
xml.search('item').each { |item|
video = Video.new
video.title = item.at('.//media:title').content
video.url = item.search('.//media:content').select{ |c| c['url']=~ /hiLoPref=hi/}.first['url']
video.setup
@videos << video
}
self
end
end
class Season
attr_accessor :episodes
def initialize
@episodes = []
end
def self.at(num)
season = Season.new
source = open("http://www.southparkstudios.com/episodes/season/#{num}/").read
html = Nokogiri::HTML.parse(source, nil)
html.search('a.content_eppreview').each { |node|
e = Episode.parse(node)
e.setup
season.episodes << e
}
season
end
end
require 'yaml'
require '1.rb'
alias old_open open
def open(*a)
puts a
old_open(*a)
end
seasons = []
(1..14).each{ |i| # XXX: continue
begin
s = Season.at(i)
rescue
exit
else
seasons << s
File.open("seasons.yaml", "w").puts(YAML.dump(seasons))
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment