aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-import-videos.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-03 09:33:05 +0100
committerChocobozzz <me@florianbigard.com>2021-02-03 09:45:08 +0100
commitba5a8d89bbf049e4afc41543bcc072cccdb02669 (patch)
tree6cc6b2dca17745cc0824c7ad4515f3bc4883fa4a /server/tools/peertube-import-videos.ts
parent29f148a61381727a432c22a71c7a2b7cc23d9c9e (diff)
downloadPeerTube-ba5a8d89bbf049e4afc41543bcc072cccdb02669.tar.gz
PeerTube-ba5a8d89bbf049e4afc41543bcc072cccdb02669.tar.zst
PeerTube-ba5a8d89bbf049e4afc41543bcc072cccdb02669.zip
Update server dependencies
Diffstat (limited to 'server/tools/peertube-import-videos.ts')
-rw-r--r--server/tools/peertube-import-videos.ts44
1 files changed, 23 insertions, 21 deletions
diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts
index 65798adb4..d91767c29 100644
--- a/server/tools/peertube-import-videos.ts
+++ b/server/tools/peertube-import-videos.ts
@@ -45,22 +45,24 @@ command
45 .usage("[global options] [ -- youtube-dl options]") 45 .usage("[global options] [ -- youtube-dl options]")
46 .parse(process.argv) 46 .parse(process.argv)
47 47
48const log = getLogger(program['verbose']) 48const options = command.opts()
49
50const log = getLogger(options.verbose)
49 51
50getServerCredentials(command) 52getServerCredentials(command)
51 .then(({ url, username, password }) => { 53 .then(({ url, username, password }) => {
52 if (!program['targetUrl']) { 54 if (!options.targetUrl) {
53 exitError('--target-url field is required.') 55 exitError('--target-url field is required.')
54 } 56 }
55 57
56 try { 58 try {
57 accessSync(program['tmpdir'], constants.R_OK | constants.W_OK) 59 accessSync(options.tmpdir, constants.R_OK | constants.W_OK)
58 } catch (e) { 60 } catch (e) {
59 exitError('--tmpdir %s: directory does not exist or is not accessible', program['tmpdir']) 61 exitError('--tmpdir %s: directory does not exist or is not accessible', options.tmpdir)
60 } 62 }
61 63
62 url = normalizeTargetUrl(url) 64 url = normalizeTargetUrl(url)
63 program['targetUrl'] = normalizeTargetUrl(program['targetUrl']) 65 options.targetUrl = normalizeTargetUrl(options.targetUrl)
64 66
65 const user = { username, password } 67 const user = { username, password }
66 68
@@ -76,7 +78,7 @@ async function run (url: string, user: UserInfo) {
76 78
77 const youtubeDL = await safeGetYoutubeDL() 79 const youtubeDL = await safeGetYoutubeDL()
78 80
79 let info = await getYoutubeDLInfo(youtubeDL, program['targetUrl'], command.args) 81 let info = await getYoutubeDLInfo(youtubeDL, options.targetUrl, command.args)
80 82
81 if (!Array.isArray(info)) info = [ info ] 83 if (!Array.isArray(info)) info = [ info ]
82 84
@@ -92,10 +94,10 @@ async function run (url: string, user: UserInfo) {
92 let infoArray: any[] 94 let infoArray: any[]
93 95
94 infoArray = [].concat(info) 96 infoArray = [].concat(info)
95 if (program['first']) { 97 if (options.first) {
96 infoArray = infoArray.slice(0, program['first']) 98 infoArray = infoArray.slice(0, options.first)
97 } else if (program['last']) { 99 } else if (options.last) {
98 infoArray = infoArray.slice(-program['last']) 100 infoArray = infoArray.slice(-options.last)
99 } 101 }
100 // Normalize utf8 fields 102 // Normalize utf8 fields
101 infoArray = infoArray.map(i => normalizeObject(i)) 103 infoArray = infoArray.map(i => normalizeObject(i))
@@ -104,12 +106,12 @@ async function run (url: string, user: UserInfo) {
104 106
105 for (const [ index, info ] of infoArray.entries()) { 107 for (const [ index, info ] of infoArray.entries()) {
106 try { 108 try {
107 if (index > 0 && program['waitInterval']) { 109 if (index > 0 && options.waitInterval) {
108 log.info("Wait for %d seconds before continuing.", program['waitInterval'] / 1000) 110 log.info("Wait for %d seconds before continuing.", options.waitInterval / 1000)
109 await new Promise(res => setTimeout(res, program['waitInterval'])) 111 await new Promise(res => setTimeout(res, options.waitInterval))
110 } 112 }
111 await processVideo({ 113 await processVideo({
112 cwd: program['tmpdir'], 114 cwd: options.tmpdir,
113 url, 115 url,
114 user, 116 user,
115 youtubeInfo: info 117 youtubeInfo: info
@@ -119,7 +121,7 @@ async function run (url: string, user: UserInfo) {
119 } 121 }
120 } 122 }
121 123
122 log.info('Video/s for user %s imported: %s', user.username, program['targetUrl']) 124 log.info('Video/s for user %s imported: %s', user.username, options.targetUrl)
123 process.exit(0) 125 process.exit(0)
124} 126}
125 127
@@ -137,14 +139,14 @@ async function processVideo (parameters: {
137 log.debug('Fetched object.', videoInfo) 139 log.debug('Fetched object.', videoInfo)
138 140
139 const originallyPublishedAt = buildOriginallyPublishedAt(videoInfo) 141 const originallyPublishedAt = buildOriginallyPublishedAt(videoInfo)
140 if (program['since'] && originallyPublishedAt && originallyPublishedAt.getTime() < program['since'].getTime()) { 142 if (options.since && originallyPublishedAt && originallyPublishedAt.getTime() < options.since.getTime()) {
141 log.info('Video "%s" has been published before "%s", don\'t upload it.\n', 143 log.info('Video "%s" has been published before "%s", don\'t upload it.\n',
142 videoInfo.title, formatDate(program['since'])) 144 videoInfo.title, formatDate(options.since))
143 return 145 return
144 } 146 }
145 if (program['until'] && originallyPublishedAt && originallyPublishedAt.getTime() > program['until'].getTime()) { 147 if (options.until && originallyPublishedAt && originallyPublishedAt.getTime() > options.until.getTime()) {
146 log.info('Video "%s" has been published after "%s", don\'t upload it.\n', 148 log.info('Video "%s" has been published after "%s", don\'t upload it.\n',
147 videoInfo.title, formatDate(program['until'])) 149 videoInfo.title, formatDate(options.until))
148 return 150 return
149 } 151 }
150 152
@@ -161,11 +163,11 @@ async function processVideo (parameters: {
161 163
162 log.info('Downloading video "%s"...', videoInfo.title) 164 log.info('Downloading video "%s"...', videoInfo.title)
163 165
164 const options = [ '-f', getYoutubeDLVideoFormat(), ...command.args, '-o', path ] 166 const youtubeDLOptions = [ '-f', getYoutubeDLVideoFormat(), ...command.args, '-o', path ]
165 try { 167 try {
166 const youtubeDL = await safeGetYoutubeDL() 168 const youtubeDL = await safeGetYoutubeDL()
167 const youtubeDLExec = promisify(youtubeDL.exec).bind(youtubeDL) 169 const youtubeDLExec = promisify(youtubeDL.exec).bind(youtubeDL)
168 const output = await youtubeDLExec(videoInfo.url, options, processOptions) 170 const output = await youtubeDLExec(videoInfo.url, youtubeDLOptions, processOptions)
169 log.info(output.join('\n')) 171 log.info(output.join('\n'))
170 await uploadVideoOnPeerTube({ 172 await uploadVideoOnPeerTube({
171 cwd, 173 cwd,