aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/videos.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/videos.js')
-rw-r--r--src/videos.js35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/videos.js b/src/videos.js
index f787ae49c..b95219c39 100644
--- a/src/videos.js
+++ b/src/videos.js
@@ -1,27 +1,27 @@
1;(function () { 1;(function () {
2 'use strict' 2 'use strict'
3 3
4 var async = require('async')
5 var config = require('config')
4 var fs = require('fs') 6 var fs = require('fs')
5 var webtorrent = require('./webTorrentNode') 7 var webtorrent = require('./webTorrentNode')
6 var config = require('config')
7 var async = require('async')
8 8
9 var logger = require('./logger') 9 var logger = require('./logger')
10 var VideosDB = require('./database').VideosDB
11 var pods = require('./pods') 10 var pods = require('./pods')
11 var VideosDB = require('./database').VideosDB
12 12
13 var videos = {} 13 var videos = {}
14 // Public url 14
15 var http = config.get('webserver.https') === true ? 'https' : 'http' 15 var http = config.get('webserver.https') === true ? 'https' : 'http'
16 var host = config.get('webserver.host') 16 var host = config.get('webserver.host')
17 var port = config.get('webserver.port') 17 var port = config.get('webserver.port')
18 18
19 // ----------- Private functions ----------- 19 // ----------- Private functions -----------
20 function seedVideo (path, callback) { 20 function seedVideo (path, callback) {
21 logger.debug('Seeding : %s', path) 21 logger.info('Seeding %s...', path)
22 22
23 webtorrent.seed(path, function (torrent) { 23 webtorrent.seed(path, function (torrent) {
24 logger.debug('Seeded : %s', torrent.magnetURI) 24 logger.info('%s seeded (%s).', path, torrent.magnetURI)
25 25
26 return callback(null, torrent) 26 return callback(null, torrent)
27 }) 27 })
@@ -46,7 +46,7 @@
46 var video_file = data.video 46 var video_file = data.video
47 var video_data = data.data 47 var video_data = data.data
48 48
49 logger.debug('Path: %s', video_file.path) 49 logger.info('Adding %s video.', video_file.path)
50 seedVideo(video_file.path, function (err, torrent) { 50 seedVideo(video_file.path, function (err, torrent) {
51 if (err) { 51 if (err) {
52 logger.error('Cannot seed this video.', { error: err }) 52 logger.error('Cannot seed this video.', { error: err })
@@ -70,7 +70,7 @@
70 // Now we'll send the video's meta data 70 // Now we'll send the video's meta data
71 params.namePath = null 71 params.namePath = null
72 72
73 logger.debug('Sending this video Uri to friends...') 73 logger.info('Sending %s video to friends.', video_file.path)
74 74
75 var data = { 75 var data = {
76 path: '/api/' + global.API_VERSION + '/remotevideos/add', 76 path: '/api/' + global.API_VERSION + '/remotevideos/add',
@@ -91,7 +91,7 @@
91 } 91 }
92 92
93 videos.remove = function (id, callback) { 93 videos.remove = function (id, callback) {
94 // Maybe the torrent is not seeding, it doesn't have importance 94 // Maybe the torrent is not seeded, but we catch the error to don't stop the removing process
95 function removeTorrent (magnetUri, callback) { 95 function removeTorrent (magnetUri, callback) {
96 try { 96 try {
97 webtorrent.remove(magnetUri, callback) 97 webtorrent.remove(magnetUri, callback)
@@ -114,7 +114,7 @@
114 return callback(new Error(error_string)) 114 return callback(new Error(error_string))
115 } 115 }
116 116
117 logger.debug('Removing video %s', video.magnetUri) 117 logger.info('Removing %s video', video.name)
118 118
119 removeTorrent(video.magnetUri, function () { 119 removeTorrent(video.magnetUri, function () {
120 VideosDB.findByIdAndRemove(id, function (err) { 120 VideosDB.findByIdAndRemove(id, function (err) {
@@ -154,16 +154,15 @@
154 154
155 // Use the magnet Uri because the _id field is not the same on different servers 155 // Use the magnet Uri because the _id field is not the same on different servers
156 videos.removeRemote = function (fromUrl, magnetUri, callback) { 156 videos.removeRemote = function (fromUrl, magnetUri, callback) {
157 // TODO : check if the remote server has the rights to remove this video
158
159 VideosDB.findOne({ magnetUri: magnetUri }, function (err, video) { 157 VideosDB.findOne({ magnetUri: magnetUri }, function (err, video) {
160 if (err || !video) { 158 if (err || !video) {
161 logger.error('Cannot find the torrent URI of this remote video.') 159 logger.error('Cannot find the torrent URI of this remote video.')
162 return callback(err) 160 return callback(err)
163 } 161 }
164 162
163 // TODO: move to reqValidators middleware ?
165 if (video.podUrl !== fromUrl) { 164 if (video.podUrl !== fromUrl) {
166 logger.error('The pod has not rights on this video.') 165 logger.error('The pod has not the rights on this video.')
167 return callback(err) 166 return callback(err)
168 } 167 }
169 168
@@ -222,23 +221,23 @@
222 }) 221 })
223 } 222 }
224 223
225 videos.seedAll = function (final_callback) { 224 videos.seedAll = function (callback) {
226 VideosDB.find({ namePath: { $ne: null } }, function (err, videos_list) { 225 VideosDB.find({ namePath: { $ne: null } }, function (err, videos_list) {
227 if (err) { 226 if (err) {
228 logger.error('Cannot get list of the videos to seed.', { error: err }) 227 logger.error('Cannot get list of the videos to seed.', { error: err })
229 return final_callback(err) 228 return callback(err)
230 } 229 }
231 230
232 async.each(videos_list, function (video, callback) { 231 async.each(videos_list, function (video, each_callback) {
233 seedVideo(videos.uploadDir + video.namePath, function (err) { 232 seedVideo(videos.uploadDir + video.namePath, function (err) {
234 if (err) { 233 if (err) {
235 logger.error('Cannot seed this video.', { error: err }) 234 logger.error('Cannot seed this video.', { error: err })
236 return callback(err) 235 return callback(err)
237 } 236 }
238 237
239 callback(null) 238 each_callback(null)
240 }) 239 })
241 }, final_callback) 240 }, callback)
242 }) 241 })
243 } 242 }
244 243