A little programming exercise to keep the coder alive ... Problem: DJ Marky's podcast gone in iTunes. Suggested fix: batch-download podcast feed. Requirement: 140 characters ("golf") solution to tweet it around ... no seriously: I wanted to see how to solve this in a nice one-liner (so no fancy input options for this script ... google on: 'script download podcast feed <your preferred coding tool>' for more advanced stuff already out there).
This is what I have come up with so far:
wget $(wget -q -O - feed_url | sed -n 's/.*enclosure.*url="\([^"]*\)" .*//p')
Read this from the inside-out: get the feed and dump to standard output (-O) and without other noise (-q), filter the enclosure tags and get the URL out of it (the enclosure tag is what the feeds have in common. See the RSS spec). This is wrapped in a subprocess ( $(...) ) and provides a list of mp3 files which is fed to the outer wget which starts to download them one by one.
Although I tend to use perl -pe in one-liners for its powerful regex engine, I learned the useful -n / p combo of sed to combine grep and replacing strings in one go (suggestions in perl are welcome in the comments ...)
Extending it to a small script to receive a feed as input as first command line argument ($1):
podcast_feed.sh
#!/bin/bash wget $(wget -q -O - $1 | sed -n 's/.*enclosure.*url="\([^"]*\)" .*//p')
Testing a 'dry run' (don't download / print-only) version with various feeds (just take the outer wget off)
podcast_feed_print.sh
#!/bin/bash wget -q -O - $1 | sed -n 's/.*enclosure.*url="\([^"]*\)" .*/# /p'
Test it with 5 feeds:
$ for pc in $(cat podcast_feed_test.txt);
> do echo "testing "$pc && ./podcast_feed_print.sh $pc | head -2 && echo
> done
testing http://djmarky.com.br/podcast/podcast.xml # http://p.audio.uol.com.br/djmarky/podcast/markys_podcast_august_2013.mp3 # http://p.audio.uol.com.br/djmarky/podcast/marky_july_2013.mp3 testing http://feeds.feedburner.com/spipodcast # http://traffic.libsyn.com/patflynn/SPI092-Psychology_of_Selling_How_to_Price.mp3 # http://traffic.libsyn.com/patflynn/SPI091-Mixing_Online_Business_with_Offline_Marketing_Strategies.mp3 testing http://www.fatburningman.com/feed/podcast/ # http://traffic.libsyn.com/fatburningman/99DrDavidPerlmutter.mp3 # http://traffic.libsyn.com/fatburningman/98ChrisKresser.mp3 testing http://lewishowes.com/feed/podcast/ # http://media.blubrry.com/the_school_of_greatness/www.podtrac.com/pts/redirect.mp3/feeds.soundcloud.com/stream/126379015-lewishowes-sean-stephenson-how-to-leave.mp3 # http://media.blubrry.com/the_school_of_greatness/www.podtrac.com/pts/redirect.mp3/feeds.soundcloud.com/stream/124890483-lewishowes-daniel-negreanu.mp3 testing http://feeds.feedburner.com/se-radio # http://feedproxy.google.com/~r/se-radio/~5/mqwgeoTD1sc/SE-RadioEpisode199-MichaelStonebraker.mp3 # http://feedproxy.google.com/~r/se-radio/~5/rcNWFPGdwrk/SE-RadioEpisode198-WilVanDerAalst.mp3
Works, and with 86 characters quite small!
Downloading podcasts now ...
$ podcast_feed.sh http://djmarky.com.br/podcast/podcast.xml --2013-12-27 00:46:35-- http://p.audio.uol.com.br/djmarky/podcast/markys_podcast_august_2013.mp3 Resolving p.audio.uol.com.br... 200.147.98.177, 200.147.1.156, 200.147.1.157, ... Connecting to p.audio.uol.com.br|200.147.98.177|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 89803694 (86M) [audio/mpeg] Saving to: ‘markys_podcast_august_2013.mp3’ .. ..
The code used in this post can be found here.
- command line (5) ,
- feed (2) ,
- golf (1) ,
- perl (10) ,
- podcast (1) ,
- scripting (9) ,
- sed (1) ,
- unix (5) ,
- wget (1) ,
- XML (2)