public
Description: Podcast Get is a short program for fetching new podcasts and plunking them on your disk
Homepage: http://jadn.com/~bob/
Clone URL: git://github.com/bherrmann7/podcast-get.git
podcast-get / src / pget.groovy
f2295299 » bherrmann7 2008-11-13 Users are so demanding. Tr... 1 /*
2 How to get and use this script
6c106120 » bherrmann7 2008-11-20 Reordered podcasts. added ... 3 0. Get Groovy from http://groovy.codehaus.org/
06879147 » bherrmann7 2008-11-13 4 1. Download this script as pget.groovy (click the 'raw' link on this github page.) --------------------^^^
f2295299 » bherrmann7 2008-11-13 Users are so demanding. Tr... 5 2. Create a directory to save the podcast in (for example, mkdir /tmp/podcasts )
6 3. Edit pget.groovy and change the sites to be url's to podcasts you like
7 4. Run like this, "groovy pget.groovy <downloadLocation>" (ie. groovy pget.groovy /tmp/podcasts)
8 Enjoy.
bf1157b7 » bherrmann7 2008-11-13 More words about why and wh... 9
7c968d27 » bherrmann7 2008-11-14 move lines around in the co... 10 I use this script to download new mp3's into a directory. I then copy the files onto my mp3 player and
11 listen to them during my commute. When I'm need a recharge of new mp3s, I re-run the script to get more podcasts.
12
bf1157b7 » bherrmann7 2008-11-13 More words about why and wh... 13 This script;
f84dbd01 » bherrmann7 2008-11-14 mixed single and double quo... 14 - numbers the files uniquely (so there aren't any naming collisions)
830daeeb » bherrmann7 2008-11-13 more explanation 15 - preserves the download order so I hear my most important podcasts first.
16 - keeps track of what is downloaded (so you don't get the same podcasts over and over.)
17 - only downloads a max of 3 podcasts from each source (so when first using this script you don't get 100 podcasts)
bf1157b7 » bherrmann7 2008-11-13 More words about why and wh... 18 - You can stop the script and edit and re-run it (tweaker friendly). Rerunning is safe because it doesn't update the history until the end and it skips already downloaded files.
19
dc89f9cb » bherrmann7 2008-11-13 Add some simple usage instr... 20 */
f2295299 » bherrmann7 2008-11-13 Users are so demanding. Tr... 21 // groovy 1.6beta2 has a bug. uncomment this line to use it.
22 // def args = [ "/tmp/podcasts" ]
23 if (args.size() != 1 ){
24 println "usage: pget downloadDirectory"
25 System.exit(1)
26 }
27 def downloadLocation = args[0]
28 if ( !new File(downloadLocation).isDirectory() ){
29 println "Error: The argument (${downloadLocation}) is not a directory."
28f25a0c » bherrmann7 2008-11-13 Make the download location ... 30 System.exit(-1);
31 }
f2295299 » bherrmann7 2008-11-13 Users are so demanding. Tr... 32 downloadLocation += File.separator + "%04d-%s"
9615b941 » Bob Herrmann 2008-11-10 adding in pget.groovy 33
34 def downloadHistory = []
f84dbd01 » bherrmann7 2008-11-14 mixed single and double quo... 35 def downloadHistoryFile = new File(System.properties['user.home']+File.separator+'.pgetDownloadHistory');
9615b941 » Bob Herrmann 2008-11-10 adding in pget.groovy 36 if ( downloadHistoryFile.exists() ){
37 downloadHistory = evaluate(downloadHistoryFile.text)
38 } else {
39 println "Warning: No download history found, creating a new one."
40 }
41
42 println "running, cached: " + downloadHistory.size()
43
44 sites = [
3afaa37b » Bob Herrmann 2009-03-23 updated podcasts 45 "http://feeds2.feedburner.com/WebdevradioPodcastHome",
46 "http://feeds2.feedburner.com/PhandroidPodcast",
47 "http://feeds2.feedburner.com/ThisAintYourDadsJava",
93fc86af » bherrmann7 2009-02-27 added javaworld, re-ranked ... 48 "http://www.cringely.com/feed/podcast/",
49 "http://feedproxy.google.com/androidguyscom",
3afaa37b » Bob Herrmann 2009-03-23 updated podcasts 50 "http://hansamann.podspot.de/rss",
51 "http://www.pbs.org/cringely/pulpit/rss/podcast.rss.xml",
6c106120 » bherrmann7 2008-11-20 Reordered podcasts. added ... 52 "http://feeds.feedburner.com/javaposse",
53 "http://feeds.feedburner.com/rubyonrailspodcast",
54 "http://blog.stackoverflow.com/index.php?feed=podcast",
9615b941 » Bob Herrmann 2008-11-10 adding in pget.groovy 55 "http://leoville.tv/podcasts/ww.xml",
56 "http://www.nofluffjuststuff.com/s/podcast/itunes.xml",
57 "http://media.ajaxian.com/",
734a1e40 » bherrmann7 2009-02-02 58 "http://agiletoolkit.libsyn.com/rss",
59 "http://feeds.feedburner.com/railsenvy-podcast",
9615b941 » Bob Herrmann 2008-11-10 adding in pget.groovy 60 "http://www.discovery.com/radio/xml/sciencechannel.xml",
61 "http://feeds.feedburner.com/gigavox/channel/itconversations",
62 "http://www.scienceandsociety.net/podcasts/index.xml",
63 "http://leoville.tv/podcasts/floss.xml",
64 ]
65 enclosures = [:]
66
67 histmap = [:]
68 downloadHistory.each {urlName, fileName ->
69 histmap[urlName] = fileName
70 }
71
72 sites.each {site ->
73 //site = sites[0]
74 println "site: ${site}"
75 xml = new groovy.util.XmlSlurper().parse(site)
76
56e2b05b » bherrmann7 2008-11-23 Bump max to 6. 77 int max = 6;
9615b941 » Bob Herrmann 2008-11-10 adding in pget.groovy 78
79 def xmlenclosures = xml.depthFirst().findAll { it.name().equals("enclosure") }
80 println " has ${xmlenclosures.size()} enclosures"
81 xmlenclosures.each {enclosure ->
82 //println "enclosure " + enclosure.@url + " or " + enclosure.@url.toString()
83
84 url = enclosure.@url.toString()
85 filename = url.toString().substring(url.toString().lastIndexOf('/') + 1);
86 //println "$filename of $url"
87
88 if (max-- > 0) {
89 if (histmap[filename]) {
90 println "already have $filename"
91 // prevend downloading past 'areadly have'
92 max = 0;
93 } else {
f2295299 » bherrmann7 2008-11-13 Users are so demanding. Tr... 94 println "Will get: " + filename + " " + url
9615b941 » Bob Herrmann 2008-11-10 adding in pget.groovy 95 enclosures[url] = filename
96 }
97
98 }
99 }
100 }
101
102 println "\nstarting downloads... will get " + enclosures.size() + " files"
103
104 errors = 0;
105
106 enclosures.each {url, filename ->
107 println "downloading: " + filename + " " + url
28f25a0c » bherrmann7 2008-11-13 Make the download location ... 108 ondiskname = String.format(downloadLocation, downloadHistory.size(), filename)
9615b941 » Bob Herrmann 2008-11-10 adding in pget.groovy 109
110 file = new File(ondiskname)
111 file.parentFile.mkdir()
112
113 if (file.exists()) {
114 println "**** ALREADY DOWNLOADED: ${url}"
115 } else {
116 def fileOut = new FileOutputStream(file)
117 def out = new BufferedOutputStream(fileOut)
118 out << new URL(url).openStream()
119 out.close()
734a1e40 » bherrmann7 2009-02-02 120
3afaa37b » Bob Herrmann 2009-03-23 updated podcasts 121 [ "/usr/bin/id3v2", "-t", '_' + file.name, ondiskname ].execute()
9615b941 » Bob Herrmann 2008-11-10 adding in pget.groovy 122 }
123 println "ok have downloadHistory[$filename]=$ondiskname"
124
125 odnf = new File(ondiskname);
126 downloadHistory << [filename, odnf.name]
127 }
128
129 // saved new items
130 downloadHistoryFile.withPrintWriter {pw ->
131 pw.println("def history = [ ")
132 downloadHistory.each {
133 pw.println " [ '${it[0]}', '${it[1]}' ],"
134 }
135 pw.println("]")
136 }
137
3afaa37b » Bob Herrmann 2009-03-23 updated podcasts 138 println "all done, cache:" + downloadHistory.size() + ", added:" + enclosures.size() + ", errors:" + errors