I am making a movie streaming platform, with the use of WebTorrent plugin, which will stream the whole movie without downloading it, user just needs to paste the torrent link or the same. So, I want to post the value of input field as the value for the variable. The value for the input field will be a link to the torrent file, for eg. "https://webtorrent.io/torrents/sintel.torrent". So what ever link has been posted in the input box, it should be posted as a value for the variable i.e. torrentId.
Example: var torrentId = 'https://webtorrent.io/torrents/sintel.torrent'
In the case for the above torrent file, the piece of code should look like the example mentioned above, so what I am trying to do here is, as soon as the user pastes a link to the torrent file, the value for the variable torrentId should be defined in the format as the example mentioned above, and the desired movie will be loaded, to be streamed on the go.
Here is the snippet, without custom link functionality.
var vid_type = document.getElementById('type').value;
if (vid_type === 'embed_tr') {
var client = new WebTorrent()
var torrentId = 'https://webtorrent.io/torrents/sintel.torrent'
client.add(torrentId, function(torrent) {
var file = torrent.files.find(function(file) {
return file.name.endsWith('.mp4')
})
file.appendTo('body')
})
}
<script src="https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js"></script>
<select _ngcontent-fte-c234="" required="" id="type" formcontrolname="type" class="ng-valid ng-touched ng-dirty">
<option _ngcontent-fte-c234="" value="embed_tr" trans="">Embed Torrent</option>
<option _ngcontent-fte-c234="" value="video" trans="">Direct Video (.mp4, .webm, .avi, .mov etc.)</option>
<option _ngcontent-fte-c234="" value="stream" trans="">Adaptive Stream (hls, dash)</option>
<option _ngcontent-fte-c234="" value="external" trans="">Basic Url</option>
</select>
Here is the snippet, with custom link functionality, this is what I am trying to do.
var vid_type = document.getElementById('type').value;
if (vid_type === 'embed_tr') {
var client = new WebTorrent()
function myFunction() {
var torrentId = document.getElementById('url').value;
console.log(torrentId)
}
client.add(torrentId, function(torrent) {
var file = torrent.files.find(function(file) {
return file.name.endsWith('.mp4')
})
file.appendTo('body')
})
}
#url {
width: 275px;
}
<script src="https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js"></script>
<select _ngcontent-fte-c234="" required="" id="type" formcontrolname="type" class="ng-valid ng-touched ng-dirty">
<option _ngcontent-fte-c234="" value="embed_tr" trans="">Embed Torrent</option>
<option _ngcontent-fte-c234="" value="video" trans="">Direct Video (.mp4, .webm, .avi, .mov etc.)</option>
<option _ngcontent-fte-c234="" value="stream" trans="">Adaptive Stream (hls, dash)</option>
<option _ngcontent-fte-c234="" value="external" trans="">Basic Url</option>
</select>
<input _ngcontent-fte-c234="" name="torrentId" type="text" required="" maxlength="250" id="url" formcontrolname="url" class="ng-untouched ng-pristine ng-invalid" placeholder="Paste the link to the torrent file">
blurevent on those inputs.