Добавил возможность загружать файлы сразу в S3
This commit is contained in:
@@ -46,25 +46,38 @@ class YtDlpManager:
|
||||
"--no-warnings",
|
||||
"-o",
|
||||
"-",
|
||||
self.url
|
||||
self.url,
|
||||
]
|
||||
print("Start processing")
|
||||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, bufsize=0)
|
||||
print("Write filename to upload backend")
|
||||
self.backend.start(self.title + ".mp4")
|
||||
print("Start write chunk to upload backend")
|
||||
chunk_size = 1024 ** 2
|
||||
return self._processing(command, self.title + ".mp4")
|
||||
|
||||
def download_audio(self):
|
||||
command = [
|
||||
"yt-dlp",
|
||||
"-f",
|
||||
"bestaudio",
|
||||
"--no-part",
|
||||
"--quiet",
|
||||
"--no-warnings",
|
||||
"-o",
|
||||
"-",
|
||||
self.url,
|
||||
]
|
||||
return self._processing(command, self.title + ".m4a")
|
||||
|
||||
def _processing(self, command: list[str], filename: str, chunk_size: int = 1024**2):
|
||||
process = subprocess.Popen(
|
||||
command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, bufsize=0
|
||||
)
|
||||
self.backend.start(filename)
|
||||
length = 0
|
||||
while True:
|
||||
chunk = process.stdout.read(chunk_size)
|
||||
if not chunk:
|
||||
break
|
||||
length += chunk_size
|
||||
print("Write chunk to backend", length)
|
||||
self.backend.upload_chunk(chunk)
|
||||
print("End writing to backend")
|
||||
ret = process.wait()
|
||||
print("Check ret status")
|
||||
if ret != 0:
|
||||
self.backend.abort()
|
||||
raise RuntimeError(f"yt-dlp failed, status code: {ret}")
|
||||
return self.backend.finish()
|
||||
|
||||
Reference in New Issue
Block a user