Created
February 16, 2014 21:55
-
-
Save amoilanen/9041189 to your computer and use it in GitHub Desktop.
Simple script that downloads all the JavaScript Jabber http://javascriptjabber.com/ episodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Downloads all the mp3 episode recordings from JavaScript Jabber http://javascriptjabber.com | |
#Assumes that the system 'wget' command is available which is the case on Linux | |
#Episodes will be downloaded to /home/user/JSJabber | |
require 'net/http' | |
def get(uri) | |
response = Net::HTTP.get_response(URI.parse(uri)) | |
if response.code == "301" | |
response = Net::HTTP.get_response(URI.parse(response.header['location'])) | |
end | |
response.body | |
end | |
def episode_links | |
html = get("http://javascriptjabber.com/episode-guide/") | |
links = html.scan(/href="(http:\/\/javascriptjabber.com\/\d+[^#]*?)"/) | |
links.map{ |match| match[0] }.uniq | |
end | |
def mp3_download_link(episodeLink) | |
html = get(episodeLink) | |
html.match(/href="(.*?)".*title="Download"/)[1] | |
end | |
def download_episode(episodeLink) | |
downloadLink = mp3_download_link(episodeLink) | |
system("wget -P ~/JSJabber #{downloadLink}") | |
end | |
episodes = episode_links | |
count = 0 | |
puts "Total #{episodes.length} to download..." | |
episodes.each do |episode| | |
count += 1 | |
puts "Downloading episode #{count} of #{episodes.length}" | |
download_episode(episode) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment