Skip to content Skip to sidebar Skip to footer

How Do I Capture An Mp3 Stream With Python

What's the best way of capturing an mp3 stream coming off of http and saving it to disk with python? Thus far I've tried target = open(target_path, 'w') conn = urllib.urlopen(strea

Solution 1:

If you're on Windows, you might accidentally be doing CRLF conversions, corrupting the binary data. Try opening target in binary mode:

target = open(target_path, "wb")

Solution 2:

The best way for this is:

urllib.urlretrieve(stream_url, target_path);

Solution 3:

Perhaps the syntax changed from the previous urllib answer (that got me to the correct answer btw), but this syntax works for python3:

import urllib.request

urllib.request.urlretrieve(stream_url, target_path)

Post a Comment for "How Do I Capture An Mp3 Stream With Python"