torrent_parser 1.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

Utility to parse .torrent files. ci

To parse bencoded data consider using https://pub.dev/packages/torrent_bencode

Standalone executable #

Installation

# install with pub
pub global activate torrent_parser

Usage

tp ./test/multi.torrent

{
  "encoding": "UTF-8",
  "announce": "http://tr.bangumi.moe:6969/announce",
  "created by": "rin-pr/0.5.1",
  "creation date": 1494251524,
  "info": {
    "name": "[Sakurato.sub] [New Game!] [13_OVA] [GB] [720P]",
    "length": null,
    "piece length": 131072,
    "files": [
      {
        "length": 132320705,
        "path": [
          "[Sakurato.sub] [New Game!] [13_OVA] [GB] [720P].mp4"
        ]
      },
      ...
    ],
    "pieces": [
      "a5641ed0f4be619742fd56bc3fe3f4454c5ebed6",
      "37a1f42bf736ea12eb76b0ccb53bf505d3babb15",
      "7b46a960cfd74c491a77a1335462f9311ff6d9ae",
      "ef84bb9f06d96b9bf532134095b311c1ab3e7087",
      "0be60c3fa15f8981186b4931ca6151ad4e39fd96",
      "cba2ca15ed8b110c57f52f0d58767abf73eca3a4",
      "cbfcb848de4ab11db8f375516371c24c2a739320",
      "e22f05de6ec9b31e336bc409f591b8a9ee4fb725",
      ...
    ]
  }
}

Usage #

An example:

import 'package:torrent_parser/torrent_parser.dart';

main() async {
  final parser = await TorrentParser.fromFile('test/multi.torrent');
  // or final parser = TorrentParser.fromString('d8:announce27:http://example.com/announcee');

  final torrent = parser.parse();
  // or final torrent = parser.tryParse();
  // which return null rather than throw an exception on failure

  print(torrent);
  // Output:
  //
  // {
  //   "encoding": "UTF-8",
  //   "announce": "http://tr.bangumi.moe:6969/announce",
  //   "info": {
  //     "length": null,
  //     "name": "[Sakurato.sub] [New Game!] [13_OVA] [GB] [720P]",
  //     "files": [
  //       {
  //         "length": 132320705,
  //         "path": [
  //           "[Sakurato.sub] [New Game!] [13_OVA] [GB] [720P].mp4"
  //         ]
  //       },
  //       ...
  //     ],
  //     "piece length": 131072,
  //     "pieces": [
  //       "a5641ed0f4be619742fd56bc3fe3f4454c5ebed6",
  //       "37a1f42bf736ea12eb76b0ccb53bf505d3babb15",
  //       "cba2ca15ed8b110c57f52f0d58767abf73eca3a4",
  //       "cbfcb848de4ab11db8f375516371c24c2a739320",
  //       ...
  //     ]
  //   },
  //   "announce-list": [
  //     [
  //       "http://tr.bangumi.moe:6969/announce"
  //     ],
  //     [
  //       "http://t.nyaatracker.com/announce"
  //     ],
  //     ...
  //   ],
  //   "created by": "rin-pr/0.5.1",
  //   "creation date": 1494251524
  // }

  print(torrent.announce);
  // Output:
  //
  // http://tr.bangumi.moe:6969/announce

  print(torrent.info.name);
  // Output:
  //
  // [Sakurato.sub] [New Game!] [13_OVA] [GB] [720P]
}

Test #

Run tests with:

pub run test

References #

Features and bugs #

Please file feature requests and bugs at the Github issues.

1.2.0 #

  • add support for announce-list

1.1.1+1 #

  • update README

1.1.1 #

  • add torrent.info.totalLength field

1.1.0 #

  • add infoHash field

1.0.0 #

  • use torrent_parser

0.1.4 #

  • Add executable

0.1.3 #

  • More documentation

0.1.2 #

  • Minor bug fixes

0.1.1 #

  • Minor bug fixes

0.1.0 #

  • Initial version, created by Stagehand

example/torrent_parser_example.dart

import 'package:torrent_parser/torrent_parser.dart';

main() async {
  final parser = await TorrentParser.fromFile('test/multi.torrent');
  print(parser.parse());
}

Use this package as an executable

1. Install it

You can install the package from the command line:


$ pub global activate torrent_parser

2. Use it

The package has the following executables:


$ tp

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  torrent_parser: ^1.2.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:torrent_parser/torrent_parser.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
28
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
62
Learn more about scoring.

We analyzed this package on Dec 12, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4

Health suggestions

Fix bin/parser.dart. (-0.50 points)

Analysis of bin/parser.dart reported 1 hint:

line 35 col 3: Dead code.

Format lib/src/utils.dart.

Run dartfmt to format lib/src/utils.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (json_annotation).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
convert ^2.0.0 2.1.1
crypto ^2.0.0 2.1.4
json_annotation ^2.0.0 2.4.0 3.0.0
path ^1.6.0 1.6.4
torrent_bencode ^0.1.0 0.1.0+1
Transitive dependencies
charcode 1.1.2
collection 1.14.12
typed_data 1.1.6
Dev dependencies
build_runner ^1.0.0
json_serializable ^2.0.0
pedantic ^1.0.0
test ^1.0.0