]> 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 7da4b11d2bb06b21ad1016575623eba944e7558c..a74c77dc4c98b8bdf37cb80c7d67a4b03275030f 100644 (file)
@@ -17,16 +17,40 @@ 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,
-  getVideoThumbnail: getVideoThumbnail,
+  createVideoThumbnail: createVideoThumbnail,
   removeVideosDataFromDisk: removeVideosDataFromDisk,
   removeRemoteVideos: removeRemoteVideos,
   seed: seed,
   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) {
@@ -54,7 +78,7 @@ function getVideoState (video) {
   return { exist: exist, owned: owned }
 }
 
-function getVideoThumbnail (videoPath, callback) {
+function createVideoThumbnail (videoPath, callback) {
   const filename = pathUtils.basename(videoPath) + '.jpg'
   ffmpeg(videoPath)
     .on('error', callback)
@@ -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)