aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-15 14:16:40 +0200
committerChocobozzz <me@florianbigard.com>2020-04-15 14:16:40 +0200
commit62068f4153cb1e67fe30a7f92947c3f2ec058c73 (patch)
tree9253408bc4e96f3dac4afe230eafecc1356c49d8 /server/controllers
parentf757be65b8dc2d3b286b5d8b22c64637d7bc2fb8 (diff)
parent652c64165b3d8d1c5d5fc646c29e5cd1c82a3330 (diff)
downloadPeerTube-62068f4153cb1e67fe30a7f92947c3f2ec058c73.tar.gz
PeerTube-62068f4153cb1e67fe30a7f92947c3f2ec058c73.tar.zst
PeerTube-62068f4153cb1e67fe30a7f92947c3f2ec058c73.zip
Merge branch 'pr/2629' into develop
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/videos/import.ts30
1 files changed, 29 insertions, 1 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index da0832258..fb9d73140 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -3,11 +3,13 @@ import * as magnetUtil from 'magnet-uri'
3import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' 3import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
4import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' 4import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares'
5import { MIMETYPES } from '../../../initializers/constants' 5import { MIMETYPES } from '../../../initializers/constants'
6import { getYoutubeDLInfo, YoutubeDLInfo } from '../../../helpers/youtube-dl' 6import { getYoutubeDLInfo, YoutubeDLInfo, getYoutubeDLSubs } from '../../../helpers/youtube-dl'
7import { createReqFiles } from '../../../helpers/express-utils' 7import { createReqFiles } from '../../../helpers/express-utils'
8import { logger } from '../../../helpers/logger' 8import { logger } from '../../../helpers/logger'
9import { VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared' 9import { VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared'
10import { VideoModel } from '../../../models/video/video' 10import { VideoModel } from '../../../models/video/video'
11import { VideoCaptionModel } from '../../../models/video/video-caption'
12import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
11import { getVideoActivityPubUrl } from '../../../lib/activitypub' 13import { getVideoActivityPubUrl } from '../../../lib/activitypub'
12import { TagModel } from '../../../models/video/tag' 14import { TagModel } from '../../../models/video/tag'
13import { VideoImportModel } from '../../../models/video/video-import' 15import { VideoImportModel } from '../../../models/video/video-import'
@@ -28,6 +30,7 @@ import {
28 MThumbnail, 30 MThumbnail,
29 MUser, 31 MUser,
30 MVideoAccountDefault, 32 MVideoAccountDefault,
33 MVideoCaptionVideo,
31 MVideoTag, 34 MVideoTag,
32 MVideoThumbnailAccountDefault, 35 MVideoThumbnailAccountDefault,
33 MVideoWithBlacklistLight 36 MVideoWithBlacklistLight
@@ -136,6 +139,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
136 const targetUrl = body.targetUrl 139 const targetUrl = body.targetUrl
137 const user = res.locals.oauth.token.User 140 const user = res.locals.oauth.token.User
138 141
142 // Get video infos
139 let youtubeDLInfo: YoutubeDLInfo 143 let youtubeDLInfo: YoutubeDLInfo
140 try { 144 try {
141 youtubeDLInfo = await getYoutubeDLInfo(targetUrl) 145 youtubeDLInfo = await getYoutubeDLInfo(targetUrl)
@@ -168,6 +172,30 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
168 user 172 user
169 }) 173 })
170 174
175 // Get video subtitles
176 try {
177 const subtitles = await getYoutubeDLSubs(targetUrl)
178
179 logger.info('Will create %s subtitles from youtube import %s.', subtitles.length, targetUrl)
180
181 for (const subtitle of subtitles) {
182 const videoCaption = new VideoCaptionModel({
183 videoId: video.id,
184 language: subtitle.language
185 }) as MVideoCaptionVideo
186 videoCaption.Video = video
187
188 // Move physical file
189 await moveAndProcessCaptionFile(subtitle, videoCaption)
190
191 await sequelizeTypescript.transaction(async t => {
192 await VideoCaptionModel.insertOrReplaceLanguage(video.id, subtitle.language, null, t)
193 })
194 }
195 } catch (err) {
196 logger.warn('Cannot get video subtitles.', { err })
197 }
198
171 // Create job to import the video 199 // Create job to import the video
172 const payload = { 200 const payload = {
173 type: 'youtube-dl' as 'youtube-dl', 201 type: 'youtube-dl' as 'youtube-dl',