2024-07-23 16:38:51 +02:00
|
|
|
import {
|
|
|
|
FFmpegContainer,
|
|
|
|
ffprobePromise,
|
|
|
|
getVideoStreamDimensionsInfo,
|
|
|
|
getVideoStreamFPS,
|
|
|
|
hasAudioStream,
|
|
|
|
hasVideoStream,
|
|
|
|
isAudioFile
|
|
|
|
} from '@peertube/peertube-ffmpeg'
|
|
|
|
import { FileStorage, VideoFileFormatFlag, VideoFileMetadata, VideoFileStream, VideoResolution } from '@peertube/peertube-models'
|
2024-03-15 15:47:18 +01:00
|
|
|
import { getFileSize, getLowercaseExtension } from '@peertube/peertube-node-utils'
|
2024-07-23 16:38:51 +02:00
|
|
|
import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg/ffmpeg-options.js'
|
2024-03-15 15:47:18 +01:00
|
|
|
import { logger, loggerTagsFactory } from '@server/helpers/logger.js'
|
2024-07-23 16:38:51 +02:00
|
|
|
import { doRequestAndSaveToFile, generateRequestStream } from '@server/helpers/requests.js'
|
2024-03-15 15:47:18 +01:00
|
|
|
import { CONFIG } from '@server/initializers/config.js'
|
2024-07-23 16:38:51 +02:00
|
|
|
import { MIMETYPES, REQUEST_TIMEOUTS } from '@server/initializers/constants.js'
|
2024-03-15 15:47:18 +01:00
|
|
|
import { VideoFileModel } from '@server/models/video/video-file.js'
|
|
|
|
import { VideoSourceModel } from '@server/models/video/video-source.js'
|
2024-08-08 10:33:41 +02:00
|
|
|
import { MVideo, MVideoFile, MVideoId, MVideoThumbnail, MVideoWithAllFiles } from '@server/types/models/index.js'
|
2024-03-15 15:47:18 +01:00
|
|
|
import { FfprobeData } from 'fluent-ffmpeg'
|
2024-06-13 09:23:12 +02:00
|
|
|
import { move, remove } from 'fs-extra/esm'
|
2024-07-23 16:38:51 +02:00
|
|
|
import { Readable, Writable } from 'stream'
|
2023-07-31 14:34:36 +02:00
|
|
|
import { lTags } from './object-storage/shared/index.js'
|
2024-07-23 16:38:51 +02:00
|
|
|
import {
|
|
|
|
getHLSFileReadStream,
|
|
|
|
getWebVideoFileReadStream,
|
|
|
|
makeHLSFileAvailable,
|
|
|
|
makeWebVideoFileAvailable,
|
|
|
|
storeOriginalVideoFile
|
|
|
|
} from './object-storage/videos.js'
|
2023-07-31 14:34:36 +02:00
|
|
|
import { generateHLSVideoFilename, generateWebVideoFilename } from './paths.js'
|
|
|
|
import { VideoPathManager } from './video-path-manager.js'
|
2023-04-21 14:55:10 +02:00
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export async function buildNewFile (options: {
|
2023-04-21 14:55:10 +02:00
|
|
|
path: string
|
|
|
|
mode: 'web-video' | 'hls'
|
2023-10-19 14:18:22 +02:00
|
|
|
ffprobe?: FfprobeData
|
2024-07-23 16:38:51 +02:00
|
|
|
}): Promise<MVideoFile> {
|
2023-10-19 14:18:22 +02:00
|
|
|
const { path, mode, ffprobe: probeArg } = options
|
2023-04-21 14:55:10 +02:00
|
|
|
|
2023-10-19 14:18:22 +02:00
|
|
|
const probe = probeArg ?? await ffprobePromise(path)
|
2023-04-21 14:55:10 +02:00
|
|
|
const size = await getFileSize(path)
|
|
|
|
|
|
|
|
const videoFile = new VideoFileModel({
|
|
|
|
extname: getLowercaseExtension(path),
|
|
|
|
size,
|
2024-07-23 16:38:51 +02:00
|
|
|
metadata: await buildFileMetadata(path, probe),
|
|
|
|
|
|
|
|
streams: VideoFileStream.NONE,
|
|
|
|
|
|
|
|
formatFlags: mode === 'web-video'
|
|
|
|
? VideoFileFormatFlag.WEB_VIDEO
|
|
|
|
: VideoFileFormatFlag.FRAGMENTED
|
2023-04-21 14:55:10 +02:00
|
|
|
})
|
|
|
|
|
2024-07-23 16:38:51 +02:00
|
|
|
if (await hasAudioStream(path, probe)) {
|
|
|
|
videoFile.streams |= VideoFileStream.AUDIO
|
|
|
|
}
|
|
|
|
|
|
|
|
if (await hasVideoStream(path, probe)) {
|
|
|
|
videoFile.streams |= VideoFileStream.VIDEO
|
|
|
|
}
|
|
|
|
|
2023-04-21 14:55:10 +02:00
|
|
|
if (await isAudioFile(path, probe)) {
|
2024-02-28 10:00:01 +01:00
|
|
|
videoFile.fps = 0
|
2023-04-21 14:55:10 +02:00
|
|
|
videoFile.resolution = VideoResolution.H_NOVIDEO
|
2024-02-28 10:00:01 +01:00
|
|
|
videoFile.width = 0
|
|
|
|
videoFile.height = 0
|
2023-04-21 14:55:10 +02:00
|
|
|
} else {
|
2024-02-27 11:18:56 +01:00
|
|
|
const dimensions = await getVideoStreamDimensionsInfo(path, probe)
|
2023-04-21 14:55:10 +02:00
|
|
|
videoFile.fps = await getVideoStreamFPS(path, probe)
|
2024-02-27 11:18:56 +01:00
|
|
|
videoFile.resolution = dimensions.resolution
|
|
|
|
videoFile.width = dimensions.width
|
|
|
|
videoFile.height = dimensions.height
|
2023-04-21 14:55:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
videoFile.filename = mode === 'web-video'
|
2023-07-11 09:21:13 +02:00
|
|
|
? generateWebVideoFilename(videoFile.resolution, videoFile.extname)
|
2023-04-21 14:55:10 +02:00
|
|
|
: generateHLSVideoFilename(videoFile.resolution)
|
|
|
|
|
|
|
|
return videoFile
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
2022-07-29 14:50:41 +02:00
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export async function removeHLSPlaylist (video: MVideoWithAllFiles) {
|
2022-07-29 14:50:41 +02:00
|
|
|
const hls = video.getHLSPlaylist()
|
|
|
|
if (!hls) return
|
|
|
|
|
2023-05-22 10:16:45 +02:00
|
|
|
const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
|
2022-07-29 14:50:41 +02:00
|
|
|
|
2023-05-22 10:16:45 +02:00
|
|
|
try {
|
|
|
|
await video.removeStreamingPlaylistFiles(hls)
|
|
|
|
await hls.destroy()
|
|
|
|
|
|
|
|
video.VideoStreamingPlaylists = video.VideoStreamingPlaylists.filter(p => p.id !== hls.id)
|
|
|
|
} finally {
|
|
|
|
videoFileMutexReleaser()
|
|
|
|
}
|
2022-07-29 14:50:41 +02:00
|
|
|
}
|
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export async function removeHLSFile (video: MVideoWithAllFiles, fileToDeleteId: number) {
|
2022-07-29 14:50:41 +02:00
|
|
|
const hls = video.getHLSPlaylist()
|
|
|
|
const files = hls.VideoFiles
|
|
|
|
|
|
|
|
if (files.length === 1) {
|
|
|
|
await removeHLSPlaylist(video)
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
2023-05-22 10:16:45 +02:00
|
|
|
const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
|
2022-07-29 14:50:41 +02:00
|
|
|
|
2023-05-22 10:16:45 +02:00
|
|
|
try {
|
|
|
|
const toDelete = files.find(f => f.id === fileToDeleteId)
|
|
|
|
await video.removeStreamingPlaylistVideoFile(video.getHLSPlaylist(), toDelete)
|
|
|
|
await toDelete.destroy()
|
|
|
|
|
|
|
|
hls.VideoFiles = hls.VideoFiles.filter(f => f.id !== toDelete.id)
|
|
|
|
} finally {
|
|
|
|
videoFileMutexReleaser()
|
|
|
|
}
|
2022-07-29 14:50:41 +02:00
|
|
|
|
|
|
|
return hls
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export async function removeAllWebVideoFiles (video: MVideoWithAllFiles) {
|
2023-05-22 10:16:45 +02:00
|
|
|
const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
|
|
|
|
|
|
|
|
try {
|
|
|
|
for (const file of video.VideoFiles) {
|
2023-07-11 09:21:13 +02:00
|
|
|
await video.removeWebVideoFile(file)
|
2023-05-22 10:16:45 +02:00
|
|
|
await file.destroy()
|
|
|
|
}
|
2022-07-29 14:50:41 +02:00
|
|
|
|
2023-05-22 10:16:45 +02:00
|
|
|
video.VideoFiles = []
|
|
|
|
} finally {
|
|
|
|
videoFileMutexReleaser()
|
|
|
|
}
|
2022-07-29 14:50:41 +02:00
|
|
|
|
|
|
|
return video
|
|
|
|
}
|
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export async function removeWebVideoFile (video: MVideoWithAllFiles, fileToDeleteId: number) {
|
2022-07-29 14:50:41 +02:00
|
|
|
const files = video.VideoFiles
|
|
|
|
|
|
|
|
if (files.length === 1) {
|
2023-07-11 09:21:13 +02:00
|
|
|
return removeAllWebVideoFiles(video)
|
2022-07-29 14:50:41 +02:00
|
|
|
}
|
|
|
|
|
2023-05-22 10:16:45 +02:00
|
|
|
const videoFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
|
|
|
|
try {
|
|
|
|
const toDelete = files.find(f => f.id === fileToDeleteId)
|
2023-07-11 09:21:13 +02:00
|
|
|
await video.removeWebVideoFile(toDelete)
|
2023-05-22 10:16:45 +02:00
|
|
|
await toDelete.destroy()
|
2022-07-29 14:50:41 +02:00
|
|
|
|
2023-05-22 10:16:45 +02:00
|
|
|
video.VideoFiles = files.filter(f => f.id !== toDelete.id)
|
|
|
|
} finally {
|
|
|
|
videoFileMutexReleaser()
|
|
|
|
}
|
2022-07-29 14:50:41 +02:00
|
|
|
|
|
|
|
return video
|
|
|
|
}
|
|
|
|
|
2023-04-21 14:55:10 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export async function buildFileMetadata (path: string, existingProbe?: FfprobeData) {
|
2023-04-21 14:55:10 +02:00
|
|
|
const metadata = existingProbe || await ffprobePromise(path)
|
|
|
|
|
|
|
|
return new VideoFileMetadata(metadata)
|
|
|
|
}
|
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export function getVideoFileMimeType (extname: string, isAudio: boolean) {
|
2023-10-03 12:20:11 +02:00
|
|
|
return isAudio && extname === '.mp4' // We use .mp4 even for audio file only
|
|
|
|
? MIMETYPES.AUDIO.EXT_MIMETYPE['.m4a']
|
|
|
|
: MIMETYPES.VIDEO.EXT_MIMETYPE[extname]
|
|
|
|
}
|
|
|
|
|
2023-04-21 14:55:10 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export async function createVideoSource (options: {
|
|
|
|
inputFilename: string
|
|
|
|
inputProbe: FfprobeData
|
|
|
|
inputPath: string
|
|
|
|
video: MVideoId
|
|
|
|
createdAt?: Date
|
|
|
|
}) {
|
|
|
|
const { inputFilename, inputPath, inputProbe, video, createdAt } = options
|
|
|
|
|
|
|
|
const videoSource = new VideoSourceModel({
|
|
|
|
inputFilename,
|
|
|
|
videoId: video.id,
|
|
|
|
createdAt
|
|
|
|
})
|
|
|
|
|
|
|
|
if (inputPath) {
|
|
|
|
const probe = inputProbe ?? await ffprobePromise(inputPath)
|
|
|
|
|
|
|
|
if (await isAudioFile(inputPath, probe)) {
|
|
|
|
videoSource.fps = 0
|
|
|
|
videoSource.resolution = VideoResolution.H_NOVIDEO
|
|
|
|
videoSource.width = 0
|
|
|
|
videoSource.height = 0
|
|
|
|
} else {
|
|
|
|
const dimensions = await getVideoStreamDimensionsInfo(inputPath, probe)
|
|
|
|
videoSource.fps = await getVideoStreamFPS(inputPath, probe)
|
|
|
|
videoSource.resolution = dimensions.resolution
|
|
|
|
videoSource.width = dimensions.width
|
|
|
|
videoSource.height = dimensions.height
|
|
|
|
}
|
|
|
|
|
|
|
|
videoSource.metadata = await buildFileMetadata(inputPath, probe)
|
|
|
|
videoSource.size = await getFileSize(inputPath)
|
|
|
|
}
|
2023-04-21 14:55:10 +02:00
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
return videoSource.save()
|
|
|
|
}
|
2023-04-21 14:55:10 +02:00
|
|
|
|
2024-03-15 15:47:18 +01:00
|
|
|
export async function saveNewOriginalFileIfNeeded (video: MVideo, videoFile: MVideoFile) {
|
|
|
|
if (!CONFIG.TRANSCODING.ORIGINAL_FILE.KEEP) return
|
|
|
|
|
|
|
|
const videoSource = await VideoSourceModel.loadLatest(video.id)
|
|
|
|
|
|
|
|
// Already have saved an original file
|
|
|
|
if (!videoSource || videoSource.keptOriginalFilename) return
|
|
|
|
videoSource.keptOriginalFilename = videoFile.filename
|
|
|
|
|
|
|
|
const lTags = loggerTagsFactory(video.uuid)
|
|
|
|
|
|
|
|
logger.info(`Storing original video file ${videoSource.keptOriginalFilename} of video ${video.name}`, lTags())
|
|
|
|
|
|
|
|
const sourcePath = VideoPathManager.Instance.getFSVideoFileOutputPath(video, videoFile)
|
|
|
|
|
|
|
|
if (CONFIG.OBJECT_STORAGE.ENABLED) {
|
|
|
|
const fileUrl = await storeOriginalVideoFile(sourcePath, videoSource.keptOriginalFilename)
|
|
|
|
await remove(sourcePath)
|
|
|
|
|
|
|
|
videoSource.storage = FileStorage.OBJECT_STORAGE
|
|
|
|
videoSource.fileUrl = fileUrl
|
|
|
|
} else {
|
|
|
|
const destinationPath = VideoPathManager.Instance.getFSOriginalVideoFilePath(videoSource.keptOriginalFilename)
|
|
|
|
await move(sourcePath, destinationPath)
|
|
|
|
|
|
|
|
videoSource.storage = FileStorage.FILE_SYSTEM
|
|
|
|
}
|
|
|
|
|
|
|
|
await videoSource.save()
|
|
|
|
|
|
|
|
// Delete previously kept video files
|
|
|
|
const allSources = await VideoSourceModel.listAll(video.id)
|
|
|
|
for (const oldSource of allSources) {
|
|
|
|
if (!oldSource.keptOriginalFilename) continue
|
|
|
|
if (oldSource.id === videoSource.id) continue
|
|
|
|
|
|
|
|
try {
|
|
|
|
await video.removeOriginalFile(oldSource)
|
|
|
|
} catch (err) {
|
|
|
|
logger.error('Cannot delete old original file ' + oldSource.keptOriginalFilename, { err, ...lTags() })
|
|
|
|
}
|
|
|
|
}
|
2022-07-29 14:50:41 +02:00
|
|
|
}
|
2024-07-23 16:38:51 +02:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export async function muxToMergeVideoFiles (options: {
|
2024-08-08 10:33:41 +02:00
|
|
|
video: MVideoThumbnail
|
2024-07-23 16:38:51 +02:00
|
|
|
videoFiles: MVideoFile[]
|
|
|
|
output: Writable
|
|
|
|
}) {
|
|
|
|
const { video, videoFiles, output } = options
|
|
|
|
|
|
|
|
const inputs: (string | Readable)[] = []
|
|
|
|
const tmpDestinations: string[] = []
|
|
|
|
|
|
|
|
try {
|
2024-08-08 10:33:41 +02:00
|
|
|
let maxResolution = 0
|
|
|
|
|
2024-07-23 16:38:51 +02:00
|
|
|
for (const videoFile of videoFiles) {
|
|
|
|
if (!videoFile) continue
|
|
|
|
|
2024-08-08 10:33:41 +02:00
|
|
|
maxResolution = Math.max(maxResolution, videoFile.resolution)
|
|
|
|
|
2024-07-23 16:38:51 +02:00
|
|
|
const { input, isTmpDestination } = await buildMuxInput(video, videoFile)
|
|
|
|
|
|
|
|
inputs.push(input)
|
|
|
|
|
|
|
|
if (isTmpDestination === true) tmpDestinations.push(input)
|
|
|
|
}
|
|
|
|
|
2024-08-08 10:33:41 +02:00
|
|
|
// Include cover to audio file?
|
|
|
|
const { coverPath, isTmpDestination } = maxResolution === 0
|
|
|
|
? await buildCoverInput(video)
|
|
|
|
: { coverPath: undefined, isTmpDestination: false }
|
|
|
|
|
|
|
|
if (coverPath && isTmpDestination) tmpDestinations.push(coverPath)
|
|
|
|
|
2024-07-23 16:38:51 +02:00
|
|
|
const inputsToLog = inputs.map(i => {
|
|
|
|
if (typeof i === 'string') return i
|
|
|
|
|
|
|
|
return 'ReadableStream'
|
|
|
|
})
|
|
|
|
|
|
|
|
logger.info(`Muxing files for video ${video.url}`, { inputs: inputsToLog, ...lTags(video.uuid) })
|
|
|
|
|
|
|
|
try {
|
2024-08-08 10:33:41 +02:00
|
|
|
await new FFmpegContainer(getFFmpegCommandWrapperOptions('vod')).mergeInputs({
|
|
|
|
inputs,
|
|
|
|
output,
|
|
|
|
logError: true,
|
|
|
|
|
|
|
|
// Include a cover if this is an audio file
|
|
|
|
coverPath
|
|
|
|
})
|
2024-07-23 16:38:51 +02:00
|
|
|
|
|
|
|
logger.info(`Mux ended for video ${video.url}`, { inputs: inputsToLog, ...lTags(video.uuid) })
|
|
|
|
} catch (err) {
|
|
|
|
const message = err?.message || ''
|
|
|
|
|
|
|
|
if (message.includes('Output stream closed')) {
|
|
|
|
logger.info(`Client aborted mux for video ${video.url}`, lTags(video.uuid))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.warn(`Cannot mux files of video ${video.url}`, { err, inputs: inputsToLog, ...lTags(video.uuid) })
|
|
|
|
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
for (const destination of tmpDestinations) {
|
|
|
|
await remove(destination)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function buildMuxInput (
|
|
|
|
video: MVideo,
|
|
|
|
videoFile: MVideoFile
|
|
|
|
): Promise<{ input: Readable, isTmpDestination: false } | { input: string, isTmpDestination: boolean }> {
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Remote
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if (video.remote === true) {
|
|
|
|
const timeout = REQUEST_TIMEOUTS.VIDEO_FILE
|
|
|
|
|
|
|
|
const videoSizeKB = videoFile.size / 1000
|
|
|
|
const bodyKBLimit = videoSizeKB + 0.1 * videoSizeKB
|
|
|
|
|
|
|
|
// FFmpeg doesn't support multiple input streams, so download the audio file on disk directly
|
|
|
|
if (videoFile.isAudio()) {
|
|
|
|
const destination = VideoPathManager.Instance.buildTMPDestination(videoFile.filename)
|
|
|
|
|
|
|
|
// > 1GB
|
|
|
|
if (bodyKBLimit > 1000 * 1000) {
|
|
|
|
throw new Error('Cannot download remote video file > 1GB')
|
|
|
|
}
|
|
|
|
|
|
|
|
await doRequestAndSaveToFile(videoFile.fileUrl, destination, { timeout, bodyKBLimit })
|
|
|
|
|
|
|
|
return { input: destination, isTmpDestination: true }
|
|
|
|
}
|
|
|
|
|
|
|
|
return { input: generateRequestStream(videoFile.fileUrl, { timeout, bodyKBLimit }), isTmpDestination: false }
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Local on FS
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if (videoFile.storage === FileStorage.FILE_SYSTEM) {
|
|
|
|
return { input: VideoPathManager.Instance.getFSVideoFileOutputPath(video, videoFile), isTmpDestination: false }
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Local on object storage
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// FFmpeg doesn't support multiple input streams, so download the audio file on disk directly
|
|
|
|
if (videoFile.hasAudio() && !videoFile.hasVideo()) {
|
|
|
|
const destination = VideoPathManager.Instance.buildTMPDestination(videoFile.filename)
|
|
|
|
|
|
|
|
if (videoFile.isHLS()) {
|
|
|
|
await makeHLSFileAvailable(video.getHLSPlaylist(), videoFile.filename, destination)
|
|
|
|
} else {
|
|
|
|
await makeWebVideoFileAvailable(videoFile.filename, destination)
|
|
|
|
}
|
|
|
|
|
|
|
|
return { input: destination, isTmpDestination: true }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (videoFile.isHLS()) {
|
|
|
|
const { stream } = await getHLSFileReadStream({
|
|
|
|
playlist: video.getHLSPlaylist().withVideo(video),
|
|
|
|
filename: videoFile.filename,
|
|
|
|
rangeHeader: undefined
|
|
|
|
})
|
|
|
|
|
|
|
|
return { input: stream, isTmpDestination: false }
|
|
|
|
}
|
|
|
|
|
|
|
|
// Web video
|
|
|
|
const { stream } = await getWebVideoFileReadStream({
|
|
|
|
filename: videoFile.filename,
|
|
|
|
rangeHeader: undefined
|
|
|
|
})
|
|
|
|
|
|
|
|
return { input: stream, isTmpDestination: false }
|
|
|
|
}
|
2024-08-08 10:33:41 +02:00
|
|
|
|
|
|
|
async function buildCoverInput (video: MVideoThumbnail) {
|
|
|
|
const preview = video.getPreview()
|
|
|
|
|
|
|
|
if (video.isOwned()) return { coverPath: preview?.getPath() }
|
|
|
|
|
|
|
|
if (preview.fileUrl) {
|
|
|
|
const destination = VideoPathManager.Instance.buildTMPDestination(preview.filename)
|
|
|
|
|
|
|
|
await doRequestAndSaveToFile(preview.fileUrl, destination)
|
|
|
|
|
|
|
|
return { coverPath: destination, isTmpDestination: true }
|
|
|
|
}
|
|
|
|
|
|
|
|
return { coverPath: undefined }
|
|
|
|
}
|