ElixirTorrent (elixir_torrent v0.1.2)

Copy Markdown View Source

Public API for controlling torrent downloads.

This is the entrypoint you should use from other applications. Start a download with download/1 and poll stats with stats/2.

Public functions

  • main/1 - starts the CLI loop used by the escript
  • version/0 - returns this client's peer ID/version string
  • download/1 - starts downloading a .torrent from disk
  • stats/2 - fetches selected runtime stats for a torrent
  • get/2 - low-level raw getter kept for compatibility
  • list_files/1 - lists files with per-file download progress
  • remove/2 - stops a torrent and optionally deletes its data

Summary

Types

Per-file progress entry returned by list_files/1.

20-byte torrent info hash.

Functions

Starts downloading a .torrent file from the given local path.

Low-level getter that proxies to the internal torrent model getter through the torrent pid.

Lists files in a torrent with per-file download progress.

Starts the CLI loop used by the escript entrypoint.

Stops a torrent and removes it from the active session.

Returns selected runtime stats for a running torrent process.

Returns the peer ID/version string advertised by this client.

Types

file_entry()

@type file_entry() :: %{
  index: non_neg_integer(),
  path: String.t(),
  name: String.t(),
  length: non_neg_integer(),
  downloaded: non_neg_integer(),
  progress: float(),
  complete?: boolean()
}

Per-file progress entry returned by list_files/1.

Keys: :index, :path, :name, :length, :downloaded, :progress, :complete?.

info_hash()

@type info_hash() :: binary()

20-byte torrent info hash.

Functions

download(path)

Starts downloading a .torrent file from the given local path.

Returns the same value as Torrents.download/1: {:ok, pid} on success or {:error, reason}.

Example:

{:ok, pid} = ElixirTorrent.download("/tmp/file.torrent")

get(pid, args \\ [])

@spec get(pid(), atom() | [atom()]) :: any()

Low-level getter that proxies to the internal torrent model getter through the torrent pid.

Prefer stats/2 when you need runtime statistics as a map.

list_files(hash)

@spec list_files(info_hash()) :: [file_entry()]

Lists files in a torrent with per-file download progress.

See file_entry/0 for the shape of each returned entry.

main(_)

Starts the CLI loop used by the escript entrypoint.

remove(hash, opts \\ [])

@spec remove(
  info_hash(),
  keyword()
) :: :ok | {:error, term()}

Stops a torrent and removes it from the active session.

Pass delete_data: true to also delete downloaded files from disk.

stats(pid, fields \\ [:name, :speed, :downloaded, :bytes_size])

@spec stats(pid(), [atom()]) :: {:ok, map()} | {:error, :torrent_not_found}

Returns selected runtime stats for a running torrent process.

By default it returns: :name, :speed, :downloaded, :bytes_size.

You can request custom fields, for example:

ElixirTorrent.stats(pid, [:name, :speed, :downloaded, :bytes_size])

Result shape:

{:ok,
 %{
   name: "ubuntu.iso",
   speed: %{download: 1200, upload: 80},
   downloaded: 1048576,
   bytes_size: 4294967296
 }}

version()

Returns the peer ID/version string advertised by this client.