Skip to content

add_torrent ¤

Command to add torrents.

Functions:

add_torrents ¤

add_torrents(
    api: API,
    torrent_files: list[str | Path] | None = None,
    from_file: str | Path | None = None,
    options: dict | None = None,
    position: int | None = None,
) -> int

Add torrent subcommand.

Parameters:

  • api (API) –

    The API instance to use.

  • torrent_files (list[str | Path] | None, default: None ) –

    The paths to the torrent files.

  • from_file (str | Path | None, default: None ) –

    Path to the file to read torrent files paths from.

  • options (dict | None, default: None ) –

    String of aria2c options to add to download.

  • position (int | None, default: None ) –

    Position to add new download in the queue.

Returns:

  • int ( int ) –

    Always 0.

Source code in src/aria2p/cli/commands/add_torrent.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def add_torrents(
    api: API,
    torrent_files: list[str | Path] | None = None,
    from_file: str | Path | None = None,
    options: dict | None = None,
    position: int | None = None,
) -> int:
    """Add torrent subcommand.

    Parameters:
        api: The API instance to use.
        torrent_files: The paths to the torrent files.
        from_file: Path to the file to read torrent files paths from.
        options: String of aria2c options to add to download.
        position: Position to add new download in the queue.

    Returns:
        int: Always 0.
    """
    ok = True

    if not torrent_files:
        torrent_files = []

    if from_file:
        try:
            torrent_files.extend(read_lines(from_file))
        except OSError:
            print(f"Cannot open file: {from_file}", file=sys.stderr)
            ok = False

    for torrent_file in torrent_files:
        new_download = api.add_torrent(torrent_file, options=options, position=position)
        print(f"Created download {new_download.gid}")

    return 0 if ok else 1