Files
alfred/agent/tools/api.py
Francwa 2c8cdd3ab1 New archi: domain driven development
Working but need to check out code
2025-12-01 07:10:03 +01:00

88 lines
2.4 KiB
Python

"""API tools for interacting with external services - Adapted for DDD architecture."""
from typing import Dict, Any
# Import use cases instead of direct API clients
from application.movies import SearchMovieUseCase
from application.torrents import SearchTorrentsUseCase, AddTorrentUseCase
# Import infrastructure clients
from infrastructure.api.tmdb import tmdb_client
from infrastructure.api.knaben import knaben_client
from infrastructure.api.qbittorrent import qbittorrent_client
def find_media_imdb_id(media_title: str) -> Dict[str, Any]:
"""
Find the IMDb ID for a given media title using TMDB API.
This is a wrapper that uses the SearchMovieUseCase.
Args:
media_title: Title of the media to search for
Returns:
Dict with IMDb ID or error information
Example:
>>> result = find_media_imdb_id("Inception")
>>> print(result)
{'status': 'ok', 'imdb_id': 'tt1375666', 'title': 'Inception', ...}
"""
# Create use case with TMDB client
use_case = SearchMovieUseCase(tmdb_client)
# Execute use case
response = use_case.execute(media_title)
# Return as dict
return response.to_dict()
def find_torrent(media_title: str) -> Dict[str, Any]:
"""
Find torrents for a given media title using Knaben API.
This is a wrapper that uses the SearchTorrentsUseCase.
Args:
media_title: Title of the media to search for
Returns:
Dict with torrent information or error details
"""
# Create use case with Knaben client
use_case = SearchTorrentsUseCase(knaben_client)
# Execute use case
response = use_case.execute(media_title, limit=10)
# Return as dict
return response.to_dict()
def add_torrent_to_qbittorrent(magnet_link: str) -> Dict[str, Any]:
"""
Add a torrent to qBittorrent using a magnet link.
This is a wrapper that uses the AddTorrentUseCase.
Args:
magnet_link: Magnet link of the torrent to add
Returns:
Dict with success or error information
Example:
>>> result = add_torrent_to_qbittorrent("magnet:?xt=urn:btih:...")
>>> print(result)
{'status': 'ok', 'message': 'Torrent added successfully'}
"""
# Create use case with qBittorrent client
use_case = AddTorrentUseCase(qbittorrent_client)
# Execute use case
response = use_case.execute(magnet_link)
# Return as dict
return response.to_dict()