]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/videos.js
Try to make a better communication (between pods) module
[github/Chocobozzz/PeerTube.git] / server / lib / videos.js
index 154c31ef9e4f3537913b90bee673a30d0001edd8..a74c77dc4c98b8bdf37cb80c7d67a4b03275030f 100644 (file)
@@ -17,6 +17,7 @@ const uploadDir = pathUtils.join(__dirname, '..', '..', config.get('storage.uplo
 const thumbnailsDir = pathUtils.join(__dirname, '..', '..', config.get('storage.thumbnails'))
 
 const videos = {
+  convertVideoToRemote: convertVideoToRemote,
   createRemoteVideos: createRemoteVideos,
   getVideoDuration: getVideoDuration,
   getVideoState: getVideoState,
@@ -27,6 +28,29 @@ const videos = {
   seedAllExisting: seedAllExisting
 }
 
+function convertVideoToRemote (video, callback) {
+  fs.readFile(thumbnailsDir + video.thumbnail, function (err, thumbnailData) {
+    if (err) {
+      logger.error('Cannot read the thumbnail of the video')
+      return callback(err)
+    }
+
+    const remoteVideo = {
+      name: video.name,
+      description: video.description,
+      magnetUri: video.magnetUri,
+      author: video.author,
+      duration: video.duration,
+      thumbnailBase64: new Buffer(thumbnailData).toString('base64'),
+      tags: video.tags,
+      createdDate: video.createdDate,
+      podUrl: video.podUrl
+    }
+
+    return callback(null, remoteVideo)
+  })
+}
+
 function createRemoteVideos (videos, callback) {
   // Create the remote videos from the new pod
   createRemoteVideoObjects(videos, function (err, remoteVideos) {
@@ -153,7 +177,9 @@ function createRemoteVideoObjects (videos, callback) {
           magnetUri: video.magnetUri,
           podUrl: video.podUrl,
           duration: video.duration,
-          thumbnail: thumbnailName
+          thumbnail: thumbnailName,
+          tags: video.tags,
+          author: video.author
         }
         remoteVideos.push(params)