• Stars
    star
    173
  • Rank 218,819 (Top 5 %)
  • Language
    JavaScript
  • License
    The Unlicense
  • Created over 7 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Transform ordinary download links into super-powered WebTorrent ones!

download-with-webtorrent-button

Transform ordinary download links into super-powered WebTorrent ones!

Example

Check out the demo page: https://wmhilton.github.io/download-with-webtorrent-button

screenshot of WebTorrent button

Sponsor

Rationale

Do you have a big, popular file that lots of people download and the Internet would grind to a halt if your website went down? It is EASY to spread the burden of hosting a file among all the people who are downloading it. Bittorrent (despite its association with piracy) is a fabulous network protocol that does exactly that. It use to be that you needed to install separate software to use Bittorrent, but with the advent of WebTorrent it is now possible to use the Bittorrent protocol seamlessly in the browser without visitors ever having to leave your site!

Despite how FREAKING AWESOME WebTorrent is, not enough sites are taking advantage of it. To make taking advantage of WebTorrent as easy and accessible as possible, I decided to make a "Download with WebTorrent" button that turns your ordinary download link into a super-powered WebTorrent download link! All you have to do is paste a small code snippet in your HTML.

Installation using a CDN

Add the following stylesheet to <head>:

<link rel="stylesheet" href="https://unpkg.com/download-with-webtorrent-button/dist/index.css">

And the following scripts to the bottom of <body>:

<script src="https://unpkg.com/webtorrent/webtorrent.min.js"></script>
<script src="https://unpkg.com/download-with-webtorrent-button/dist/index.js"></script>

This adds a single function registerWebtorrentLinks() to the global scope. It automatically initializes a tags. If you add additional a tags after the initial page load (such as in the case of single page apps) you can rerun registerWebtorrentLinks().

If you want to override the CSS styles, take a look at index.css.

Installation using a module bundler?

Somebody should fork this and make it a React component. Pull requests welcome!

Usage

The easiest way

To add a Download with WebTorrent button to your page, use a regular <a> link. The link's href attribute will be provided as a fallback on browsers that can't run WebTorrent, or if an error occurs. Then add a data-webtorrent attribute.

You can use data-webtorrent="auto" and these fabulous free services will auto-generate a WebTorrent-compatible .torrent file for your link.

<a href="file.mp4" data-webtorrent="auto">Link Text</a>

Bring your own torrent

If you already have a magnet URI, you can use that,

<a href="file.mp4" data-webtorrent="magnet:?xt=urn:btih:...">Link Text</a>

or the location of a .torrent file,

<a href="file.mp4" data-webtorrent="https://example.com/path/to/file.torrent">Link Text</a>

but know that WebTorrent is not yet compatible with the DHT and requires ws or http trackers. If your .torrent only includes udp trackers or is tracker-less and relies on the DHT, you are better off using data-webtorrent="auto".

If your torrent is a folder torrent rather than a single file, add a data-file attribute with the name of the individual file you intend the link for.

<a href="https://webtorrent.io/torrents/Sintel/Sintel.mp4" data-webtorrent="magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent" data-file="Sintel.mp4">Sintel</a>

License

Copyright 2017 William Hilton. Licensed under The Unlicense.

More Repositories

1

lock-screen

An invisible screensaver / lock screen for Windows 7+
C#
79
star
2

nde

The IDE of the future, today!
JavaScript
78
star
3

react-prettier-code-tag

Responsive JS <code> tags using prettier
JavaScript
70
star
4

cors-buster

When you need a file, but the headers ain't good, who you gonna call? CORS Buster!
JavaScript
49
star
5

g

g - the improved CLI for git
Shell
41
star
6

magic-portal

Pass objects with async methods between WebWorkers and the main thread easily
JavaScript
14
star
7

node-modules.io

A website dedicated to alternatives to npmjs.com
13
star
8

beautify

Parses and rewrites your HTML/CSS/JS/PHP to be beautiful and readable
JavaScript
12
star
9

hubo-js

