aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/videos.js')
-rw-r--r--lib/videos.js102
1 files changed, 50 insertions, 52 deletions
diff --git a/lib/videos.js b/lib/videos.js
index 0e8143351..2d7d9500d 100644
--- a/lib/videos.js
+++ b/lib/videos.js
@@ -1,52 +1,50 @@
1;(function () { 1'use strict'
2 'use strict' 2
3 3var async = require('async')
4 var async = require('async') 4var config = require('config')
5 var config = require('config') 5var path = require('path')
6 var path = require('path') 6var webtorrent = require('../lib/webtorrent')
7 var webtorrent = require('../lib/webtorrent') 7
8 8var logger = require('../helpers/logger')
9 var logger = require('../helpers/logger') 9var Videos = require('../models/videos')
10 var Videos = require('../models/videos') 10
11 11var uploadDir = path.join(__dirname, '..', config.get('storage.uploads'))
12 var uploadDir = path.join(__dirname, '..', config.get('storage.uploads')) 12
13 13var videos = {
14 var videos = { 14 seed: seed,
15 seed: seed, 15 seedAllExisting: seedAllExisting
16 seedAllExisting: seedAllExisting 16}
17 } 17
18 18function seed (path, callback) {
19 function seed (path, callback) { 19 logger.info('Seeding %s...', path)
20 logger.info('Seeding %s...', path) 20
21 21 webtorrent.seed(path, function (torrent) {
22 webtorrent.seed(path, function (torrent) { 22 logger.info('%s seeded (%s).', path, torrent.magnetURI)
23 logger.info('%s seeded (%s).', path, torrent.magnetURI) 23
24 24 return callback(null, torrent)
25 return callback(null, torrent) 25 })
26 }) 26}
27 } 27
28 28function seedAllExisting (callback) {
29 function seedAllExisting (callback) { 29 Videos.listOwned(function (err, videos_list) {
30 Videos.listOwned(function (err, videos_list) { 30 if (err) {
31 if (err) { 31 logger.error('Cannot get list of the videos to seed.')
32 logger.error('Cannot get list of the videos to seed.') 32 return callback(err)
33 return callback(err) 33 }
34 } 34
35 35 async.each(videos_list, function (video, each_callback) {
36 async.each(videos_list, function (video, each_callback) { 36 seed(uploadDir + video.namePath, function (err) {
37 seed(uploadDir + video.namePath, function (err) { 37 if (err) {
38 if (err) { 38 logger.error('Cannot seed this video.')
39 logger.error('Cannot seed this video.') 39 return callback(err)
40 return callback(err) 40 }
41 } 41
42 42 each_callback(null)
43 each_callback(null) 43 })
44 }) 44 }, callback)
45 }, callback) 45 })
46 }) 46}
47 } 47
48 48// ---------------------------------------------------------------------------
49 // --------------------------------------------------------------------------- 49
50 50module.exports = videos
51 module.exports = videos
52})()