0

I need to convert a MP4 downloaded with the Requests module, into a MP3 with the Moviepy module.

The 2 operations work perfectly.

However, in order to convert the MP4 into MP3 (using the moviepy audio.write_audiofile() method),

I need to save the MP4 onto the disk (using the requests write() method)

which basically is useless since I will delete right after.

Please do you know if there's a method that takes the content downloaded with Requests, and converts it directly into MP3 file?

Thank you in advance!

Bibelo
  • 221
  • 2
  • 8

1 Answers1

0

I am not so familiar with this, but i think you can use io.BytesIO (https://docs.python.org/3/library/io.html#io.BytesIO), with this you can write data (from requets) into a BytesIO-Object instead of a file (you can use it on every file read/write actions instead of a real file). An example:

import io


b = io.BytesIO()
with open("file.dat", "br") as f:
    b.write(f.read())

b.seek(0)

with open("new_file.dat", "bw") as f:
    f.write(b.read())

b.close()
D-E-N
  • 1,242
  • 7
  • 14
  • Thank you, I tried, but the problem is that the moviepy method really requires a filename... – Bibelo Sep 29 '20 at 22:00