Skip to content

Instantly share code, notes, and snippets.

@mnutt
Created July 28, 2009 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnutt/157464 to your computer and use it in GitHub Desktop.
Save mnutt/157464 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'vendor', 'rpodcast', 'lib'))
options = {}
ARGV.each do |arg|
key, value = arg.split('=')
options[key.intern] = value.to_i
end
options[:limit] ||= 1000
options[:offset] ||= 0
require 'rubygems'
require 'rpodcast'
require 'open-uri'
require 'json'
def leading_zero(num)
num < 10 ? "0#{num}" : num.to_s
end
class String
def truncate(size)
self.size > size ? self[0..size] : self
end
end
# Audios
content = open("http://www-tracey.archive.org/services/collection-rss.php?collection=78rpm").read
feed = RPodcast::Feed.new(content)
feed.parse
entries = feed.episodes.slice(options[:offset], options[:limit]).map{|e|
artist, title = e.title.split('-')
duration = "#{rand(8)}:#{leading_zero(rand(60))}"
album = e.title.split(' ').reverse.join(' ').truncate(48)
{ 'Artist' => artist.truncate(39), 'Link' => e.enclosure.url, 'Name' => title.truncate(39), 'Album' => album.truncate(39), 'Length' => duration, 'Type' => 'Audio' } if title
} rescue nil
# Videos
content = open("http://www-tracey.archive.org/services/collection-rss.php?mediatype=movies").read
feed = RPodcast::Feed.new(content)
feed.parse
entries << feed.episodes.slice(options[:offset], options[:limit]).map{|e|
title = e.title.truncate(90)
duration = "#{rand(15)}:#{leading_zero(rand(60))}"
{ 'Name' => e.title, 'Link' => e.enclosure.url, 'Length' => duration, 'Type' => 'Video' } if title
} rescue nil
# Images
content = open("http://api.flickr.com/services/feeds/photos_public.gne?id=51035599008@N01&lang=en-us&format=rss_200").read
feed = RPodcast::Feed.new(content)
feed.parse
entries << feed.episodes.slice(options[:offset], options[:limit]).map{|e|
title = e.title.truncate(80)
duration = "#{rand(15)}:#{leading_zero(rand(60))}"
{ 'Name' => e.title, 'Link' => e.enclosure.url, 'Type' => 'Image' } if title
} rescue nil
# Documents
content = open("http://www.scribd.com/feeds/group_rss/1257").read
doc = Hpricot.XML(content)
entries << feed.episodes.slice(options[:offset], options[:limit]).map{|e|
title = e.at('title').inner_html.truncate(80)
{ 'Name' => title, 'Size' => e.at('description').to_s.size * rand(25), 'Type' => 'Document' }
} rescue nil
schema = {
'Audio' => ['Sharing', 'Name', 'Artist', 'Album', 'Length'],
'Video' => ['Sharing', 'Name', 'Length'],
'Images' => ['Sharing', 'Name'],
'Documents' => ['Sharing', 'Name', 'Type']
}
response = {'schema' => schema, 'files' => entries.flatten.compact}
puts JSON.pretty_generate(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment