开源webtorrent在线播放器

在线解析磁连,并播放。

用php解析torrent文件

https://github.com/adriengibrat/torrent-rw

磁连和种子互转

https://github.com/likebeta/torrent2magnet

官方-方法1

https://github.com/webtorrent/webtorrent

<script src="https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js"></script>
<div id="video" style="width: 100%; height: auto;"></div>
<script>
//var WebTorrent = require('webtorrent')
var client = new WebTorrent()
// Sintel, a free, Creative Commons movie
var torrentId = 'magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&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'

client.add(torrentId, function (torrent) {
// Got torrent metadata!
console.log('Client is downloading:', torrent.infoHash);
// Torrents can contain many files. Let's use the .mp4 file
var file = torrent.files.find(function (file) {
	return file.name.endsWith('.mp4')
});
// Display the file by adding it to the DOM.
// Supports video, audio, image files, and more!
file.appendTo('#video');
/*
torrent.files.forEach(function (file) {
// Display the file by appending it to the DOM. Supports video, audio, images, and
// more. Specify a container element (CSS selector or reference to DOM node).
file.appendTo('body')
})
*/
})
</script>

官方-方法2

https://github.com/mikeal/webtorrent-element

<script src="https://cdn.jsdelivr.net/npm/webtorrent-element@latest/dist/webtorrent-element.min.js"></script>
<web-torrent src="magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&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"
  file="Sintel.mp4"
  />
点赞