ActivityPub-federated video streaming platform using P2P directly in your web browser
Refractor published date on video import
Chocobozzzc74c9be934fa
diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.tsindex a5ab92df0b..782dd2e2e1 100644--- a/server/helpers/youtube-dl.ts+++ b/server/helpers/youtube-dl.ts@@ -16,7 +16,7 @@ export type YoutubeDLInfo = {nsfw?: booleantags?: string[]thumbnailUrl?: string- originallyPublishedAt?: string+ originallyPublishedAt?: Date}const processOptions = {@@ -143,13 +143,33 @@ async function safeGetYoutubeDL () {return youtubeDL}+function buildOriginallyPublishedAt (obj: any) {+ let originallyPublishedAt: Date = null++ const uploadDateMatcher = /^(\d{4})(\d{2})(\d{2})$/.exec(obj.upload_date)+ if (uploadDateMatcher) {+ originallyPublishedAt = new Date()+ originallyPublishedAt.setHours(0, 0, 0, 0)++ const year = parseInt(uploadDateMatcher[1], 10)+ // Month starts from 0+ const month = parseInt(uploadDateMatcher[2], 10) - 1+ const day = parseInt(uploadDateMatcher[3], 10)++ originallyPublishedAt.setFullYear(year, month, day)+ }++ return originallyPublishedAt+}+// ---------------------------------------------------------------------------export {updateYoutubeDLBinary,downloadYoutubeDLVideo,getYoutubeDLInfo,- safeGetYoutubeDL+ safeGetYoutubeDL,+ buildOriginallyPublishedAt}// ---------------------------------------------------------------------------@@ -174,9 +194,6 @@ 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)-return {name: titleTruncation(obj.title),description: descriptionTruncation(obj.description),@@ -185,7 +202,7 @@ function buildVideoInfo (obj: any) {nsfw: isNSFW(obj),tags: getTags(obj.tags),thumbnailUrl: obj.thumbnail || undefined,- originallyPublishedAt: new Date(date).toISOString()+ originallyPublishedAt: buildOriginallyPublishedAt(obj)}}diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.tsindex 6a95d60958..7816d229c6 100644--- a/server/middlewares/validators/search.ts+++ b/server/middlewares/validators/search.ts@@ -10,6 +10,9 @@ const videosSearchValidator = [query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'),query('endDate').optional().custom(isDateValid).withMessage('Should have a valid end date'),+ query('originallyPublishedStartDate').optional().custom(isDateValid).withMessage('Should have a valid published start date'),+ query('originallyPublishedEndDate').optional().custom(isDateValid).withMessage('Should have a valid published end date'),+query('durationMin').optional().isInt().withMessage('Should have a valid min duration'),query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.tsindex cd4988553d..b04c0b8268 100644--- a/server/tests/api/videos/video-imports.ts+++ b/server/tests/api/videos/video-imports.ts@@ -37,6 +37,7 @@ describe('Test video imports', function () {expect(videoHttp.description).to.equal('this is a super description')expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ])expect(videoHttp.files).to.have.lengthOf(1)+ expect(videoHttp.originallyPublishedAt).to.equal('2019-01-13T23:00:00.000Z')const resMagnet = await getVideo(url, idMagnet)const videoMagnet: VideoDetails = resMagnet.bodydiff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.tsindex 4032c5e0d1..04e24e8184 100644--- a/server/tools/peertube-import-videos.ts+++ b/server/tools/peertube-import-videos.ts@@ -11,7 +11,7 @@ import { truncate } from 'lodash'import * as prompt from 'prompt'import { remove } from 'fs-extra'import { sha256 } from '../helpers/core-utils'-import { safeGetYoutubeDL } from '../helpers/youtube-dl'+import { safeGetYoutubeDL, buildOriginallyPublishedAt } from '../helpers/youtube-dl'import { getSettings, netrc } from './cli'let accessToken: string@@ -212,7 +212,7 @@ 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 originallyPublishedAt = buildOriginallyPublishedAt(videoInfo)const videoAttributes = {name: truncate(videoInfo.title, {@@ -234,7 +234,7 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, cwd: stfixture: videoPath,thumbnailfile,previewfile: thumbnailfile,- originallyPublishedAt: new Date(date).toISOString()+ originallyPublishedAt: originallyPublishedAt ? originallyPublishedAt.toISOString() : null}console.log('\nUploading on PeerTube video "%s".', videoAttributes.name)diff --git a/shared/utils/videos/videos.ts b/shared/utils/videos/videos.tsindex 92dadfb690..5d43d9061f 100644--- a/shared/utils/videos/videos.ts+++ b/shared/utils/videos/videos.ts@@ -42,7 +42,6 @@ type VideoAttributes = {updateAt: stringprivacy?: VideoPrivacy}- originallyPublishedAt?: string}function getVideoCategories (url: string) {