How to download torrent with url

How to download torrent with url

how to download torrent with url

Essentially, I have an RSS Feed of torrents that I iterate through and grab the torrent file url, then would like to initiate a download of that torrent. WebTorrent, the streaming torrent client for the browser, Mac, Windows, and Linux. createElement('a') a.download = file.name a.href = url a.textContent. that Vuze needs to locate and talk to the other peers in the download's swarm. The option to add torrent URLs to Vuze is also found by clicking the Open.

How to download torrent with url - really

WebTorrent

WebTorrent is a streaming torrent client for Node.js and the web. WebTorrent provides the same API in both environments.

To use WebTorrent in the browser, WebRTC support is required (Chrome, Firefox, Opera, Safari).

Install

Quick Example

Is WebRTC natively supported in the environment?

Create a new instance.

If is specified, then the default options (shown below) will be overridden.

For possible values of see the documentation.

For possible values of see the documentation.

Start downloading a new torrent.

can be one of:

  • magnet uri (string)
  • torrent file (buffer)
  • info hash (hex string or buffer)
  • parsed torrent (from parse-torrent)
  • http/https url to a torrent file (string)
  • filesystem path to a torrent file (string) (Node.js only)

If is specified, then the default options (shown below) will be overridden.

If is specified, then it will be called when this torrent is ready to be used (i.e. metadata is available). Note: this is distinct from the 'torrent' event which will fire for all torrents.

If you want access to the torrent object immediately in order to listen to events as the metadata is fetched from the network, then use the return value of . If you just want the file data, then use or the 'torrent' event.

If you provide , it will be called as with:

  • - size of all the files in the torrent
  • - an array of torrent file objects
  • - the torrent instance being stored

Note: downloading a torrent automatically seeds it, allowing the user to also serve the file to others who need it

Start seeding a new torrent.

can be any of the following:

  • filesystem path to file or folder (string) (Node.js only)
  • W3C File object (from an or drag and drop) (browser only)
  • W3C FileList object (basically an array of objects) (browser only)
  • Node Buffer object
  • Node Readable stream object

Or, an array of , , , or objects.

If is specified, it should contain the following types of options:

  • options for create-torrent (to allow configuration of the .torrent file that is created)
  • options for (see above)

If is specified, it will be called when the client has begun seeding the file.

Note: Every torrent is required to have a name. If one is not explicitly provided through , one will be determined automatically using the following logic:

  • If all files share a common path prefix, that will be used. For example, if all file paths start with the torrent name will be .
  • Otherwise, the first file that has a name will determine the torrent name. For example, if the first file is , the torrent name will be .
  • If no files have names (say that all files are Buffer or Stream objects), then a name like "Unnamed Torrent

Note: Every file is required to have a name. For filesystem paths or W3C File objects, the name is included in the object. For Buffer or Readable stream types, a property can be set on the object, like this:

Emitted when a torrent is ready to be used (i.e. metadata is available and store is ready). See the torrent section for more info on what methods a has.

Emitted when the client encounters a fatal error. The client is automatically destroyed and all torrents are removed and cleaned up when this occurs.

Always listen for the 'error' event.

Remove a torrent from the client. Destroy all connections to peers and delete all saved file data. If is specified, it will be called when file data is removed.

*Note: This method does not currently delete torrent data (in e.g. , see the option to ). Until this is fixed, please implement it yourself (consider using the npm package).

Destroy the client, including all torrents and connections to peers. If is specified, it will be called when the client has gracefully closed.

An array of all torrents in the client.

Returns the torrent with the given . Convenience method. Easier than searching through the array. Returns if no matching torrent found.

Total download speed for all torrents, in bytes/sec.

Total upload speed for all torrents, in bytes/sec.

Total download progress for all active torrents, from 0 to 1.

Aggregate "seed ratio" for all torrents (uploaded / downloaded).

Name of the torrent (string).

Info hash of the torrent (string).

Magnet URI of the torrent (string).

file of the torrent (Buffer).

(browser only)

file of the torrent (Blob URL).

Array of all tracker servers. Each announce is an URL (string).

Array of all files in the torrent. See documentation for below to learn what methods/properties files have.

