aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers')
-rw-r--r--server/lib/job-queue/handlers/video-import.ts29
1 files changed, 15 insertions, 14 deletions
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index 2f74e9fbd..cb79725aa 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -42,8 +42,17 @@ import { generateVideoMiniature } from '../../thumbnail'
42async function processVideoImport (job: Job) { 42async function processVideoImport (job: Job) {
43 const payload = job.data as VideoImportPayload 43 const payload = job.data as VideoImportPayload
44 44
45 if (payload.type === 'youtube-dl') return processYoutubeDLImport(job, payload) 45 const videoImport = await getVideoImportOrDie(payload.videoImportId)
46 if (payload.type === 'magnet-uri' || payload.type === 'torrent-file') return processTorrentImport(job, payload) 46 if (videoImport.state === VideoImportState.CANCELLED) {
47 logger.info('Do not process import since it has been cancelled', { payload })
48 return
49 }
50
51 videoImport.state = VideoImportState.PROCESSING
52 await videoImport.save()
53
54 if (payload.type === 'youtube-dl') return processYoutubeDLImport(job, videoImport, payload)
55 if (payload.type === 'magnet-uri' || payload.type === 'torrent-file') return processTorrentImport(job, videoImport, payload)
47} 56}
48 57
49// --------------------------------------------------------------------------- 58// ---------------------------------------------------------------------------
@@ -54,15 +63,11 @@ export {
54 63
55// --------------------------------------------------------------------------- 64// ---------------------------------------------------------------------------
56 65
57async function processTorrentImport (job: Job, payload: VideoImportTorrentPayload) { 66async function processTorrentImport (job: Job, videoImport: MVideoImportDefault, payload: VideoImportTorrentPayload) {
58 logger.info('Processing torrent video import in job %d.', job.id) 67 logger.info('Processing torrent video import in job %d.', job.id)
59 68
60 const videoImport = await getVideoImportOrDie(payload.videoImportId) 69 const options = { type: payload.type, videoImportId: payload.videoImportId }
61 70
62 const options = {
63 type: payload.type,
64 videoImportId: payload.videoImportId
65 }
66 const target = { 71 const target = {
67 torrentName: videoImport.torrentName ? getSecureTorrentName(videoImport.torrentName) : undefined, 72 torrentName: videoImport.torrentName ? getSecureTorrentName(videoImport.torrentName) : undefined,
68 uri: videoImport.magnetUri 73 uri: videoImport.magnetUri
@@ -70,14 +75,10 @@ async function processTorrentImport (job: Job, payload: VideoImportTorrentPayloa
70 return processFile(() => downloadWebTorrentVideo(target, VIDEO_IMPORT_TIMEOUT), videoImport, options) 75 return processFile(() => downloadWebTorrentVideo(target, VIDEO_IMPORT_TIMEOUT), videoImport, options)
71} 76}
72 77
73async function processYoutubeDLImport (job: Job, payload: VideoImportYoutubeDLPayload) { 78async function processYoutubeDLImport (job: Job, videoImport: MVideoImportDefault, payload: VideoImportYoutubeDLPayload) {
74 logger.info('Processing youtubeDL video import in job %d.', job.id) 79 logger.info('Processing youtubeDL video import in job %d.', job.id)
75 80
76 const videoImport = await getVideoImportOrDie(payload.videoImportId) 81 const options = { type: payload.type, videoImportId: videoImport.id }
77 const options = {
78 type: payload.type,
79 videoImportId: videoImport.id
80 }
81 82
82 const youtubeDL = new YoutubeDLWrapper(videoImport.targetUrl, ServerConfigManager.Instance.getEnabledResolutions('vod')) 83 const youtubeDL = new YoutubeDLWrapper(videoImport.targetUrl, ServerConfigManager.Instance.getEnabledResolutions('vod'))
83 84