This commit is contained in:
Pawarit Thong-ek 2024-09-19 22:20:16 +03:00 committed by GitHub
commit 6b110e8342
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 18 additions and 2 deletions

View file

@ -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 <token>"
}
}
}
```
Response

View file

@ -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

View file

@ -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')

View file

@ -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:

View file

@ -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(

View file

@ -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))