Home > Uncategorized, music > Groovy drumming

Groovy drumming

Recently I bought myself a cool Roland V-Drum set.

Now I stumbled across freedrumlessons.com, a site with dozens of (you guessed it) free drum lessons on video.

In order to avoid downloading all video files manually, I wrote a little Groovy script. It greps the overview page for all links to sub-pages, and then scrapes all the sub-pages for MP4-files (so I can put them on my iPod later).

I can’t imagine what it would have been like using plain Java…

Here’s the code:

[sourcecode language='java']
println (‘————————’)
def filesToDownload = []
def url = ‘http://www.freedrumlessons.com/drum-lessons’

def slurper = new XmlSlurper(new org.ccil.cowan.tagsoup.Parser())

def html = slurper.parse(url)
def lists = html.’**’.findAll { it.name() == ‘li’}

def links = lists.a*.’@href’
links.removeAll([''])

def i = 0

links.each {
def scrapeurl = “http://www.freedrumlessons.com${it}”
println “Scraping ${scrapeurl}…”
def innerSlurper = new XmlSlurper(new org.ccil.cowan.tagsoup.Parser())
def innerHtml = innerSlurper.parse(scrapeurl)

def files = innerHtml.depthFirst().grep{ it.name() == ‘a’ && it.@href.toString().endsWith(‘.mp4′) }.’@href’

files.each {
filesToDownload += it.toString()
println (“Added ${it}”)
}
}

println (‘ ** ‘)

filesToDownload.each {
println (“Downloading ${it}”)
def filename = it.tokenize(‘/’)[-1]
def infile = new FileOutputStream(filename)
def outfile = new BufferedOutputStream(infile)
outfile << new URL(it).openStream()
outfile.close()
}

println “Finished”
[/sourcecode]

Share this:
  • LinkedIn
  • del.icio.us
  • Digg
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • TwitThis
  1. June 27th, 2008 at 20:30 | #1

    Working on sth similar but based on dineJS http://code.google.com/p/dinejs/ and E4X. Especially check out the sample about the NES ROM downloader

    http://code.google.com/p/dinejs/wiki/SampleDownloadRoms

  2. Maria
    January 28th, 2009 at 14:37 | #2

    Oh, was bin ich neidisch (auf das V-Drumset natürlich)!!!!! Möchte eines, seit ich in Wien bin, aber habe einfach keinen Platz dafür ;(
    Welches hast du denn?

  3. tom
    January 28th, 2009 at 22:08 | #3

    aber geh, keinen platz? viel kompakter gehts doch gar nicht mehr :-)

    ich hab das TD-9KX und bin sehr happy damit – v.a. hat es diese übungssongs zusätzlich zum durchgeschliffenen line-in, an dem mein ipod hängt. irgendwann kauf ich mir eine grössere snare und häng die jetzige als 4. tom dazu – dann noch ein 2. crash-becken…

  1. No trackbacks yet.