Working with TORRENT files

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Metadata MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-metadata -- dnx GroupDocs.Metadata.Mcp --yes
Folders, licensing and more →

In the BitTorrent file distribution system, a torrent file or METAINFO is a computer file that contains metadata about files and folders to be distributed, and usually also a list of the network locations of trackers, which are computers that help participants in the system find each other and form efficient distribution groups called swarms. A torrent file does not contain the content to be distributed; it only contains information about those files, such as their names, sizes, folder structure, and cryptographic hash values for verifying file integrity. 

Note
For more information on torrent files please refer to this article: https://en.wikipedia.org/wiki/Torrent_file

Reading TORRENT file metadata

To get TORRENT file metadata, the following steps are needed to be followed:

  1. Load a TORRENT file
  2. Get the root metadata package
  3. Extract  the native metadata package using TorrentRootPackage.TorrentPackage
  4. Read the TORRENT file properties

AdvancedUsage.ManagingMetadataForSpecificFormats.Peer2Peer.TorrentReadNativeMetadataProperties

using (Metadata metadata = new Metadata(Constants.InputTorrent))
{
	var root = metadata.GetRootPackage<TorrentRootPackage>();

	Console.WriteLine(root.TorrentPackage.Announce);
	Console.WriteLine(root.TorrentPackage.Comment);
	Console.WriteLine(root.TorrentPackage.CreatedBy);
	Console.WriteLine(root.TorrentPackage.CreationDate);

	foreach (var file in root.TorrentPackage.SharedFiles)
	{
		Console.WriteLine(file.Name);
		Console.WriteLine(file.Length);
	}

	// ...
}

Updating TORRENT file metadata

The GroupDocs.Metadata API also supports updating some metadata properties of a TORRENT file. Please see the code snippet below to learn how to do that.

AdvancedUsage.ManagingMetadataForSpecificFormats.Peer2Peer.TorrentReadNativeMetadataProperties

using (Metadata metadata = new Metadata(Constants.InputTorrent))
{
	var root = metadata.GetRootPackage<TorrentRootPackage>();
	Console.WriteLine(root.TorrentPackage.Announce);
	Console.WriteLine(root.TorrentPackage.Comment);
	Console.WriteLine(root.TorrentPackage.CreatedBy);
	Console.WriteLine(root.TorrentPackage.CreationDate);

	foreach (var file in root.TorrentPackage.SharedFiles)
	{
		Console.WriteLine(file.Name);
		Console.WriteLine(file.Length);
	}

	// ...
}

More resources

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document metadata management App

Along with full featured .NET library we provide simple, but powerful free Apps. You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.