|
|
|
@ -1,14 +1,19 @@
|
|
|
|
|
import subprocess
|
|
|
|
|
import yt_dlp
|
|
|
|
|
import boto3
|
|
|
|
|
from urllib.error import HTTPError
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from yt_dlp_stream_to_s3.s3_client import s3
|
|
|
|
|
from botocore.exceptions import ClientError
|
|
|
|
|
from yt_dlp_stream_to_s3.client import s3, create_presigned_url
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def yt_dlp_stream_to_s3(url: str, s3_extra_args: dict = ()) -> None:
|
|
|
|
|
def yt_dlp_stream_to_s3(
|
|
|
|
|
url: str,
|
|
|
|
|
expiration=86400 * 7, # 7 days
|
|
|
|
|
s3_extra_args: dict = (),
|
|
|
|
|
) -> None:
|
|
|
|
|
media_url = remove_queries_from_url(url)
|
|
|
|
|
|
|
|
|
|
ydl_opts = {
|
|
|
|
@ -47,6 +52,8 @@ def yt_dlp_stream_to_s3(url: str, s3_extra_args: dict = ()) -> None:
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
yt_dlp_process.wait()
|
|
|
|
|
|
|
|
|
|
return create_presigned_url(AWS_S3_BUCKET_NAME, filename, expiration)
|
|
|
|
|
except HTTPError:
|
|
|
|
|
raise YtDlpStreamToS3Error("Could not connect to the media resource.")
|
|
|
|
|
|
|
|
|
@ -55,3 +62,6 @@ def yt_dlp_stream_to_s3(url: str, s3_extra_args: dict = ()) -> None:
|
|
|
|
|
|
|
|
|
|
except yt_dlp.utils.DownloadError:
|
|
|
|
|
raise YtDlpStreamToS3Error("Could not download media. Check logs.")
|
|
|
|
|
|
|
|
|
|
except ClientError:
|
|
|
|
|
raise YtDlpStreamToS3Error("Error communicating with the S3 service.")
|
|
|
|
|