diff --git a/README.md b/README.md index 6c28bab..6a94ba1 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,13 @@ documentations lives at `http://127.0.0.1:1984/docs`. "download_media_type": "AUDIO_VIDEO", "save_to_storage": false, "custom_filename": "cool.mp4", - "automatic_extension": false + "automatic_extension": false, + "custom_options": { + "http_headers": { + "User-Agent": "MyApp/1.0.0", + "Authorization": "Bearer " + } + } } ``` Response diff --git a/app_api/api/api/api_v1/schemas/task.py b/app_api/api/api/api_v1/schemas/task.py index 5bf8989..a48d88c 100644 --- a/app_api/api/api/api_v1/schemas/task.py +++ b/app_api/api/api/api_v1/schemas/task.py @@ -59,7 +59,7 @@ class CreateTaskIn(StrictRealBaseModel): save_to_storage: bool = ... custom_filename: str = ... automatic_extension: bool = ... - + custom_options: dict | None = Field(None, strict=False) class CreateTaskOut(StrictRealBaseModel): id: uuid.UUID diff --git a/app_api/api/core/services/task.py b/app_api/api/core/services/task.py index 84a72cb..c476a4a 100644 --- a/app_api/api/core/services/task.py +++ b/app_api/api/core/services/task.py @@ -81,6 +81,7 @@ class TaskService: ack_message_id=None, custom_filename=task.custom_filename, automatic_extension=task.automatic_extension, + custom_options=task.custom_options, ) if not await publisher.send_for_download(payload): raise TaskServiceError('Failed to create task') diff --git a/app_bot/bot/core/service.py b/app_bot/bot/core/service.py index 304d886..baa665b 100644 --- a/app_bot/bot/core/service.py +++ b/app_bot/bot/core/service.py @@ -37,6 +37,7 @@ class UrlService: download_media_type=url.download_media_type, custom_filename=None, automatic_extension=False, + custom_options=None, ) is_sent = await self._rmq_publisher.send_for_download(payload) if not is_sent: diff --git a/app_worker/worker/core/downloader.py b/app_worker/worker/core/downloader.py index 8d1ccec..b24b095 100644 --- a/app_worker/worker/core/downloader.py +++ b/app_worker/worker/core/downloader.py @@ -60,6 +60,13 @@ class MediaDownloader: media_type=media_type, curr_tmp_dir=curr_tmp_dir ) + if media_payload.custom_options: + for key, value in media_payload.custom_options.items(): + try: + ytdl_opts_model.ytdl_opts[key].update(value) + except KeyError: + ytdl_opts_model.ytdl_opts[key] = value + with yt_dlp.YoutubeDL(ytdl_opts_model.ytdl_opts) as ytdl: self._log.info('Downloading "%s" to "%s"', url, curr_tmp_dir) self._log.info( diff --git a/yt_shared/yt_shared/schemas/media.py b/yt_shared/yt_shared/schemas/media.py index fc478e9..c7822cc 100644 --- a/yt_shared/yt_shared/schemas/media.py +++ b/yt_shared/yt_shared/schemas/media.py @@ -37,6 +37,7 @@ class InbMediaPayload(StrictRealBaseModel): download_media_type: DownMediaType custom_filename: str | None automatic_extension: bool + custom_options: dict[str, dict] | None added_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))