]>
code.delx.au - monosys/blob - ripping/grab-abc-stream
12 def exec_subprocess(cmd
):
14 p
= subprocess
.Popen(cmd
)
17 print >>sys
.stderr
, cmd
[0], "exited with error code:", ret
22 print >>sys
.stderr
, "Failed to run", cmd
[0], e
23 except KeyboardInterrupt:
24 print "Cancelled", cmd
28 except KeyboardInterrupt:
29 p
.send_signal(signal
.SIGKILL
)
33 def mplayer_convert(stream
, author
, title
):
34 print "Downloading", stream
35 wmfile
= tempfile
.NamedTemporaryFile()
41 "pcm:file=" + wmfile
.name
,
44 if not exec_subprocess(cmd
):
47 print "Converting", wmfile
.name
, "to mp3"
54 os
.path
.splitext(os
.path
.basename(stream
))[0] + ".mp3",
56 if not exec_subprocess(cmd
):
63 qs
= urlparse
.parse_qs(urlparse
.urlparse(u
).query
)
65 doc
= etree
.parse(urllib
.urlopen(wmfile
))
66 streams
= doc
.xpath("//ref/@href")
71 for stream
in streams
:
72 if not stream
.startswith("mms://"):
74 if mplayer_convert(stream
, author
, title
):
77 print "Paste 'Listen Now' URLs from ABC... Press CTRL-D to finish"
79 for line
in sys
.stdin
:
83 except KeyboardInterrupt: