Refractor published date on video import
This commit is contained in:
parent
84929846e7
commit
c74c9be934
|
@ -16,7 +16,7 @@ export type YoutubeDLInfo = {
|
|||
nsfw?: boolean
|
||||
tags?: 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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'),
|
||||
|
||||
|
|
|
@ -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.body
|
||||
|
|
|
@ -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: st
|
|||
fixture: videoPath,
|
||||
thumbnailfile,
|
||||
previewfile: thumbnailfile,
|
||||
originallyPublishedAt: new Date(date).toISOString()
|
||||
originallyPublishedAt: originallyPublishedAt ? originallyPublishedAt.toISOString() : null
|
||||
}
|
||||
|
||||
console.log('\nUploading on PeerTube video "%s".', videoAttributes.name)
|
||||
|
|
|
@ -42,7 +42,6 @@ type VideoAttributes = {
|
|||
updateAt: string
|
||||
privacy?: VideoPrivacy
|
||||
}
|
||||
originallyPublishedAt?: string
|
||||
}
|
||||
|
||||
function getVideoCategories (url: string) {
|
||||
|
|
Loading…
Reference in New Issue