dtorrent_parser 1.0.8 copy "dtorrent_parser: ^1.0.8" to clipboard
dtorrent_parser: ^1.0.8 copied to clipboard

A Dart library for parsing .torrent file to Torrent model/saving Torrent model to .torrent file.

example/dtorrent_parser_example.dart

import 'dart:io';

import 'package:dtorrent_parser/dtorrent_parser.dart';
import 'package:path/path.dart' as path;

var scriptDir = path.dirname(Platform.script.path);
var torrentsPath =
    path.canonicalize(path.join(scriptDir, '..', '..', '..', 'torrents'));
void main() async {
  readAndSave(path.join(torrentsPath, 'big-buck-bunny.torrent'),
      path.join(scriptDir, '..', 'tmp', 'big-buck-bunny.torrent'));
  readAndSave(path.join(torrentsPath, 'sintel.torrent'),
      path.join(scriptDir, '..', 'tmp', 'sintel.torrent'));
}

void readAndSave(String path, String newPath) async {
  var result = await Torrent.parse(path);
  printModelInfo(result);
  var newFile = await result.saveAs(newPath, true);
  var result2 = await Torrent.parse(newFile.path);
  printModelInfo(result2);
}

void printModelInfo(Torrent model) {
  print('${model.filePath} Info Hash : ${model.infoHash}');
  print('${model.filePath} announces :');
  for (var announce in model.announces) {
    print('$announce');
  }
  print('DHT nodes:');
  for (var element in model.nodes) {
    print(element);
  }

  print('${model.filePath} files :');
  for (var file in model.files) {
    print('$file');
  }
}
1
likes
160
pub points
71%
popularity

Publisher

unverified uploader

A Dart library for parsing .torrent file to Torrent model/saving Torrent model to .torrent file.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

b_encode_decode, crypto

More

Packages that depend on dtorrent_parser