Skip to content

Instantly share code, notes, and snippets.

@abevoelker
Created January 10, 2011 04:00
Show Gist options
  • Save abevoelker/772338 to your computer and use it in GitHub Desktop.
Save abevoelker/772338 to your computer and use it in GitHub Desktop.
DJ Tiësto's podcast download/sync script
#!/usr/bin/ruby
#-------------------------------------------------------------------------------
# File: tiestoSync.rb
# Purpose: Syncs a directory of DJ Tiësto's podcasts with the current Web list
# Arguments: [0] Directory containing podcast files to sync
# Returns: N/A
# Example: tiestoSync.rb ~/podcasts
# Author(s): Abe Voelker (http://abevoelker.com)
# Created: 2011-01-09
# License: Released into the public domain.
#-------------------------------------------------------------------------------
PODCAST_URL = 'http://www.radio538.nl/clublife/podcast.xml'
require 'net/http'
require 'rubygems'
require 'xmlsimple'
#Just a few checks for good measure
dir = ARGV[0]
if !File::exists?(dir) then
$stderr.puts("'" + dir + "' doesn't exist!")
exit
end
if !File::directory?(dir) then
$stderr.puts("'" + dir + "' isn't a directory!!")
exit
end
if !File::writable?(dir) then
$stderr.puts("Directory '" + dir + "' isn't writable!")
exit
end
xml_data = Net::HTTP.get_response(URI.parse(PODCAST_URL)).body
data = XmlSimple.xml_in(xml_data)
data['channel'][0]['item'].each do |item|
podcast = item['enclosure'][0]['url']
file = podcast.split("/").last
puts "Checking for file '" + file + "'"
if File::exists?(dir + '/' + file) then
puts "Skipping existing file '" + file + "'"
else
puts "Downloading non-existent file '" + file + "'..."
file = dir + '/' + file
Net::HTTP.start(URI.parse(podcast).host) do |http|
resp = http.get(podcast)
open(file, "wb") do |file|
puts "Writing file to disk..."
file.write(resp.body)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment