Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

torrent with multifile #977

Closed
f1atlux opened this issue Nov 17, 2016 · 8 comments
Closed

torrent with multifile #977

f1atlux opened this issue Nov 17, 2016 · 8 comments

Comments

@f1atlux
Copy link

@f1atlux f1atlux commented Nov 17, 2016

webtorrent.js latest
firefox latest

hi there, i've a torrent file which has multiple files. myname.txt, blabla.jpg and stream.mp4

webtorrent.js is not start streaming on that situation. is there any idea to modify it like "detect that file type" thing?

best.

@f1atlux f1atlux changed the title multi file torrents streaming torrent with multifile Nov 17, 2016
@vankasteelj

This comment has been minimized.

Copy link

@vankasteelj vankasteelj commented Nov 17, 2016

I personnaly do this:

var supported = ['mp4', 'm4v', 'avi', 'mov', 'mkv', 'wmv'];
var extname = function (filename) {
  return filename.split('.').pop();
};

// hide non-video files from selection and set index
for (var f in torrent.files) {
  torrent.files[f].index = f;
  torrent.files[f].display = supported.indexOf(extname(torrent.files[f].name).toLowerCase()) !== -1;
}

note: there might be a better way to find the file extension, I'm using node so I do require('path').extname(filename). in the same spirit, I can pay all those extensions above, but I guess the browser can only play mp4, maybe mov... anyway you get the idea

I can then easily select files, because I only display those who have display=true and I can pick them because there is the "real" index (the one that interrests webtorrent anyway) there. You can then:

var fileIndex = <the actual index you set above, you can also loop to find the biggest .length, it will be 99.99% of the time the video file>;

for (var f in torrent.files) {
  var file = torrent.files[f];
  if (f === parseInt(fileIndex)) {
    file.select();
  } else {
    file.deselect();
  }
}
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 19, 2017

@f1atlux You should do something like what @vankasteelj suggests. All the information is the torrent.files array for you to determine which files you want to stream.

@feross feross closed this Jan 19, 2017
@vankasteelj

This comment has been minimized.

Copy link

@vankasteelj vankasteelj commented Jan 19, 2017

it does have the inconvenient of being heavy to process on v8 with a 100+ file torrent on a slow CPU like an Atom Z

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 20, 2017

@vankasteelj Looping through an array one time is not a heavyweight operation. Anyway, what you're suggesting would have to be done internally in webtorrent either way, so it makes no performance difference:

var files = torrent.files.filter(function (file) {
  var ext = path.extname(file)
  return ext === '.mp4'
})
console.log(files) // now this array only contains mp4 files
@vankasteelj

This comment has been minimized.

Copy link

@vankasteelj vankasteelj commented Jan 21, 2017

it's not the looping array that is heavy, it's the 99 occurrences of file.deselect() on a 100-file torrent. Because part of the point of streaming a torrent is not to download it entirely if it's, for example, the complete CCC collection in 1 torrent.

@vankasteelj

This comment has been minimized.

Copy link

@vankasteelj vankasteelj commented Jan 21, 2017

torrent.deselect() could be a useful api (if you're not internally looping and deselecting each file^^)

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 21, 2017

Yeah, there is already an open issue about improving the way we do selections. For now, we only have file.deselect(). You can follow that issue here: #164

@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.