import { cleanUpReqFiles, createReqFiles } from '../../../helpers/express-utils'
import { logger } from '../../../helpers/logger'
import { getSecureTorrentName } from '../../../helpers/utils'
-import { YoutubeDL, YoutubeDLInfo } from '../../../helpers/youtube-dl'
+import { YoutubeDLWrapper, YoutubeDLInfo } from '../../../helpers/youtube-dl'
import { CONFIG } from '../../../initializers/config'
import { MIMETYPES } from '../../../initializers/constants'
import { sequelizeTypescript } from '../../../initializers/database'
import { VideoModel } from '../../../models/video/video'
import { VideoCaptionModel } from '../../../models/video/video-caption'
import { VideoImportModel } from '../../../models/video/video-import'
+import { Hooks } from '@server/lib/plugins/hooks'
const auditLogger = auditLoggerFactory('video-imports')
const videoImportsRouter = express.Router()
videoName = result.name
}
- const video = buildVideo(res.locals.videoChannel.id, body, { name: videoName })
+ const video = await buildVideo(res.locals.videoChannel.id, body, { name: videoName })
const thumbnailModel = await processThumbnail(req, video)
const previewModel = await processPreview(req, video)
const targetUrl = body.targetUrl
const user = res.locals.oauth.token.User
- const youtubeDL = new YoutubeDL(targetUrl, ServerConfigManager.Instance.getEnabledResolutions('vod'))
+ const youtubeDL = new YoutubeDLWrapper(targetUrl, ServerConfigManager.Instance.getEnabledResolutions('vod'))
// Get video infos
let youtubeDLInfo: YoutubeDLInfo
try {
- youtubeDLInfo = await youtubeDL.getYoutubeDLInfo()
+ youtubeDLInfo = await youtubeDL.getInfoForDownload()
} catch (err) {
logger.info('Cannot fetch information from import for URL %s.', targetUrl, { err })
})
}
- const video = buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo)
+ const video = await buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo)
// Process video thumbnail from request.files
let thumbnailModel = await processThumbnail(req, video)
return res.json(videoImport.toFormattedJSON()).end()
}
-function buildVideo (channelId: number, body: VideoImportCreate, importData: YoutubeDLInfo): MVideoThumbnail {
- const videoData = {
+async function buildVideo (channelId: number, body: VideoImportCreate, importData: YoutubeDLInfo): Promise<MVideoThumbnail> {
+ let videoData = {
name: body.name || importData.name || 'Unknown name',
remote: false,
category: body.category || importData.category,
? new Date(body.originallyPublishedAt)
: importData.originallyPublishedAt
}
+
+ videoData = await Hooks.wrapObject(
+ videoData,
+ body.targetUrl
+ ? 'filter:api.video.import-url.video-attribute.result'
+ : 'filter:api.video.import-torrent.video-attribute.result'
+ )
+
const video = new VideoModel(videoData)
video.url = getLocalVideoActivityPubUrl(video)
return isArray(name) ? name[0] : name
}
-async function processYoutubeSubtitles (youtubeDL: YoutubeDL, targetUrl: string, videoId: number) {
+async function processYoutubeSubtitles (youtubeDL: YoutubeDLWrapper, targetUrl: string, videoId: number) {
try {
- const subtitles = await youtubeDL.getYoutubeDLSubs()
+ const subtitles = await youtubeDL.getSubtitles()
logger.info('Will create %s subtitles from youtube import %s.', subtitles.length, targetUrl)