]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tools/peertube-upload.ts
Allow specification of Channel ID in peertube-upload.js
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-upload.ts
index 1f871e660ff555e7a59b2be1f21365822bc0c425..4034b7e38051102ff4aeacdc6c74ca3270bb4c92 100644 (file)
@@ -15,6 +15,7 @@ program
   .option('-P, --privacy <privacy_number>', 'Privacy')
   .option('-N, --nsfw', 'Video is Not Safe For Work')
   .option('-c, --category <category_number>', 'Category number')
+  .option('-C, --channel-id <channel_id>', 'Channel ID')
   .option('-m, --comments-enabled', 'Enable comments')
   .option('-l, --licence <licence_number>', 'Licence number')
   .option('-L, --language <language_code>', 'Language ISO 639 code (fr or en...)')
@@ -75,7 +76,10 @@ getSettings()
       process.exit(-1)
     }
 
-    run().catch(err => console.error(err))
+    run().catch(err => {
+      console.error(err)
+      process.exit(-1)
+    })
   })
 
 async function run () {
@@ -90,14 +94,19 @@ async function run () {
     password: program[ 'password' ]
   }
 
-  const res2 = await login(program[ 'url' ], client, user)
-  const accessToken = res2.body.access_token
+  let accessToken: string
+  try {
+    const res2 = await login(program[ 'url' ], client, user)
+    accessToken = res2.body.access_token
+  } catch (err) {
+    throw new Error('Cannot authenticate. Please check your username/password.')
+  }
 
   await access(program[ 'file' ], constants.F_OK)
 
   console.log('Uploading %s video...', program[ 'videoName' ])
 
-  const videoAttributes = {
+  let videoAttributes:any = {
     name: program['videoName'],
     category: program['category'],
     licence: program['licence'],
@@ -114,7 +123,11 @@ async function run () {
     support: undefined
   }
 
-  await uploadVideo(program['url'], accessToken, videoAttributes)
+  if (program['channelId']) {
+    videoAttributes.channelId = program['channelId']
+  }
+
+  await uploadVideo(program[ 'url' ], accessToken, videoAttributes)
 
   console.log(`Video ${program['videoName']} uploaded.`)
   process.exit(0)