Merge pull request #1 from darrencauthon/rubyize

Thanks I'm not that much of a rubyist (apart from making rake tasks to build my stuff), and I did this at like 3 am this morning so I was super tired....
This commit is contained in:
Tommy Parnell
2014-05-28 14:26:27 -04:00

View File

@@ -4,14 +4,23 @@ require 'nokogiri'
require 'fileutils'
FileUtils.mkdir_p 'downloads/'
FileUtils.cd 'downloads/'
xml = Nokogiri::XML(open('http://s.ch9.ms/Shows/Azure-Friday/feed/mp4high'))
item = xml.xpath('//item')
item.each do |s|
next if File.exist? s.at('enclosure')['url'].to_s.split('/').last
File.open("#{s.at('enclosure')['url'].to_s.split('/').last}", "wb") do |file|
puts " downloading " + s.at('enclosure')['url'].to_s.split('/').last
file.write open("#{s.at('enclosure')['url']}").read
end
def podcasts
feed = 'http://s.ch9.ms/Shows/Azure-Friday/feed/mp4high'
Nokogiri::XML(open(feed)).xpath('//item')
end
podcasts.each do |podcast|
source = podcast.at('enclosure')['url'].to_s
name = source.split('/').last
local_file = "downloads/#{name}"
next if File.exist? local_file
File.open(local_file, "wb") do |file|
puts " downloading " + name
file.write open(source).read
end
end
puts 'all done!