import { FormValidatorService } from '@app/shared'
import { VideoCaptionService } from '@app/shared/video-caption'
import { VideoImportService } from '@app/shared/video-import'
-import { scrollToTop } from '@app/shared/misc/utils'
+import { scrollToTop, getAbsoluteAPIUrl } from '@app/shared/misc/utils'
import { switchMap, map } from 'rxjs/operators'
@Component({
this.isImportingVideo = false
this.hasImportedVideo = true
+ const absoluteAPIUrl = getAbsoluteAPIUrl()
+
+ const thumbnailUrl = video.thumbnailPath
+ ? absoluteAPIUrl + video.thumbnailPath
+ : null
+
+ const previewUrl = video.previewPath
+ ? absoluteAPIUrl + video.previewPath
+ : null
+
this.video = new VideoEdit(Object.assign(video, {
commentsEnabled: videoUpdate.commentsEnabled,
downloadEnabled: videoUpdate.downloadEnabled,
support: null,
- thumbnailUrl: null,
- previewUrl: null
+ thumbnailUrl,
+ previewUrl
}))
this.videoCaptions = videoCaptions
private hydrateFormFromVideo () {
this.form.patchValue(this.video.toFormPatch())
+
+ const objects = [
+ {
+ url: 'thumbnailUrl',
+ name: 'thumbnailfile'
+ },
+ {
+ url: 'previewUrl',
+ name: 'previewfile'
+ }
+ ]
+
+ for (const obj of objects) {
+ fetch(this.video[obj.url])
+ .then(response => response.blob())
+ .then(data => {
+ this.form.patchValue({
+ [ obj.name ]: data
+ })
+ })
+ }
}
}
import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
import { CONFIG } from '../../../initializers/config'
import { sequelizeTypescript } from '../../../initializers/database'
-import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail'
+import { createVideoMiniatureFromExisting, createVideoMiniatureFromUrl } from '../../../lib/thumbnail'
import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
import {
MChannelAccountDefault,
const video = buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo)
- const thumbnailModel = await processThumbnail(req, video)
- const previewModel = await processPreview(req, video)
+ let thumbnailModel: MThumbnail
+
+ // Process video thumbnail from request.files
+ thumbnailModel = await processThumbnail(req, video)
+
+ // Process video thumbnail from url if processing from request.files failed
+ if (!thumbnailModel) {
+ thumbnailModel = await processThumbnailFromUrl(youtubeDLInfo.thumbnailUrl, video)
+ }
+
+ let previewModel: MThumbnail
+
+ // Process video preview from request.files
+ previewModel = await processPreview(req, video)
+
+ // Process video preview from url if processing from request.files failed
+ if (!previewModel) {
+ previewModel = await processPreviewFromUrl(youtubeDLInfo.thumbnailUrl, video)
+ }
const tags = body.tags || youtubeDLInfo.tags
const videoImportAttributes = {
const payload = {
type: 'youtube-dl' as 'youtube-dl',
videoImportId: videoImport.id,
- thumbnailUrl: youtubeDLInfo.thumbnailUrl,
- downloadThumbnail: !thumbnailModel,
- downloadPreview: !previewModel,
+ generateThumbnail: !thumbnailModel,
+ generatePreview: !previewModel,
fileExt: youtubeDLInfo.fileExt
? `.${youtubeDLInfo.fileExt}`
: '.mp4'
return undefined
}
+async function processThumbnailFromUrl (url: string, video: VideoModel) {
+ try {
+ return createVideoMiniatureFromUrl(url, video, ThumbnailType.MINIATURE)
+ } catch (err) {
+ logger.warn('Cannot generate video thumbnail %s for %s.', url, video.url, { err })
+ return undefined
+ }
+}
+
+async function processPreviewFromUrl (url: string, video: VideoModel) {
+ try {
+ return createVideoMiniatureFromUrl(url, video, ThumbnailType.PREVIEW)
+ } catch (err) {
+ logger.warn('Cannot generate video preview %s for %s.', url, video.url, { err })
+ return undefined
+ }
+}
+
function insertIntoDB (parameters: {
video: MVideoThumbnailAccountDefault
thumbnailModel: MThumbnail
import { Notifier } from '../../notifier'
import { CONFIG } from '../../../initializers/config'
import { sequelizeTypescript } from '../../../initializers/database'
-import { createVideoMiniatureFromUrl, generateVideoMiniature } from '../../thumbnail'
+import { generateVideoMiniature } from '../../thumbnail'
import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
import { MThumbnail } from '../../../typings/models/video/thumbnail'
import { MVideoImportDefault, MVideoImportDefaultFiles, MVideoImportVideo } from '@server/typings/models/video/video-import'
type: 'youtube-dl'
videoImportId: number
- thumbnailUrl: string
- downloadThumbnail: boolean
- downloadPreview: boolean
+ generateThumbnail: boolean
+ generatePreview: boolean
fileExt?: string
}
const options = {
videoImportId: payload.videoImportId,
- downloadThumbnail: false,
- downloadPreview: false,
-
generateThumbnail: true,
generatePreview: true
}
const options = {
videoImportId: videoImport.id,
- downloadThumbnail: payload.downloadThumbnail,
- downloadPreview: payload.downloadPreview,
- thumbnailUrl: payload.thumbnailUrl,
-
- generateThumbnail: false,
- generatePreview: false
+ generateThumbnail: payload.generateThumbnail,
+ generatePreview: payload.generatePreview
}
return processFile(() => downloadYoutubeDLVideo(videoImport.targetUrl, payload.fileExt, VIDEO_IMPORT_TIMEOUT), videoImport, options)
type ProcessFileOptions = {
videoImportId: number
- downloadThumbnail: boolean
- downloadPreview: boolean
- thumbnailUrl?: string
-
generateThumbnail: boolean
generatePreview: boolean
}
// Process thumbnail
let thumbnailModel: MThumbnail
- if (options.downloadThumbnail && options.thumbnailUrl) {
- try {
- thumbnailModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImportWithFiles.Video, ThumbnailType.MINIATURE)
- } catch (err) {
- logger.warn('Cannot generate video thumbnail %s for %s.', options.thumbnailUrl, videoImportWithFiles.Video.url, { err })
- }
- }
-
- if (!thumbnailModel && (options.generateThumbnail || options.downloadThumbnail)) {
+ if (options.generateThumbnail) {
thumbnailModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.MINIATURE)
}
// Process preview
let previewModel: MThumbnail
- if (options.downloadPreview && options.thumbnailUrl) {
- try {
- previewModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImportWithFiles.Video, ThumbnailType.PREVIEW)
- } catch (err) {
- logger.warn('Cannot generate video preview %s for %s.', options.thumbnailUrl, videoImportWithFiles.Video.url, { err })
- }
- }
-
- if (!previewModel && (options.generatePreview || options.downloadPreview)) {
+ if (options.generatePreview) {
previewModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.PREVIEW)
}
} from '../../../../shared/extra-utils'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
+import { testImage } from '../../../../shared/extra-utils/miscs/miscs'
const expect = chai.expect
const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })
const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
expect(res.body.video.name).to.equal('small video - youtube')
+ expect(res.body.video.thumbnailPath).to.equal(`/static/thumbnails/${res.body.video.uuid}.jpg`)
+ expect(res.body.video.previewPath).to.equal(`/static/previews/${res.body.video.uuid}.jpg`)
+ await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath)
+ await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath)
const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id)
const videoCaptions: VideoCaption[] = resCaptions.body.data