Downloading Videos From RubyPlus with Ruby (and unix)

When I discovered that I had an account at rubyplus.org and realized how many screencasts they had that were available for my viewing pleasure, I got excited… Real excited!

And then I noticed that I would have to click the download button for each and every one of the videos; I want the world, I want the whole world… 

I knew I could use Ruby to help me download every video with ease, so I made an ultra tiny script:

(1..69).each do |episode_number|
`wget http://ldenman:blindedyo@rubyplus.org/episodes/#{episode_number}/download`
end

There were 69 (meow) episodes created from RubyPlus, hence the (1..69).
Surely you know the range method:

(1..10).each {|num| print num} #=> 12345678910

A Range represents an interval—a set of values with a start and an end. Ranges may be constructed using the s..e and s…e literals, or with Range::new. Ranges constructed using .. run from the start to the end inclusively. Those created using … exclude the end value. When used as an iterator, ranges return each value in the sequence.

We are using our range as an iterator

so I specify the number I want to start with, episode 1 and I specify the number I want to end with 69 and then I join those two numbers together with.. (I could use to join the numbers together, but it would exclude the last number from the output.)

I then send the message each on our range. Now, each takes a block. A block is basically a chunk of code run between a do and an end keyword. so we have a block:

#Block with keywords
(1..5).each do |number|
 print number
end
#=>12345

#Block with brackets
(1..5).each {|number| print number}
#=>12345

That’s right, same answer… different syntax.

So, now we look at the code inside the block(line 2):

(1..69).each do |episode_number|
`wget http://ldenman:blindedyo@rubyplus.org/episodes/#{episode_number}/download`
end

For each number in our range, wget will be called with our specified url. And our episode_number will continue to increase until we have reached 69.
I guess I should say that you have to place any console code between these little `grave accents`

GNU Wget is a free software package for retrieving files using HTTP, HTTPS and FTP, the most widely-used Internet protocols. It is a non-interactive commandline tool, so it may easily be called from scripts, cron jobs, terminals without X-Windows support, etc.

Hey! Wget may be easily called from scripts!!! That’s What I Just Did Weeeeeeeee! And It Was Easy, Wasn’t It?!

Then, we finalize the script with our end keyword and then we run it in a directory we want it.

ruby download_all_files.rb

Whoomp There It Is!

Ruby

makes it easy to do stuff like this and it’s all fun and games too!

RailsCasts on my iPhone

Unless you aren’t in the know, Ryan Bates’ RailsCasts happens to be a really great series of short rails blurbs giving you good hints into anything from checking out your production log to refactoring your code to restful authentication and so on and on and on.

Last night I decided it would be a great night to fall asleep and sure enough, I couldn’t get to sleep. So I decided to think about ruby on rails. Some nights when I can’t fall asleep I think about that, among other things. Then, suddenly, I realized that my iPhone has the ability to stream MP4’s. And well, Ryan Bates already had it on the lockdown and decided to hook a brother up with railscasts in MP4. So I perk up on my pillow and go Railscasts.com. You should try it out!

The Jing Project

The Jing Project is an interesting application that I stumbled upon the other day. I didn’t actually use the site stumble upon to find it, I actually just saw a group of pictures on Flickr that were watermarked: “Brought to you by the Jing Project.”

So, I didn’t think much of it at the time… I was just sort of annoyed at all the watermarked images. But then I actually went to the Jing Project site. After reading the three main features on the website, I decided to give it a whirl. To my surprise, when I opened the application a cute logo came up and then fancilly set itself up in the upper right corner of my screen. It resembles a small sun just ready to shine it’s goodness. However, if you don’t like the sun and think it’s too intrusive, you can add an icon to your menu bar instead. I like the menu bar, personally.

As soon as I opened the application I knew what to do. Just click the button and record an image or screencast. It’s dead easy; It’s Free. If you haven’t checked it out, do so. Just check out the site.