aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-import-videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/peertube-import-videos.ts')
-rw-r--r--server/tools/peertube-import-videos.ts25
1 files changed, 14 insertions, 11 deletions
diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts
index 915995031..b3f57a8f9 100644
--- a/server/tools/peertube-import-videos.ts
+++ b/server/tools/peertube-import-videos.ts
@@ -11,9 +11,9 @@ import { promisify } from 'util'
11import { advancedVideosSearch, getClient, getVideoCategories, login, uploadVideo } from '../../shared/extra-utils/index' 11import { advancedVideosSearch, getClient, getVideoCategories, login, uploadVideo } from '../../shared/extra-utils/index'
12import { sha256 } from '../helpers/core-utils' 12import { sha256 } from '../helpers/core-utils'
13import { doRequestAndSaveToFile } from '../helpers/requests' 13import { doRequestAndSaveToFile } from '../helpers/requests'
14import { buildOriginallyPublishedAt, getYoutubeDLVideoFormat, safeGetYoutubeDL } from '../helpers/youtube-dl'
15import { CONSTRAINTS_FIELDS } from '../initializers/constants' 14import { CONSTRAINTS_FIELDS } from '../initializers/constants'
16import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getLogger, getServerCredentials } from './cli' 15import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getLogger, getServerCredentials } from './cli'
16import { YoutubeDL } from '@server/helpers/youtube-dl'
17 17
18type UserInfo = { 18type UserInfo = {
19 username: string 19 username: string
@@ -74,9 +74,9 @@ async function run (url: string, user: UserInfo) {
74 user.password = await promptPassword() 74 user.password = await promptPassword()
75 } 75 }
76 76
77 const youtubeDL = await safeGetYoutubeDL() 77 const youtubeDLBinary = await YoutubeDL.safeGetYoutubeDL()
78 78
79 let info = await getYoutubeDLInfo(youtubeDL, options.targetUrl, command.args) 79 let info = await getYoutubeDLInfo(youtubeDLBinary, options.targetUrl, command.args)
80 80
81 if (!Array.isArray(info)) info = [ info ] 81 if (!Array.isArray(info)) info = [ info ]
82 82
@@ -86,7 +86,7 @@ async function run (url: string, user: UserInfo) {
86 if (uploadsObject) { 86 if (uploadsObject) {
87 console.log('Fixing URL to %s.', uploadsObject.url) 87 console.log('Fixing URL to %s.', uploadsObject.url)
88 88
89 info = await getYoutubeDLInfo(youtubeDL, uploadsObject.url, command.args) 89 info = await getYoutubeDLInfo(youtubeDLBinary, uploadsObject.url, command.args)
90 } 90 }
91 91
92 let infoArray: any[] 92 let infoArray: any[]
@@ -130,13 +130,14 @@ async function processVideo (parameters: {
130 youtubeInfo: any 130 youtubeInfo: any
131}) { 131}) {
132 const { youtubeInfo, cwd, url, user } = parameters 132 const { youtubeInfo, cwd, url, user } = parameters
133 const youtubeDL = new YoutubeDL('', [])
133 134
134 log.debug('Fetching object.', youtubeInfo) 135 log.debug('Fetching object.', youtubeInfo)
135 136
136 const videoInfo = await fetchObject(youtubeInfo) 137 const videoInfo = await fetchObject(youtubeInfo)
137 log.debug('Fetched object.', videoInfo) 138 log.debug('Fetched object.', videoInfo)
138 139
139 const originallyPublishedAt = buildOriginallyPublishedAt(videoInfo) 140 const originallyPublishedAt = youtubeDL.buildOriginallyPublishedAt(videoInfo)
140 if (options.since && originallyPublishedAt && originallyPublishedAt.getTime() < options.since.getTime()) { 141 if (options.since && originallyPublishedAt && originallyPublishedAt.getTime() < options.since.getTime()) {
141 log.info('Video "%s" has been published before "%s", don\'t upload it.\n', 142 log.info('Video "%s" has been published before "%s", don\'t upload it.\n',
142 videoInfo.title, formatDate(options.since)) 143 videoInfo.title, formatDate(options.since))
@@ -161,13 +162,14 @@ async function processVideo (parameters: {
161 162
162 log.info('Downloading video "%s"...', videoInfo.title) 163 log.info('Downloading video "%s"...', videoInfo.title)
163 164
164 const youtubeDLOptions = [ '-f', getYoutubeDLVideoFormat(), ...command.args, '-o', path ] 165 const youtubeDLOptions = [ '-f', youtubeDL.getYoutubeDLVideoFormat(), ...command.args, '-o', path ]
165 try { 166 try {
166 const youtubeDL = await safeGetYoutubeDL() 167 const youtubeDLBinary = await YoutubeDL.safeGetYoutubeDL()
167 const youtubeDLExec = promisify(youtubeDL.exec).bind(youtubeDL) 168 const youtubeDLExec = promisify(youtubeDLBinary.exec).bind(youtubeDLBinary)
168 const output = await youtubeDLExec(videoInfo.url, youtubeDLOptions, processOptions) 169 const output = await youtubeDLExec(videoInfo.url, youtubeDLOptions, processOptions)
169 log.info(output.join('\n')) 170 log.info(output.join('\n'))
170 await uploadVideoOnPeerTube({ 171 await uploadVideoOnPeerTube({
172 youtubeDL,
171 cwd, 173 cwd,
172 url, 174 url,
173 user, 175 user,
@@ -180,13 +182,14 @@ async function processVideo (parameters: {
180} 182}
181 183
182async function uploadVideoOnPeerTube (parameters: { 184async function uploadVideoOnPeerTube (parameters: {
185 youtubeDL: YoutubeDL
183 videoInfo: any 186 videoInfo: any
184 videoPath: string 187 videoPath: string
185 cwd: string 188 cwd: string
186 url: string 189 url: string
187 user: { username: string, password: string } 190 user: { username: string, password: string }
188}) { 191}) {
189 const { videoInfo, videoPath, cwd, url, user } = parameters 192 const { youtubeDL, videoInfo, videoPath, cwd, url, user } = parameters
190 193
191 const category = await getCategory(videoInfo.categories, url) 194 const category = await getCategory(videoInfo.categories, url)
192 const licence = getLicence(videoInfo.license) 195 const licence = getLicence(videoInfo.license)
@@ -205,7 +208,7 @@ async function uploadVideoOnPeerTube (parameters: {
205 await doRequestAndSaveToFile(videoInfo.thumbnail, thumbnailfile) 208 await doRequestAndSaveToFile(videoInfo.thumbnail, thumbnailfile)
206 } 209 }
207 210
208 const originallyPublishedAt = buildOriginallyPublishedAt(videoInfo) 211 const originallyPublishedAt = youtubeDL.buildOriginallyPublishedAt(videoInfo)
209 212
210 const defaultAttributes = { 213 const defaultAttributes = {
211 name: truncate(videoInfo.title, { 214 name: truncate(videoInfo.title, {
@@ -304,7 +307,7 @@ function fetchObject (info: any) {
304 const url = buildUrl(info) 307 const url = buildUrl(info)
305 308
306 return new Promise<any>(async (res, rej) => { 309 return new Promise<any>(async (res, rej) => {
307 const youtubeDL = await safeGetYoutubeDL() 310 const youtubeDL = await YoutubeDL.safeGetYoutubeDL()
308 youtubeDL.getInfo(url, undefined, processOptions, (err, videoInfo) => { 311 youtubeDL.getInfo(url, undefined, processOptions, (err, videoInfo) => {
309 if (err) return rej(err) 312 if (err) return rej(err)
310 313