Skip to main content
Glama

download_torrent_file

Download torrent files from YggTorrent using a specific torrent ID and save them to a designated output directory for programmatic access and management.

Instructions

Download the torrent file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
output_dirYes
torrent_idYes

Implementation Reference

  • MCP tool handler and registration for 'download_torrent_file'. Delegates to YggTorrentApi implementation.
    @mcp.tool() def download_torrent_file( torrent_id: int, output_dir: str, ) -> str | None: """Download the torrent file from YggTorrent for a specific torrent by id.""" logger.info(f"Downloading torrent file for torrent: {torrent_id}") return ygg_api.download_torrent_file(torrent_id, output_dir)
  • Core implementation of downloading the torrent file: fetches bytes, edits, saves to output_dir, returns filename.
    def download_torrent_file( self, torrent_id: int, output_dir: str | Path = "." ) -> str | None: """ Download the .torrent file. Args: torrent_id: The ID of the torrent. Returns: The filename of the downloaded .torrent file or None. """ try: file_bytes = self._download_torrent_file_bytes(torrent_id) if file_bytes and isinstance(file_bytes, bytes): file_bytes = edit_torrent_bytes(file_bytes) filename = f"{torrent_id}.torrent" with open(Path(output_dir) / filename, "wb") as f: f.write(file_bytes) return filename except Exception as e: print(f"Error: {e}") print("Failed to download torrent file") return None
  • Low-level HTTP request to download torrent file bytes from YggTorrent API.
    def _download_torrent_file_bytes( self, torrent_id: int ) -> bytes | dict[str, Any] | None: """ Download the .torrent file. Corresponds to GET /torrent/{torrent_id}/download Args: torrent_id: The ID of the torrent. Returns: The .torrent file content as bytes or an error dictionary. """ if torrent_id < 1: print("torrent_id must be >= 1") return None params = { "passkey": DUMMY_PASSKEY, "tracker_domain": "tracker.p2p-world.net", # will also add "connect.maxp2p.org" later } return self._request("GET", f"torrent/{torrent_id}/download", params=params) # type: ignore

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/philogicae/ygg-torrent-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server