mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-12 15:50:01 -08:00
48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
import click
|
|
from viu_cli.core.config import AppConfig
|
|
|
|
|
|
@click.command(help="Run the background worker for notifications and downloads.")
|
|
@click.pass_obj
|
|
def worker(config: AppConfig):
|
|
"""
|
|
Starts the long-running background worker process.
|
|
This process will periodically check for AniList notifications and
|
|
process any queued downloads. It's recommended to run this in the
|
|
background (e.g., 'viu worker &') or as a system service.
|
|
"""
|
|
from viu_cli.cli.service.auth import AuthService
|
|
from viu_cli.cli.service.download.service import DownloadService
|
|
from viu_cli.cli.service.feedback import FeedbackService
|
|
from viu_cli.cli.service.notification.service import NotificationService
|
|
from viu_cli.cli.service.registry.service import MediaRegistryService
|
|
from viu_cli.cli.service.worker.service import BackgroundWorkerService
|
|
from viu_cli.libs.media_api.api import create_api_client
|
|
from viu_cli.libs.provider.anime.provider import create_provider
|
|
|
|
feedback = FeedbackService(config)
|
|
if not config.worker.enabled:
|
|
feedback.warning("Worker is disabled in the configuration. Exiting.")
|
|
return
|
|
|
|
# Instantiate services
|
|
media_api = create_api_client(config.general.media_api, config)
|
|
# Authenticate if credentials exist (enables notifications)
|
|
auth = AuthService(config.general.media_api)
|
|
if profile := auth.get_auth():
|
|
try:
|
|
media_api.authenticate(profile.token)
|
|
except Exception:
|
|
pass
|
|
provider = create_provider(config.general.provider)
|
|
registry = MediaRegistryService(config.general.media_api, config.media_registry)
|
|
|
|
notification_service = NotificationService(config, media_api, registry)
|
|
download_service = DownloadService(config, registry, media_api, provider)
|
|
worker_service = BackgroundWorkerService(
|
|
config.worker, notification_service, download_service
|
|
)
|
|
|
|
feedback.info("Starting background worker...", "Press Ctrl+C to stop.")
|
|
worker_service.run()
|