Download while simultaneously encoding

This commit is contained in:
Ritiek Malhotra
2020-03-23 18:29:23 +05:30
parent 7413c541d3
commit d154b2be20
4 changed files with 90 additions and 2 deletions

20
spotdl/helpers.py Normal file
View File

@@ -0,0 +1,20 @@
import subprocess
import threading
def download(url, path=".", progress_bar=True, ):
command = ("ffmpeg", "-y", "-i", "-", "output.wav")
content = pytube.YouTube("https://www.youtube.com/watch?v=SE0nYFJ0ZvQ")
stream = content.streams[0]
response = urllib.request.urlopen(stream.url)
process = subprocess.Popen(command, stdin=subprocess.PIPE)
while True:
chunk = response.read(16 * 1024)
if not chunk:
break
process.stdin.write(chunk)
process.stdin.close()