Skip to content

Display the total downloads/completed downloads of a torrent #671

@josecelano

Description

@josecelano

Discussed in #521

Originally posted by josecelano April 11, 2024
Proposed on: #519 by @ty5e3a45.

Currently, we only show the number of seeders and leechers for a torrent.

The Index API endpoint does not contain that info:

{
    "data": {
        "torrent_id": 987,
        "uploader": "admin",
        "info_hash": "a158dcb05854578f37f4fc79ef2206547143a0f5",
        "title": "title-e2fc03f9-f7be-4b4c-aa9d-65da0cedbed4",
        "description": "description-e2fc03f9-f7be-4b4c-aa9d-65da0cedbed4",
        "category": {
            "id": 6,
            "category_id": 6,
            "name": "test",
            "num_torrents": 1000
        },
        "upload_date": "2024-03-13 09:49:25",
        "file_size": 37,
        "seeders": 0,
        "leechers": 0,
        "files": [
            {
                "path": [
                    "file-e2fc03f9-f7be-4b4c-aa9d-65da0cedbed4.txt"
                ],
                "length": 37,
                "md5sum": null
            }
        ],
        "trackers": [
            "udp://localhost:6969"
        ],
        "magnet_link": "magnet:?xt=urn:btih:a158dcb05854578f37f4fc79ef2206547143a0f5&dn=title-e2fc03f9-f7be-4b4c-aa9d-65da0cedbed4&tr=udp%3A%2F%2Flocalhost%3A6969",
        "tags": [],
        "name": "file-e2fc03f9-f7be-4b4c-aa9d-65da0cedbed4.txt",
        "comment": null,
        "creation_date": null,
        "created_by": null,
        "encoding": null,
        "canonical_info_hash_group": [
            "a158dcb05854578f37f4fc79ef2206547143a0f5"
        ]
    }
}

It only contains the number of seeders and leechers. It does not contain the number of complete downloads because the Index does not have that number now. The Index imports that info from the tracker and stores the stats in this table:

CREATE TABLE "torrust_torrent_tracker_stats" (
	"torrent_id"	INTEGER NOT NULL,
	"tracker_url"	VARCHAR(256) NOT NULL,
	"seeders"	INTEGER NOT NULL DEFAULT 0,
	"leechers"	INTEGER NOT NULL DEFAULT 0,
	"updated_at"	TEXT DEFAULT 1000-01-01 00:00:00,
	FOREIGN KEY("torrent_id") REFERENCES "torrust_torrents"("torrent_id") ON DELETE CASCADE,
	UNIQUE("torrent_id","tracker_url"),
	PRIMARY KEY("torrent_id")
);

There is a background task to import statistics from the tracker that uses this tracker endpoint:

http://localhost:1212/api/v1/torrents?infohash=9c38422213e30bff212b30c360d26f9a02136422&token=MyAccessToken

[
  {
    "info_hash": "9c38422213e30bff212b30c360d26f9a02136422",
    "seeders": 1,
    "completed": 0,
    "leechers": 0
  }
]

In order to implement this feature we need to:

Screenshot

image

I'll open the issues because it's a good first issue for new contributors.

Subtasks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions