import { processImage } from '../helpers/image-utils'
import { join } from 'path'
import { downloadImage } from '../helpers/requests'
-import { MVideoPlaylistThumbnail } from '../typings/models/video/video-playlist'
-import { MVideoFile, MVideoThumbnail } from '../typings/models'
-import { MThumbnail } from '../typings/models/video/thumbnail'
+import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist'
+import { MVideoFile, MVideoThumbnail } from '../types/models'
+import { MThumbnail } from '../types/models/video/thumbnail'
import { getVideoFilePath } from './video-paths'
type ImageSize = { height: number, width: number }
return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, automaticallyGenerated, existingThumbnail })
}
-function createPlaylistMiniatureFromUrl (fileUrl: string, playlist: MVideoPlaylistThumbnail, size?: ImageSize) {
+function createPlaylistMiniatureFromUrl (downloadUrl: string, playlist: MVideoPlaylistThumbnail, size?: ImageSize) {
const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size)
const type = ThumbnailType.MINIATURE
- const thumbnailCreator = () => downloadImage(fileUrl, basePath, filename, { width, height })
+ // Only save the file URL if it is a remote playlist
+ const fileUrl = playlist.isOwned()
+ ? null
+ : downloadUrl
+
+ const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height })
return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
}
-function createVideoMiniatureFromUrl (fileUrl: string, video: MVideoThumbnail, type: ThumbnailType, size?: ImageSize) {
+function createVideoMiniatureFromUrl (downloadUrl: string, video: MVideoThumbnail, type: ThumbnailType, size?: ImageSize) {
const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
- const thumbnailCreator = () => downloadImage(fileUrl, basePath, filename, { width, height })
+ // Only save the file URL if it is a remote video
+ const fileUrl = video.isOwned()
+ ? null
+ : downloadUrl
+
+ const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height })
return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
}
-function createVideoMiniatureFromExisting (
- inputPath: string,
- video: MVideoThumbnail,
- type: ThumbnailType,
- automaticallyGenerated: boolean,
+function createVideoMiniatureFromExisting (options: {
+ inputPath: string
+ video: MVideoThumbnail
+ type: ThumbnailType
+ automaticallyGenerated: boolean
size?: ImageSize
-) {
+ keepOriginal?: boolean
+}) {
+ const { inputPath, video, type, automaticallyGenerated, size, keepOriginal } = options
+
const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
- const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height })
+ const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal)
return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, automaticallyGenerated, existingThumbnail })
}