Добавил новые ЭП для новой версии загрузки видео с YouTube
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
from abc import ABC, abstractmethod
|
||||
from urllib.parse import quote
|
||||
|
||||
import boto3
|
||||
from botocore.client import Config
|
||||
@@ -180,9 +181,10 @@ class S3UploadBackend(UploadBackend):
|
||||
self.key_prefix = key_prefix
|
||||
|
||||
def upload(self, name: str, file: bytes | str):
|
||||
response = self.s3.upload_file(
|
||||
Filename=file,
|
||||
Bucket=self.bucket,
|
||||
Key=f"{self.key_prefix}{name}",
|
||||
)
|
||||
return response["Location"]
|
||||
key = f"{self.key_prefix}{name}"
|
||||
if isinstance(file, str):
|
||||
self.s3.upload_file(Filename=file, Bucket=self.bucket, Key=key)
|
||||
else:
|
||||
self.s3.put_object(Bucket=self.bucket, Key=key, Body=file)
|
||||
encoded_key = quote(key, "")
|
||||
return f"{settings.S3_ENDPOINT_URL}/{self.bucket}/{encoded_key}"
|
||||
|
||||
@@ -66,20 +66,20 @@ class YtDlpManager:
|
||||
return MediaInfo(f, f.get("format_id"))
|
||||
return None
|
||||
|
||||
def download(self, video_id: str | None = None, audio_id: str | None = None):
|
||||
if video_id is None and audio_id is None:
|
||||
def download(self, video: MediaInfo | None = None, audio: MediaInfo | None = None):
|
||||
if video is None and audio is None:
|
||||
format_id = self.info.get(
|
||||
"format_id",
|
||||
)
|
||||
else:
|
||||
format_id = "" + str(video_id) if video_id is not None else ""
|
||||
if audio_id is not None:
|
||||
format_id = "" + str(video.id) if video is not None else ""
|
||||
if audio is not None:
|
||||
if len(format_id) > 0:
|
||||
format_id += "+"
|
||||
format_id += str(audio_id)
|
||||
format_id += str(audio.id)
|
||||
|
||||
ydl_opts = {
|
||||
"format": f"{video_id}+{audio_id}",
|
||||
"format": f"{format_id}",
|
||||
"merge_output_format": "mp4",
|
||||
"outtmpl": f"{settings.MEDIA_DIR}/%(title)s.%(ext)s",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user