+ // TODO: avoid doublons
+ function addRemotes (videos, callback) {
+ if (callback === undefined) callback = function () {}
+
+ var to_add = []
+
+ async.each(videos, function (video, callback_each) {
+ callback_each = dz(callback_each)
+ logger.debug('Add remote video from pod: %s', video.podUrl)
+
+ var params = {
+ name: video.name,
+ namePath: null,
+ description: video.description,
+ magnetUri: video.magnetUri,
+ podUrl: video.podUrl
+ }
+
+ to_add.push(params)
+
+ callback_each()
+ }, function () {
+ VideosDB.create(to_add, function (err, videos) {
+ if (err) {
+ logger.error('Cannot insert this remote video.', { error: err })
+ return callback(err)
+ }
+
+ return callback(null, videos)
+ })
+ })
+ }
+
+ function get (id, callback) {
+ VideosDB.findById(id, function (err, video) {
+ if (err) {
+ logger.error('Cannot get this video.', { error: err })
+ return callback(err)
+ }
+
+ return callback(null, video)
+ })
+ }
+
+ function list (callback) {
+ VideosDB.find(function (err, videos_list) {
+ if (err) {
+ logger.error('Cannot get list of the videos.', { error: err })
+ return callback(err)
+ }
+
+ return callback(null, videos_list)
+ })
+ }
+
+ function listOwned (callback) {
+ // If namePath is not null this is *our* video
+ VideosDB.find({ namePath: { $ne: null } }, function (err, videos_list) {
+ if (err) {
+ logger.error('Cannot get list of the videos.', { error: err })
+ return callback(err)
+ }
+
+ return callback(null, videos_list)
+ })
+ }
+
+ function remove (id, callback) {