Skip to content

Torrent API

Davenchy edited this page Jan 7, 2020 · 5 revisions

The Endpoint -> /torrent

Based on the webtorrent project

  • Use Torrent API in 3 easy steps
  1. select method more

  2. add torrent id more

  3. add selectors more

Methods

  1. info Get information about the torrent or any file(s) it contains

  2. serve Serve file from inside the torrent

  3. playlist Download(.m3u) playlist file for all the files or some of them

  4. torrentfile Download(.torrent) file

more information

Aliases

Torrent ID

Torrent id can be info hash or magnet uri or http/https torrent url.

the end point can be:

  1. /torrent/{the selected method}/{only info hash}

  2. /torrent/{the selected method}?torrentId={any torrent id}

Selectors

Selectors can be a url query or a parameter string

  • URL Query:

. fileIndex -> /torrent/serve/{info hash}?fileIndex=0

. filePath -> /torrent/serve/{info hash}?filePath=subtitles/subtitle.ar.vtt

. fileType -> /torrent/serve/{info hash}?fileType=video or /torrent/serve/{info hash}?fileType=.mp4

  • Parameter String

. file index -> /torrent/serve/{info hash}/0

. file path -> /torrent/serve/{info hash}/subtitles/subtitle.ar.vtt

.file type -> /torrent/serve/{info hash}/:video or /torrent/serve/{info hash}/:.mp4

Note: add ':' before the file type in the parameter string selectors

Some Examples

Files Tree

\
|-[0]- /poster.jpg
|-[1]- /movie.mp4
|-[2]- /subtitles/subtitle.en.srt
|-[3]- /subtitles/subtitle.en.vtt
|-[4]- /subtitles/subtitle.ar.srt
|-[5]- /subtitles/subtitle.ar.vtt
|-[6]- /subtitles/subtitle.fr.srt
|-[7]- /subtitles/subtitle.fr.vtt
|-[8]- /subtitles/subtitle.de.srt
|-[9]- /subtitles/subtitle.de.vtt
/

To get info of the movie and the english (.vtt) subtitle files [using indexes only]

/torrent/info/{infoHash}?fileIndex=1&fileIndex=3

OR

/torrent/info/{infoHash}/1,3

To get info of the movie and the english (.vtt) subtitle files [using paths only]

/torrent/info/{infoHash}?filePath=movie.mp4&filePath=subtitles/subtitle.en.vtt

OR

/torrent/info/{infoHash}/movie.mp4,subtitles/subtitle.en.vtt

To serve the first video in the torrent

/torrent/serve/{infoHash}?fileType=video

OR

/torrent/serve/{infoHash}?fileType=.mp4

OR

/torrent/serve/{infoHash}/:video

OR

/torrent/serve/{infoHash}/:.mp4

Real Examples

torrent info hash: 08ada5a7a6183aae1e09d831df6748d566095a10 torrent id: magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel

both gives the same results

you can use them like this

/torrent/info/08ada5a7a6183aae1e09d831df6748d566095a10

OR

/torrent/info?torrentId=08ada5a7a6183aae1e09d831df6748d566095a10

OR

/torrent/info?torrentId=magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel


Files Tree

\
|-[0]- /Sintel.de.srt
|-[1]- /Sintel.en.srt
|-[2]- /Sintel.es.srt
|-[3]- /Sintel.fr.srt
|-[4]- /Sintel.it.srt
|-[5]- /Sintel.mp4
|-[6]- /Sintel.nl.srt
|-[7]- /Sintel.pl.srt
|-[8]- /Sintel.pt.srt
|-[9]- /Sintel.ru.srt
|-[10]- /poster.jpg
/
  • Serve files

/torrent/info?torrentId=08ada5a7a6183aae1e09d831df6748d566095a10/Sintel.en.srt

/torrent/info?torrentId=08ada5a7a6183aae1e09d831df6748d566095a10/Sintel.mp4

/torrent/info?torrentId=08ada5a7a6183aae1e09d831df6748d566095a10/poster.jpg

  • Get Info

/torrent/info/08ada5a7a6183aae1e09d831df6748d566095a10/1,5,10

OR

/torrent/info/08ada5a7a6183aae1e09d831df6748d566095a10/Sintel.en.srt,Sintel.mp4,poster.jpg

  • Download playlist (.m3u)

/torrent/playlist/08ada5a7a6183aae1e09d831df6748d566095a10

  • Download torrent file (.torrent)

/torrent/torrentfile/08ada5a7a6183aae1e09d831df6748d566095a10

OR

/torrent/torrentfile?torrentId=08ada5a7a6183aae1e09d831df6748d566095a10

Tables

Get torrent info

Method path query
GET /torrent/info torrentId
GET /torrent/info/:infoHash

Content-Type: application/json

response:

{
  name: String,
  infoHash: String,
  size: Number,
  peers: Number,
  files: [Object]
}

The File Object:

[
  {
    name: String,
    index: Number,
    path: String,
    size: Number,
    downloaded: Number,
    type: String // file mime type e.g.: video/mp4 image/jpg
  },
  ...
]

Serving Files

Method path query
GET /torrent/serve/:infoHash fileIndex or filePath or fileType
GET /torrent/serve/:infoHash/{fileIndex or filePath or fileType starts with ':'}

Content-Type: depends on selected file type

supports ranges

Download torrent as playlist [.m3u]

Method path query
GET /torrent/playlist torrentId
GET /torrent/playlist/:infoHash

Content-Type: application/mpegurl

NOTE: you can use selectors too

Download torrent file [.torrent]

Method path query
GET /torrentfile torrentId
GET /torrentfile/:infoHash

Content-Type: application/x-bittorrent

Aliases

Method Alias
serve s
info i
playlist pl
torrentfile tf