PeerTube/lib/videos.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-02-04 14:10:33 -06:00
;(function () {
'use strict'
var async = require('async')
var config = require('config')
2016-02-06 09:22:39 -06:00
var webtorrent = require('../lib/webtorrent')
2016-02-04 14:10:33 -06:00
var logger = require('../helpers/logger')
var Videos = require('../models/videos')
var uploadDir = __dirname + '/../' + config.get('storage.uploads')
var videos = {
seed: seed,
seedAllExisting: seedAllExisting
}
function seed (path, callback) {
logger.info('Seeding %s...', path)
webtorrent.seed(path, function (torrent) {
logger.info('%s seeded (%s).', path, torrent.magnetURI)
return callback(null, torrent)
})
}
function seedAllExisting (callback) {
Videos.listOwned(function (err, videos_list) {
if (err) {
2016-02-05 12:02:05 -06:00
logger.error('Cannot get list of the videos to seed.')
2016-02-04 14:10:33 -06:00
return callback(err)
}
async.each(videos_list, function (video, each_callback) {
seed(uploadDir + video.namePath, function (err) {
if (err) {
2016-02-05 12:02:05 -06:00
logger.error('Cannot seed this video.')
2016-02-04 14:10:33 -06:00
return callback(err)
}
each_callback(null)
})
}, callback)
})
}
// ---------------------------------------------------------------------------
module.exports = videos
})()