a JavaScript version of Hubo, the humanoid robot
JavaScript
10
star
10

webtorrentify-link

Generate a WebTorrent-compatible .torrent from a URL
JavaScript
9
star
11

ransomAware

Be notified the moment you get ransomware by monitoring the filesystem
JavaScript
9
star
12

webtorrentify-server

A microservice for generating .torrent files from URLs
JavaScript
8
star
13

hypergit-service

Runs hypergit seed as a background service
JavaScript
7
star
14

webtorrentify-github-release

Generate a .torrent file corresponding to a particular Github Release
JavaScript
7
star
15

boots

boots is short for "It boots, but that's about it"-OS
Assembly
6
star
16

treeui

Interactive graphical tree structure editor, using d3 and jQuery
CoffeeScript
5
star
17

nandland-tutorial-projects

I bought a Nandland Go board and am doing the YouTube tutorial projects!
Verilog
4
star
18

pushrun

git push ==> run things
Shell
4
star
19

git-demystified-talk

my talk "Git Demystified"
HTML
3
star
20

nft-maker

Created with CodeSandbox
JavaScript
3
star
21

wills-wonderful-service-worker

ServiceWorker that does stuff
JavaScript
3
star
22

require.node-modules.io

Experimental alternative module loader aiming to challenge the status quo
JavaScript
3
star
23

isomorphic-textencoder

encode/decode Uint8Arrays to strings
JavaScript
2
star
24

lightning-http

pure JavaScript HTTP client/server
JavaScript
2
star
25

select-case

JavaScript
2
star
26

GearItDone

Gear It Done! is a tool to design gear trains. Exports to DXF and STL for lasercuting, machining, or 3D printing.
JavaScript
2
star
27

isomorphic-pgp

The lightweight PGP library
JavaScript
2
star
28

tdop

Douglas Crockford's Top Down Operator Precedence parser, written in ES6
JavaScript
2
star
29

whitelist-ips

Connect/Express middleware for whitelisting by IP addresses.
CoffeeScript
2
star
30

my_modules

Keeps local modules out of node_modules, but still have working 'npm install' and 'require()'.
JavaScript
2
star
31

decshell

Declarative Shell Scripting
Shell
1
star
32

git-with-empty-dir

1
star
33

cnm

Create Node Module is a cli for getting your new module off to a great start.
Shell
1
star
34

login-with-github

JavaScript
1
star
35

biotac_webgui

A webpage visualization of the Biotac finger data from ROS using rosbridge.
JavaScript
1
star
36

yarn-lockfile

parse and/or write `yarn.lock` files
JavaScript
1
star
37

log

A console.log replacement.
JavaScript
1
star
38

remodulate

Convert ES2015 modules to CommonJS modules (and vice versa?)
JavaScript
1
star
39

obs-overlay

TypeScript
1
star
40

dotfiles

My config files for $HOME are pretty fly.
Shell
1
star
41

wasm-reverse-string

just playing around with AssemblyScript
1
star
42

img2asm6502

Generate Easy 6502 assembly code to display image files.
JavaScript
1
star
43

unixtime

A microservice that returns the UNIX epoch timestamp
JavaScript
1
star
44

modload

An experimental alternative module loader
JavaScript
1
star
45

unadorned-script

Imagine you wanted to reimplement CoffeeScript in an hour.
CoffeeScript
1
star
46

deflate-cli

A CLI utility for deflating streams with the `deflate` algorithm
JavaScript
1
star
47

modinst

A highly experimental alternative module installer
JavaScript
1
star
48

inflate-cli

A CLI utility for inflating streams compressed with `deflate` algorithm
JavaScript
1
star
49

connect-block-hotlinks

Middleware for blocking cross-origin requests (hotlinks)
CoffeeScript
1
star
50

lambda-calculator

A small parser for the Ξ»-calculus written in Haskell that I'm making for fun.
Haskell
1
star
51

git-apps

Install static websites directly from Github using a ServiceWorker.
HTML
1
star
52

tab-title

Sets process.title in node, document.title in browserify
JavaScript
1
star