Import original publication date (CLI)
authorAndrés Maldonado <amaldona@etu.utc.fr>
Sat, 5 Jan 2019 18:55:40 +0000 (19:55 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 12 Feb 2019 10:19:19 +0000 (11:19 +0100)
* Import original publication date when importing a video from YouTube using the CLI
* Fix lint issues

server/helpers/youtube-dl.ts
server/tools/peertube-import-videos.ts
shared/utils/videos/videos.ts

index 4d4b37ef938fcd74249df092b71ada6c0950c7b6..a5ab92df0b865240bb3f101b5e698c1f9e7aef14 100644 (file)
@@ -175,7 +175,7 @@ function normalizeObject (obj: any) {
 
 function buildVideoInfo (obj: any) {
 
-  const date = obj.upload_date.slice(0,4)+","+obj.upload_date.slice(4,6)+","+obj.upload_date.slice(6,8)
+  const date = obj.upload_date.slice(0,4) + ',' + obj.upload_date.slice(4,6) + ',' + obj.upload_date.slice(6,8)
 
   return {
     name: titleTruncation(obj.title),
index 151c5a9896690ffd630d8ae7bc1983aa86e4c06c..4032c5e0d11dba493d23e997786745c8dac28e40 100644 (file)
@@ -212,6 +212,8 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, cwd: st
     }, thumbnailfile)
   }
 
+  const date = videoInfo.upload_date.slice(0,4) + ',' + videoInfo.upload_date.slice(4,6) + ',' + videoInfo.upload_date.slice(6,8)
+
   const videoAttributes = {
     name: truncate(videoInfo.title, {
       'length': CONSTRAINTS_FIELDS.VIDEOS.NAME.max,
@@ -231,7 +233,8 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, cwd: st
     privacy: VideoPrivacy.PUBLIC,
     fixture: videoPath,
     thumbnailfile,
-    previewfile: thumbnailfile
+    previewfile: thumbnailfile,
+    originallyPublishedAt: new Date(date).toISOString()
   }
 
   console.log('\nUploading on PeerTube video "%s".', videoAttributes.name)
index 16ecbfe848851493ee3c8fdade13badc63c67a86..92dadfb6904ea8fb7912e2b984f7073f140fc0fd 100644 (file)
@@ -42,6 +42,7 @@ type VideoAttributes = {
     updateAt: string
     privacy?: VideoPrivacy
   }
+  originallyPublishedAt?: string
 }
 
 function getVideoCategories (url: string) {
@@ -373,6 +374,10 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
     }
   }
 
+  if (attributes.originallyPublishedAt !== undefined) {
+    req.field('originallyPublishedAt', attributes.originallyPublishedAt)
+  }
+
   return req.attach('videofile', buildAbsoluteFixturePath(attributes.fixture))
             .expect(specialStatus)
 }