import { CONFIG } from '../initializers'
import { dirname, join } from 'path'
-async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout?: number) {
+async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout: number) {
const id = target.magnetUri || target.torrentName
let timer
torrent.on('error', err => rej(err))
- if (timeout) {
- timer = setTimeout(async () => {
- return safeWebtorrentDestroy(webtorrent, torrentId, file ? { directoryPath, filepath: file.path } : undefined, target.torrentName)
- .then(() => rej(new Error('Webtorrent download timeout.')))
- }, timeout)
- }
+ timer = setTimeout(async () => {
+ return safeWebtorrentDestroy(webtorrent, torrentId, file ? { directoryPath, filepath: file.path } : undefined, target.torrentName)
+ .then(() => rej(new Error('Webtorrent download timeout.')))
+ }, timeout)
})
}
import { generateVideoTmpPath } from './utils'
import { join } from 'path'
import { root } from './core-utils'
-import { ensureDir, writeFile } from 'fs-extra'
+import { ensureDir, writeFile, remove } from 'fs-extra'
import * as request from 'request'
import { createWriteStream } from 'fs'
})
}
-function downloadYoutubeDLVideo (url: string) {
+function downloadYoutubeDLVideo (url: string, timeout: number) {
const path = generateVideoTmpPath(url)
+ let timer
logger.info('Importing youtubeDL video %s', url)
return new Promise<string>(async (res, rej) => {
const youtubeDL = await safeGetYoutubeDL()
youtubeDL.exec(url, options, processOptions, err => {
- if (err) return rej(err)
+ clearTimeout(timer)
+
+ if (err) {
+ remove(path)
+ .catch(err => logger.error('Cannot delete path on YoutubeDL error.', { err }))
+
+ return rej(err)
+ }
return res(path)
})
+
+ timer = setTimeout(async () => {
+ await remove(path)
+
+ return rej(new Error('YoutubeDL download timeout.'))
+ }, timeout)
})
}
'activitypub-follow': 60000 * 10, // 10 minutes
'video-file-import': 1000 * 3600, // 1 hour
'video-file': 1000 * 3600 * 48, // 2 days, transcoding could be long
- 'video-import': 1000 * 3600, // 1 hour
+ 'video-import': 1000 * 3600 * 2, // hours
'email': 60000 * 10, // 10 minutes
'videos-views': undefined // Unlimited
}
const CRAWL_REQUEST_CONCURRENCY = 1 // How many requests in parallel to fetch remote data (likes, shares...)
const JOB_REQUEST_TIMEOUT = 3000 // 3 seconds
const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 // 2 days
+const VIDEO_IMPORT_TIMEOUT = 1000 * 3600 // 1 hour
// 1 hour
let SCHEDULER_INTERVALS_MS = {
TORRENT_MIMETYPE_EXT,
STATIC_MAX_AGE,
STATIC_PATHS,
+ VIDEO_IMPORT_TIMEOUT,
ACTIVITY_PUB,
ACTIVITY_PUB_ACTOR_TYPES,
THUMBNAILS_SIZE,
import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
import { extname, join } from 'path'
import { VideoFileModel } from '../../../models/video/video-file'
-import { CONFIG, sequelizeTypescript } from '../../../initializers'
+import { CONFIG, sequelizeTypescript, VIDEO_IMPORT_TIMEOUT } from '../../../initializers'
import { doRequestAndSaveToFile } from '../../../helpers/requests'
import { VideoState } from '../../../../shared'
import { JobQueue } from '../index'
torrentName: videoImport.torrentName ? getSecureTorrentName(videoImport.torrentName) : undefined,
magnetUri: videoImport.magnetUri
}
- return processFile(() => downloadWebTorrentVideo(target), videoImport, options)
+ return processFile(() => downloadWebTorrentVideo(target, VIDEO_IMPORT_TIMEOUT), videoImport, options)
}
async function processYoutubeDLImport (job: Bull.Job, payload: VideoImportYoutubeDLPayload) {
generatePreview: false
}
- return processFile(() => downloadYoutubeDLVideo(videoImport.targetUrl), videoImport, options)
+ return processFile(() => downloadYoutubeDLVideo(videoImport.targetUrl, VIDEO_IMPORT_TIMEOUT), videoImport, options)
}
async function getVideoImportOrDie (videoImportId: number) {
import { AbstractScheduler } from './abstract-scheduler'
-import { CONFIG, JOB_TTL, REDUNDANCY } from '../../initializers'
+import { CONFIG, REDUNDANCY, VIDEO_IMPORT_TIMEOUT } from '../../initializers'
import { logger } from '../../helpers/logger'
import { VideosRedundancy } from '../../../shared/models/redundancy'
import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
import { rename } from 'fs-extra'
import { getServerActor } from '../../helpers/utils'
import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send'
-import { VideoModel } from '../../models/video/video'
import { getVideoCacheFileActivityPubUrl } from '../activitypub/url'
import { removeVideoRedundancy } from '../redundancy'
import { getOrCreateVideoAndAccountAndChannel } from '../activitypub'
const { baseUrlHttp, baseUrlWs } = video.getBaseUrls()
const magnetUri = video.generateMagnetUri(file, baseUrlHttp, baseUrlWs)
- const tmpPath = await downloadWebTorrentVideo({ magnetUri }, JOB_TTL['video-import'])
+ const tmpPath = await downloadWebTorrentVideo({ magnetUri }, VIDEO_IMPORT_TIMEOUT)
const destPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(file))
await rename(tmpPath, destPath)