diff options
author | kimsible <kimsible@users.noreply.github.com> | 2020-04-11 04:24:42 +0200 |
---|---|---|
committer | kimsible <kimsible@users.noreply.github.com> | 2020-04-14 14:39:30 +0200 |
commit | 50ad0a1c1699fb1799c9ba2a99bf888894f88df4 (patch) | |
tree | 52279eaa419c94b96b1bf9169d396270e6146aff /server/controllers | |
parent | 5def04e17f1df09a708622afe634ccac256eab86 (diff) | |
download | PeerTube-50ad0a1c1699fb1799c9ba2a99bf888894f88df4.tar.gz PeerTube-50ad0a1c1699fb1799c9ba2a99bf888894f88df4.tar.zst PeerTube-50ad0a1c1699fb1799c9ba2a99bf888894f88df4.zip |
Add getSubs to YoutubeDL video import
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/videos/import.ts | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index da0832258..e9b9d68d7 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' | |||
3 | import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' | 3 | import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' |
4 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' | 4 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' |
5 | import { MIMETYPES } from '../../../initializers/constants' | 5 | import { MIMETYPES } from '../../../initializers/constants' |
6 | import { getYoutubeDLInfo, YoutubeDLInfo } from '../../../helpers/youtube-dl' | 6 | import { getYoutubeDLInfo, YoutubeDLInfo, getYoutubeDLSubs } from '../../../helpers/youtube-dl' |
7 | import { createReqFiles } from '../../../helpers/express-utils' | 7 | import { createReqFiles } from '../../../helpers/express-utils' |
8 | import { logger } from '../../../helpers/logger' | 8 | import { logger } from '../../../helpers/logger' |
9 | import { VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared' | 9 | import { VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '../../../../shared' |
10 | import { VideoModel } from '../../../models/video/video' | 10 | import { VideoModel } from '../../../models/video/video' |
11 | import { VideoCaptionModel } from '../../../models/video/video-caption' | ||
12 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' | ||
11 | import { getVideoActivityPubUrl } from '../../../lib/activitypub' | 13 | import { getVideoActivityPubUrl } from '../../../lib/activitypub' |
12 | import { TagModel } from '../../../models/video/tag' | 14 | import { TagModel } from '../../../models/video/tag' |
13 | import { VideoImportModel } from '../../../models/video/video-import' | 15 | import { 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,29 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) | |||
168 | user | 172 | user |
169 | }) | 173 | }) |
170 | 174 | ||
175 | |||
176 | // Get video subtitles | ||
177 | try { | ||
178 | const subtitles = await getYoutubeDLSubs(targetUrl) | ||
179 | |||
180 | for (const subtitle of subtitles) { | ||
181 | const videoCaption = new VideoCaptionModel({ | ||
182 | videoId: video.id, | ||
183 | language: subtitle.language | ||
184 | }) as MVideoCaptionVideo | ||
185 | videoCaption.Video = video | ||
186 | |||
187 | // Move physical file | ||
188 | await moveAndProcessCaptionFile(subtitle, videoCaption) | ||
189 | |||
190 | await sequelizeTypescript.transaction(async t => { | ||
191 | await VideoCaptionModel.insertOrReplaceLanguage(video.id, subtitle.language, null, t) | ||
192 | }) | ||
193 | } | ||
194 | } catch (err) { | ||
195 | logger.warn('Cannot get video subtitles.', { err }) | ||
196 | } | ||
197 | |||
171 | // Create job to import the video | 198 | // Create job to import the video |
172 | const payload = { | 199 | const payload = { |
173 | type: 'youtube-dl' as 'youtube-dl', | 200 | type: 'youtube-dl' as 'youtube-dl', |