From 84929846e743f4b5f3971b386ea2c447db8c416f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9s=20Maldonado?= Date: Sat, 5 Jan 2019 19:55:40 +0100 Subject: [PATCH] Import original publication date (CLI) * Import original publication date when importing a video from YouTube using the CLI * Fix lint issues --- server/helpers/youtube-dl.ts | 2 +- server/tools/peertube-import-videos.ts | 5 ++++- shared/utils/videos/videos.ts | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.ts index 4d4b37ef9..a5ab92df0 100644 --- a/server/helpers/youtube-dl.ts +++ b/server/helpers/youtube-dl.ts @@ -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), diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index 151c5a989..4032c5e0d 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts @@ -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) diff --git a/shared/utils/videos/videos.ts b/shared/utils/videos/videos.ts index 16ecbfe84..92dadfb69 100644 --- a/shared/utils/videos/videos.ts +++ b/shared/utils/videos/videos.ts @@ -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) } -- 2.25.1