Improved content type handling

This commit is contained in:
Martin Brodbeck 2013-09-16 15:49:35 +02:00
parent 6d6312f2d6
commit 190a9ec263

View file

@ -41,8 +41,14 @@ def record_worker(stoprec, streamurl, target_dir, name=None):
filename = target_dir + os.sep + datetime.datetime.now().isoformat()
if name:
filename += '_' + name
if(conn.getheader('Content-Type') == 'audio/mpeg'):
content_type = conn.getheader('Content-Type')
if(content_type == 'audio/mpeg'):
filename += '.mp3'
elif(content_type == 'application/ogg' or content_type == 'audio/ogg'):
filename += '.ogg'
else:
print('Unknown content type. Assuming mp3.')
filename += 'mp3'
target = open(filename, "wb")
while(not stoprec.is_set() and not conn.closed):
target.write(conn.read(1024))