This is a short script I threw together this morning to capture shows for myself.
#!/usr/bin/python
"""
streamdownloader.py
Script for downloading streaming mp3 files from internet radio sites for
a specified amount of time. Intended to be useful as something run from cron
and record your favourite shows. Have a lot of fun!
Usage: $ ./streamdownloader.py <stream> <output filename> <length in minutes>
Example: $ ./streamdownloader.py http://trentradio.ca:8800/hi-fi.ogg trent.ogg 60
Chad Mounteny
readability@gmail.com
September 2009
Should work great for Linux, have no idea otherwise.
"""
import urllib
import time
import sys
def main():
while now() - length < start:
data = conn.read(100)
target.write(data)
def now():
return int(time.time())
stream = sys.argv[1]
dest = sys.argv[2]
length = int(sys.argv[3])*60
start = now()
conn = urllib.urlopen(stream)
target = open(dest, 'wb')
if __name__ == "__main__":
main()
0 comments:
Post a Comment