Array of all pieces in the torrent. See documentation for below to learn what properties pieces have. Some pieces can be null.

Length in bytes of every piece but the last one.

Length in bytes of the last piece (<= of ).

Time remaining for download to complete (in milliseconds).

Total bytes received from peers (including invalid data).

Total verified bytes received from peers.

Total bytes uploaded to peers.

Torrent download speed, in bytes/sec.

Torrent upload speed, in bytes/sec.

Torrent download progress, from 0 to 1.

Torrent "seed ratio" (uploaded / downloaded).

Number of peers in the torrent swarm.

Max number of simultaneous connections per web seed, as passed in the options.

Torrent download location.

True when the torrent is ready to be used (i.e. metadata is available and store is ready).

True when the torrent has stopped connecting to new peers. Note that this does not pause new incoming connections, nor does it pause the streams of existing connections or their wires.

True when all the torrent files have been downloaded.

Sum of the files length (in bytes).

Date of creation of the torrent (as a Date object).

Author of the torrent (string).

A comment optionnaly set by the author (string).

Alias for . If is provided, it will be called when the torrent is fully destroyed, i.e. all open sockets are closed, and the storage is closed.

Add a peer to the torrent swarm. This is advanced functionality. Normally, you should not need to call manually. WebTorrent will automatically find peers using the tracker servers or DHT. This is just for manually adding a peer to the client.

This method should not be called until the event has been emitted.

Returns if peer was added, if peer was blocked by the loaded blocklist.

The argument must be an address string in the format (for normal TCP/uTP peers), or a instance (for WebRTC peers).

Add a web seed to the torrent swarm. For more information on BitTorrent web seeds, see BEP19.

In the browser, web seed servers must have proper CORS (Cross-origin resource sharing) headers so that data can be fetched across domain.

The argument is the web seed URL.

Remove a peer from the torrent swarm. This is advanced functionality. Normally, you should not need to call manually. WebTorrent will automatically remove peers from the torrent swarm when they're slow or don't have pieces that are needed.

The argument should be an address (i.e. "ip:port" string), a peer id (hex string), or instance.

Selects a range of pieces to prioritize starting with and ending with (both inclusive) at the given . is an optional callback to be called when the selection is updated with new data.

Deprioritizes a range of previously selected pieces.

Marks a range of pieces as critical priority to be downloaded ASAP. From to (both inclusive).

Create an http server to serve the contents of this torrent, dynamically fetching the needed torrent pieces to satisfy http requests. Range requests are supported.

Returns an instance (got from calling ). If is specified, it can have the following properties:

Visiting the root of the server will show a list of links to individual files. Access individual files at where is the index in the array (e.g. , , etc.)

Here is a usage example:

Temporarily stop connecting to new peers. Note that this does not pause new incoming connections, nor does it pause the streams of existing connections or their wires.

Resume connecting to new peers.

Verify the hashes of all pieces in the store and update the bitfield for any new valid pieces. Useful if data has been added to the store outside WebTorrent, e.g. if another process puts a valid file in the right place. Once the scan is complete, will be called (if provided), unless the torrent was destroyed during the scan, in which case will be called with an error.

Emitted when the info hash of the torrent has been determined.

Emitted when the metadata of the torrent has been determined. This includes the full contents of the .torrent file, including list of files, torrent length, piece hashes, piece length, etc.

Emitted when the torrent is ready to be used (i.e. metadata is available and store is ready).

Emitted when there is a warning. This is purely informational and it is not necessary to listen to this event, but it may aid in debugging.

Emitted when the torrent encounters a fatal error. The torrent is automatically destroyed and removed from the client when this occurs.

Note: Torrent errors are emitted at . If there are no 'error' event handlers on the torrent instance, then the error will be emitted at . This prevents throwing an uncaught exception (unhandled 'error' event), but it makes it impossible to distinguish client errors versus torrent errors. Torrent errors are not fatal, and the client is still usable afterwards. Therefore, always listen for errors in both places ( and ).

Emitted when all the torrent files have been downloaded.

Here is a usage example:

Emitted whenever data is downloaded. Useful for reporting the current torrent status, for instance:

Emitted whenever data is uploaded. Useful for reporting the current torrent status.

