Tercus / crowder

crowder is a decentralized crowd-sourced open video platform
0 stars 0 forks source link

Implement thumbnails #5

Open Tercus opened 8 years ago

Tercus commented 8 years ago

torrent.on('done', function () { create thumbnail and store in the same folder })

Once the webseed has downloaded the initial file, it should be quite simple to create a thumbnail of said file.

Tercus commented 8 years ago

might have a look at the webtorrent-desktop app, how they do it there. Seems like a pretty compact piece of code. Can be found in the "webtorrent-desktop\renderer\webtorrent.js":

// Save a JPG that represents a torrent.
// Auto chooses either a frame from a video file, an image, etc
function generateTorrentPoster (torrentKey) {
  var torrent = getTorrent(torrentKey)
  torrentPoster(torrent, function (err, buf, extension) {
    if (err) return console.log('error generating poster: %o', err)
    // save it for next time
    mkdirp(config.CONFIG_POSTER_PATH, function (err) {
      if (err) return console.log('error creating poster dir: %o', err)
      var posterFilePath = path.join(config.CONFIG_POSTER_PATH, torrent.infoHash + extension)
      fs.writeFile(posterFilePath, buf, function (err) {
        if (err) return console.log('error saving poster: %o', err)
        // show the poster
        ipc.send('wt-poster', torrentKey, posterFilePath)
      })
    })
  })
}