Created
October 6, 2012 06:39
-
-
Save flopezluis/3844235 to your computer and use it in GitHub Desktop.
an old script I created to record Vaughan Radio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time as timer | |
import urllib | |
from datetime import datetime, time | |
import signal | |
name = '' | |
def record(): | |
url_stream = urllib.urlopen("http://vaughanradio.streaming-pro.com:8012/;stream.nsv") | |
f = open("%s_%s.mp3" %(name, datetime.now().strftime("%y-%m-%d")),"wb"); | |
print ('Recording...') | |
while 1: | |
f.write(url_stream.read(1)) #It'd better to read bigger chunks | |
def timeout_handler(signum, frame): | |
print ('Finished.') | |
exit(0) | |
if __name__ == '__main__': | |
if len(sys.argv) < 4: | |
print "Usage: python record.py time_to_start time_to_finish file_name" | |
start = time(*[int(x) for x in sys.argv[1].split(":")]) | |
finish = time(*[int(x) for x in sys.argv[2].split(":")]) | |
name = sys.argv[3] | |
delta_finish = datetime.combine(datetime.today(), finish) - datetime.combine(datetime.today(), start) | |
delta_start = datetime.combine(datetime.today(), start) - datetime.today() | |
signal.signal(signal.SIGALRM, timeout_handler) | |
signal.alarm(delta_start.seconds+delta_finish.seconds) | |
print ('Waiting...') | |
timer.sleep(delta_start.seconds) | |
record() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment