Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
http からの mp3 ストリームをキャプチャし、python でディスクに保存する最良の方法は何ですか?
これまで私が試した
target = open(target_path, "w") conn = urllib.urlopen(stream_url) while True: target.write(conn.read(buf_size))
これによりデータが得られますが、mp3プレーヤーで文字化けしたり、再生されません。
Windows を使用している場合、誤って CRLF 変換を行って、バイナリ データを破損している可能性があります。targetバイナリモードで開いてみてください:
target
target = open(target_path, "wb")
これに最適な方法は次のとおりです。
urllib.urlretrieve(stream_url, target_path);