Skip to content

add ¤

Generic command to add downloads.

Functions:

  • add

    Add magnet subcommand.

add ¤

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

Add magnet subcommand.

Parameters:

  • api (API) –

    The API instance to use.

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

    The URIs or file-paths to add.

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

    Path to the file to read uris from. Deprecated: Every URI that is a valid file-path and is not a torrent or a metalink is now read as an input file.

  • 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 ) –

    0 if OK else 1.

Source code in src/aria2p/cli/commands/add.py
14
15
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
52
53
54
55
56
57
def add(
    api: API,
    uris: list[str] | None = None,
    from_file: str | None = None,
    options: dict | None = None,
    position: int | None = None,
) -> int:
    """Add magnet subcommand.

    Parameters:
        api: The API instance to use.
        uris: The URIs or file-paths to add.
        from_file: Path to the file to read uris from.
            Deprecated: Every URI that is a valid file-path
            and is not a torrent or a metalink is now read as an input file.
        options: String of aria2c options to add to download.
        position: Position to add new download in the queue.

    Returns:
        int: 0 if OK else 1.
    """
    uris = uris or []

    if from_file:
        logger.warning(
            "Deprecation warning: every URI that is a valid file-path "
            "and is not a torrent or a metalink is now read as an input file.",
        )

    new_downloads = []

    for uri in uris:
        created_downloads = api.add(uri, options=options, position=position)
        new_downloads.extend(created_downloads)
        if position is not None:
            position += len(created_downloads)

    if new_downloads:
        for new_download in new_downloads:
            print(f"Created download {new_download.gid}")
        return 0

    print("No new download was created", file=sys.stderr)
    return 1