|
|
|
@ -1,9 +1,9 @@
|
|
|
|
|
import subprocess
|
|
|
|
|
import yt_dlp
|
|
|
|
|
import boto3
|
|
|
|
|
from typing import Dict
|
|
|
|
|
from urllib.error import HTTPError
|
|
|
|
|
from botocore.exceptions import ClientError
|
|
|
|
|
from yt_dlp_stream_to_s3.client import s3, create_presigned_url
|
|
|
|
|
from yt_dlp_stream_to_s3.client import s3_client, create_presigned_url, get_file_size
|
|
|
|
|
from yt_dlp_stream_to_s3.utils import remove_queries_from_url
|
|
|
|
|
from yt_dlp_stream_to_s3.config import AWS_S3_BUCKET_NAME
|
|
|
|
|
from yt_dlp_stream_to_s3.errors import YtDlpStreamToS3Error
|
|
|
|
@ -13,7 +13,7 @@ def yt_dlp_stream_to_s3(
|
|
|
|
|
url: str,
|
|
|
|
|
expiration=86400 * 7, # 7 days
|
|
|
|
|
s3_extra_args: dict = (),
|
|
|
|
|
) -> None:
|
|
|
|
|
) -> Dict[str, str]:
|
|
|
|
|
media_url = remove_queries_from_url(url)
|
|
|
|
|
|
|
|
|
|
ydl_opts = {
|
|
|
|
@ -44,7 +44,7 @@ def yt_dlp_stream_to_s3(
|
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
s3.upload_fileobj(
|
|
|
|
|
s3_client.upload_fileobj(
|
|
|
|
|
yt_dlp_process.stdout,
|
|
|
|
|
AWS_S3_BUCKET_NAME,
|
|
|
|
|
filename,
|
|
|
|
@ -53,7 +53,12 @@ def yt_dlp_stream_to_s3(
|
|
|
|
|
|
|
|
|
|
yt_dlp_process.wait()
|
|
|
|
|
|
|
|
|
|
return create_presigned_url(AWS_S3_BUCKET_NAME, filename, expiration)
|
|
|
|
|
return dict(
|
|
|
|
|
presigned_url=create_presigned_url(
|
|
|
|
|
AWS_S3_BUCKET_NAME, filename, expiration
|
|
|
|
|
),
|
|
|
|
|
filesize=get_file_size(AWS_S3_BUCKET_NAME, filename),
|
|
|
|
|
)
|
|
|
|
|
except HTTPError:
|
|
|
|
|
raise YtDlpStreamToS3Error("Could not connect to the media resource.")
|
|
|
|
|
|
|
|
|
|