{"id":13482026,"url":"https://github.com/webtorrent/parse-torrent","last_synced_at":"2025-05-14T02:06:57.501Z","repository":{"id":14417017,"uuid":"17127972","full_name":"webtorrent/parse-torrent","owner":"webtorrent","description":"Parse a torrent identifier (magnet uri, .torrent file, info hash)","archived":false,"fork":false,"pushed_at":"2025-04-18T20:17:21.000Z","size":282,"stargazers_count":448,"open_issues_count":17,"forks_count":84,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-05-11T16:04:36.443Z","etag":null,"topics":["bittorrent","browser","javascript","magnet-uri","nodejs","parse","torrent","webtorrent"],"latest_commit_sha":null,"homepage":"https://webtorrent.io","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webtorrent.png","metadata":{"funding":{"github":["webtorrent","feross"]},"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-02-24T06:59:10.000Z","updated_at":"2025-04-03T17:20:22.000Z","dependencies_parsed_at":"2023-09-24T05:42:37.617Z","dependency_job_id":"6a200ac4-2ee9-45c3-8b20-04a57f3e79a0","html_url":"https://github.com/webtorrent/parse-torrent","commit_stats":{"total_commits":310,"total_committers":23,"mean_commits":"13.478260869565217","dds":"0.37419354838709673","last_synced_commit":"d3683823f2ce4867e92437ce0c3c2748849caf2c"},"previous_names":["feross/parse-torrent"],"tags_count":97,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webtorrent%2Fparse-torrent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webtorrent%2Fparse-torrent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webtorrent%2Fparse-torrent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webtorrent%2Fparse-torrent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webtorrent","download_url":"https://codeload.github.com/webtorrent/parse-torrent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254052727,"owners_count":22006716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bittorrent","browser","javascript","magnet-uri","nodejs","parse","torrent","webtorrent"],"created_at":"2024-07-31T17:00:58.346Z","updated_at":"2025-05-14T02:06:52.490Z","avatar_url":"https://github.com/webtorrent.png","language":"JavaScript","readme":"# parse-torrent [![ci][ci-image]][ci-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]\n\n[ci-image]: https://img.shields.io/github/actions/workflow/status/webtorrent/parse-torrent/ci.yml\n[ci-url]: https://github.com/webtorrent/parse-torrent/actions\n[npm-image]: https://img.shields.io/npm/v/parse-torrent.svg\n[npm-url]: https://npmjs.org/package/parse-torrent\n[downloads-image]: https://img.shields.io/npm/dm/parse-torrent.svg\n[downloads-url]: https://npmjs.org/package/parse-torrent\n[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[standard-url]: https://standardjs.com\n\n### Parse a torrent identifier (magnet uri, .torrent file, info hash)\n\nWorks in node and the browser (with [browserify](http://browserify.org/)). This module is used by [WebTorrent](http://webtorrent.io)!\n\n## install\n\n```\nnpm install parse-torrent\n```\n\n## usage\n\n### parse\n\nThe return value of `parseTorrent` will contain as much info as possible about the\ntorrent. The only property that is guaranteed to be present is `infoHash`.\n\n```js\nimport parseTorrent from 'parse-torrent'\nimport fs from 'fs'\n\n// info hash (as a hex string)\nparseTorrent('d2474e86c95b19b8bcfdb92bc12c9d44667cfa36')\n// { infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' }\n\n// info hash (as a Buffer)\nparseTorrent(new Buffer('d2474e86c95b19b8bcfdb92bc12c9d44667cfa36', 'hex'))\n// { infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' }\n\n// magnet uri (as a utf8 string)\nparseTorrent('magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36')\n// { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36',\n//   infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' }\n\n// magnet uri with torrent name\nparseTorrent('magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36\u0026dn=Leaves%20of%20Grass%20by%20Walt%20Whitman.epub')\n// { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36',\n//   dn: 'Leaves of Grass by Walt Whitman.epub',\n//   infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36',\n//   name: 'Leaves of Grass by Walt Whitman.epub' }\n\n// magnet uri with trackers\nparseTorrent('magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36\u0026tr=http%3A%2F%2Ftracker.example.com%2Fannounce')\n// { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36',\n//   tr: 'http://tracker.example.com/announce',\n//   infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36',\n//   announce: [ 'http://tracker.example.com/announce' ] }\n\n// .torrent file (as a Buffer)\nparseTorrent(fs.readFileSync(__dirname + '/torrents/leaves.torrent'))\n// { info:\n//    { length: 362017,\n//      name: \u003cBuffer 4c 65 61 76 65 73 20 6f 66 20 47 72 61 73 73 20 62 79 20 57 61 6c 74 20 57 68 69 74 6d 61 6e 2e 65 70 75 62\u003e,\n//      'piece length': 16384,\n//      pieces: \u003cBuffer 1f 9c 3f 59 be ec 07 97 15 ec 53 32 4b de 85 69 e4 a0 b4 eb ec 42 30 7d 4c e5 55 7b 5d 39 64 c5 ef 55 d3 54 cf 4a 6e cc 7b f1 bc af 79 d1 1f a5 e0 be 06 ...\u003e },\n//   infoBuffer: \u003cBuffer 64 36 3a 6c 65 6e 67 74 68 69 33 36 32 30 31 37 65 34 3a 6e 61 6d 65 33 36 3a 4c 65 61 76 65 73 20 6f 66 20 47 72 61 73 73 20 62 79 20 57 61 6c 74 20 57 ...\u003e,\n//   infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36',\n//   name: 'Leaves of Grass by Walt Whitman.epub',\n//   private: false,\n//   created: Thu Aug 01 2013 06:27:46 GMT-0700 (PDT),\n//   comment: 'Downloaded from http://TheTorrent.org',\n//   announce:\n//    [ 'http://tracker.example.com/announce' ],\n//   urlList: [],\n//   files:\n//    [ { path: 'Leaves of Grass by Walt Whitman.epub',\n//        name: 'Leaves of Grass by Walt Whitman.epub',\n//        length: 362017,\n//        offset: 0 } ],\n//   length: 362017,\n//   pieceLength: 16384,\n//   lastPieceLength: 1569,\n//   pieces:\n//    [ '1f9c3f59beec079715ec53324bde8569e4a0b4eb',\n//      'ec42307d4ce5557b5d3964c5ef55d354cf4a6ecc',\n//      '7bf1bcaf79d11fa5e0be06593c8faafc0c2ba2cf',\n//      '76d71c5b01526b23007f9e9929beafc5151e6511',\n//      '0931a1b44c21bf1e68b9138f90495e690dbc55f5',\n//      '72e4c2944cbacf26e6b3ae8a7229d88aafa05f61',\n//      'eaae6abf3f07cb6db9677cc6aded4dd3985e4586',\n//      '27567fa7639f065f71b18954304aca6366729e0b',\n//      '4773d77ae80caa96a524804dfe4b9bd3deaef999',\n//      'c9dd51027467519d5eb2561ae2cc01467de5f643',\n//      '0a60bcba24797692efa8770d23df0a830d91cb35',\n//      'b3407a88baa0590dc8c9aa6a120f274367dcd867',\n//      'e88e8338c572a06e3c801b29f519df532b3e76f6',\n//      '70cf6aee53107f3d39378483f69cf80fa568b1ea',\n//      'c53b506159e988d8bc16922d125d77d803d652c3',\n//      'ca3070c16eed9172ab506d20e522ea3f1ab674b3',\n//      'f923d76fe8f44ff32e372c3b376564c6fb5f0dbe',\n//      '52164f03629fd1322636babb2c014b7dae582da4',\n//      '1363965261e6ce12b43701f0a8c9ed1520a70eba',\n//      '004400a267765f6d3dd5c7beb5bd3c75f3df2a54',\n//      '560a61801147fa4ec7cf568e703acb04e5610a4d',\n//      '56dcc242d03293e9446cf5e457d8eb3d9588fd90',\n//      'c698de9b0dad92980906c026d8c1408fa08fe4ec' ] }\n```\n\n### encode\n\nThe reverse works too. To convert an object of keys/value to a magnet uri or .torrent file\nbuffer, use `toMagnetURI` and `toTorrentFile`.\n\n```js\nimport { toMagnetURI, toTorrentFile } from 'parse-torrent'\n\nconst uri = toMagnetURI({\n  infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36'\n})\nconsole.log(uri) // 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36'\n\nconst buf = toTorrentFile({\n  info: {\n    /* ... */\n  }\n})\nconsole.log(buf)\n```\n\n### remote torrents\n\nTo support remote torrent identifiers (i.e. http/https links to .torrent files, or\nfilesystem paths), as well as Blobs use the `parseTorrent.remote` function. It takes\na callback since these torrent types require async operations:\n\n```js\nimport { remote } from 'parse-torrent'\nremote(torrentId, (err, parsedTorrent) =\u003e {\n  if (err) throw err\n  console.log(parsedTorrent)\n})\n```\n\nIf the `torrentId` is an http/https link to the .torrent file, then the request to the file\ncan be modified by passing `simple-get` params. For example:\n\n```js\nimport { remote } from 'parse-torrent'\nremote(torrentId, { timeout: 60 * 1000 }, (err, parsedTorrent) =\u003e {\n  if (err) throw err\n  console.log(parsedTorrent)\n})\n```\n\n### command line program\n\nThis package also includes a command line program.\n\n```\nUsage: parse-torrent /path/to/torrent\n       parse-torrent magnet_uri\n       parse-torrent --stdin\n```\n\nTo install it, run:\n\n```\nnpm install parse-torrent -g\n```\n\n## license\n\nMIT. Copyright (c) [Feross Aboukhadijeh](https://feross.org) and [WebTorrent, LLC](https://webtorrent.io).\n","funding_links":["https://github.com/sponsors/webtorrent","https://github.com/sponsors/feross"],"categories":["Modules","JavaScript","Libraries"],"sub_categories":["Javascript"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebtorrent%2Fparse-torrent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebtorrent%2Fparse-torrent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebtorrent%2Fparse-torrent/lists"}