Emitted whenever a new peer is connected for this torrent. is an instance of , which is a node.js-style duplex stream to the remote peer. This event can be used to specify custom BitTorrent protocol extensions.

Here is a usage example:

See the extension api docs for more information on how to define a protocol extension.

Emitted whenever a DHT or tracker announce occurs, but no peers have been found. is either or depending on which announce occurred to trigger this event. Note that if you're attempting to discover peers from both a tracker and a DHT, you'll see this event separately for each.

File name, as specified by the torrent. Example: 'some-filename.txt'

File path, as specified by the torrent. Example: 'some-folder/some-filename.txt'

File length (in bytes), as specified by the torrent. Example: 12345

Total verified bytes received from peers, for this file.

File download progress, from 0 to 1.

Selects the file to be downloaded, but at a lower priority than files with streams. Useful if you know you need the file at a later stage.

Deselects the file, which means it won't be downloaded unless someone creates a stream for it.

*Note: This method is currently not working as expected, see dcposch answer on #164 for a nice work around solution.

Create a readable stream to the file. Pieces needed by the stream will be prioritized highly and fetched from the swarm first.

You can pass to stream only a slice of a file.

Both and are inclusive.

Get the file contents as a .

The file will be fetched from the network with highest priority, and will be called once the file is ready. must be specified, and will be called with a an (or ) and the file contents as a .

(browser only)

Show the file in a the browser by appending it to the DOM. This is a powerful function that handles many file types like video (.mp4, .webm, .m4v, etc.), audio (.m4a, .mp3, .wav, etc.), images (.jpg, .gif, .png, etc.), and other file formats (.pdf, .md, .txt, etc.).

The file will be fetched from the network with highest priority and streamed into the page (if it's video or audio). In some cases, video or audio files will not be streamable because they're not in a format that the browser can stream so the file will be fully downloaded before being played. For other non-streamable file types like images and PDFs, the file will be downloaded then displayed.

is a container element (CSS selector or reference to DOM node) that the content will be shown in. A new DOM node will be created for the content and appended to .

If provided, can contain the following options:

  • : Autoplay video/audio files (default: )
  • : Mute video/audio files (default: )
  • : Show video/audio player controls (default: )
  • : Files above this size will skip the "blob" strategy and fail (default: bytes)

Note: Modern browsers tend to block media that autoplays with audio (here's the Chrome policy for instance) so if you set to , it's a good idea to also set to .

If provided, will be called once the file is visible to the user. is called with an (or ) and the new DOM node that is displaying the content.

Streaming support depends on support for API in the browser. All modern browsers have support.

For video and audio, webtorrent tries multiple methods of playing the file:

  • -- best option, supports streaming with seeking, but only works with MP4-based files for now (uses API)
  • -- supports more formats, supports streaming without seeking (uses API)
  • Blob URL -- supports the most formats of all (anything the tag supports from an http url), with seeking, but does not support streaming (entire file must be downloaded first)

The Blob URL strategy will not be attempted if the file is over (200 MB by default) since it requires the entire file to be downloaded before playback can start which gives the appearance of the tag being stalled. If you increase the size, be sure to indicate loading progress to the user in the UI somehow.

For other media formats, like images, the file is just added to the DOM.

For text-based formats, like html files, pdfs, etc., the file is added to the DOM via a sandboxed tag.

(browser only)

Like but renders directly into given element (or CSS selector). For example, to render a video, provide a element like .

(browser only)

Get a W3C object which contains the file data.

The file will be fetched from the network with highest priority, and will be called once the file is ready. must be specified, and will be called with a an (or ) and the object.

(browser only)

Get a url which can be used in the browser to refer to the file.

The file will be fetched from the network with highest priority, and will be called once the file is ready. must be specified, and will be called with a an (or ) and the Blob URL ().

This method is useful for creating a file download link, like this:

Piece length (in bytes). Example: 12345

Piece missing length (in bytes). Example: 100

Источник: [https://torrent-igruha.org/3551-portal.html]
how to download torrent with url

How to download torrent with url

3 thoughts to “How to download torrent with url”

Leave a Reply

Your email address will not be published. Required fields are marked *