yt-dlp-bot/bot/core/service.py

22 lines
790 B
Python
Raw Normal View History

2022-02-04 06:21:27 +08:00
import logging
from yt_shared.constants import TaskSource
from yt_shared.rabbit.publisher import Publisher
from yt_shared.schemas.video import VideoPayload
2022-06-11 04:35:48 +08:00
class URLService:
2022-02-04 06:21:27 +08:00
def __init__(self) -> None:
self._log = logging.getLogger(self.__class__.__name__)
self._publisher = Publisher()
2022-06-11 04:35:48 +08:00
async def process_url(self, url: str, message_id: int) -> bool:
2022-02-04 06:21:27 +08:00
return await self._send_to_worker(url, message_id)
async def _send_to_worker(self, url: str, message_id: int) -> bool:
2022-06-11 04:35:48 +08:00
payload = VideoPayload(url=url, message_id=message_id, source=TaskSource.BOT)
2022-02-04 06:21:27 +08:00
is_sent = await self._publisher.send_for_download(payload)
if not is_sent:
self._log.error('Failed to publish URL %s to message broker', url)
return is_sent