runtime.py 2.14 KB
from __future__ import annotations

from services.crawler.application import (
    MediaCrawlerCommandSpec,
    get_default_mediacrawler_runtime_service,
)

EVENT_PREFIX = "BF_EVENT::"
MAX_LOG_LINES = 300
MEDIACRAWLER_RUNTIME_SERVICE = get_default_mediacrawler_runtime_service()


def build_completed_process_kwargs(*, timeout: int | None = None) -> dict[str, object]:
    return MEDIACRAWLER_RUNTIME_SERVICE.build_completed_process_kwargs(timeout=timeout)


def build_streaming_process_kwargs() -> dict[str, object]:
    return MEDIACRAWLER_RUNTIME_SERVICE.build_streaming_process_kwargs()


def build_login_status_command_spec(
    *,
    platform: str,
    headless: bool,
) -> MediaCrawlerCommandSpec:
    return MEDIACRAWLER_RUNTIME_SERVICE.build_login_status_command_spec(
        platform=platform,
        headless=headless,
    )


def build_login_command_spec(
    *,
    platform: str,
    login_type: str,
    headless: bool,
    cookies: str = "",
    phone: str = "",
) -> MediaCrawlerCommandSpec:
    return MEDIACRAWLER_RUNTIME_SERVICE.build_login_command_spec(
        platform=platform,
        login_type=login_type,
        headless=headless,
        cookies=cookies,
        phone=phone,
    )


def build_crawl_command_spec(
    *,
    platform: str,
    login_type: str,
    crawler_type: str,
    keywords: str,
    specified_ids: str,
    creator_ids: str,
    start_page: int,
    max_notes: int,
    max_comments: int,
    enable_comments: bool,
    enable_sub_comments: bool,
    save_data_option: str | None,
    headless: bool,
    cookies: str = "",
    phone: str = "",
) -> MediaCrawlerCommandSpec:
    return MEDIACRAWLER_RUNTIME_SERVICE.build_crawl_command_spec(
        platform=platform,
        login_type=login_type,
        crawler_type=crawler_type,
        keywords=keywords,
        specified_ids=specified_ids,
        creator_ids=creator_ids,
        start_page=start_page,
        max_notes=max_notes,
        max_comments=max_comments,
        enable_comments=enable_comments,
        enable_sub_comments=enable_sub_comments,
        save_data_option=save_data_option,
        headless=headless,
        cookies=cookies,
        phone=phone,
    )