| @@ -9,14 +9,19 @@ | ||
| 9 | 9 | import os |
| 10 | 10 | import shutil |
| 11 | 11 | import sys |
| 12 | import urllib | |
| 12 | import urllib2 | |
| 13 | 13 | from xml.dom import minidom |
| 14 | 14 | |
| 15 | 15 | IPOD = "/Volumes/IPOD" |
| 16 | 16 | CACHE = os.path.expanduser("~/.podgrab") |
| 17 | 17 | SEEN = os.path.join(CACHE, "seen") |
| 18 | UA = "podgrab/0.2 (+http://ttul.org/)" | |
| 18 | 19 | |
| 19 | 20 | |
| 21 | def fetch(url): | |
| 22 | return urllib2.urlopen(urllib2.Request(url, headers={"User-Agent": UA})) | |
| 23 | ||
| 24 | ||
| 20 | 25 | def read_opml(path): |
| 21 | 26 | dom = minidom.parse(path) |
| 22 | 27 | feeds = [] |
| @@ -28,7 +33,7 @@ | ||
| 28 | 33 | |
| 29 | 34 | |
| 30 | 35 | def enclosures(feed_url): |
| 31 | dom = minidom.parse(urllib.urlopen(feed_url)) | |
| 36 | dom = minidom.parse(fetch(feed_url)) | |
| 32 | 37 | for item in dom.getElementsByTagName("item"): |
| 33 | 38 | for enc in item.getElementsByTagName("enclosure"): |
| 34 | 39 | yield enc.getAttribute("url") |
| @@ -61,7 +66,9 @@ | ||
| 61 | 66 | continue |
| 62 | 67 | fname = os.path.join(CACHE, os.path.basename(enc)) |
| 63 | 68 | print " ", enc |
| 64 | urllib.urlretrieve(enc, fname) | |
| 69 | f = open(fname, "wb") | |
| 70 | shutil.copyfileobj(fetch(enc), f) | |
| 71 | f.close() | |
| 65 | 72 | out.write(enc + "\n") |
| 66 | 73 | if os.path.isdir(IPOD): |
| 67 | 74 | # NB: this does not update the iTunesDB. use gtkpod, or |