Federated video streaming platform using ActivityPub and P2P in the web browser with Angular. https://joinpeertube.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

72 lines
2.0 KiB

  1. import { program } from 'commander'
  2. import { access, constants } from 'fs-extra'
  3. import { isAbsolute } from 'path'
  4. import { assignToken, buildCommonVideoOptions, buildServer, buildVideoAttributesFromCommander, getServerCredentials } from './cli'
  5. let command = program
  6. .name('upload')
  7. command = buildCommonVideoOptions(command)
  8. command
  9. .option('-u, --url <url>', 'Server url')
  10. .option('-U, --username <username>', 'Username')
  11. .option('-p, --password <token>', 'Password')
  12. .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path')
  13. .option('-v, --preview <previewPath>', 'Preview path')
  14. .option('-f, --file <file>', 'Video absolute file path')
  15. .parse(process.argv)
  16. const options = command.opts()
  17. getServerCredentials(command)
  18. .then(({ url, username, password }) => {
  19. if (!options.videoName || !options.file) {
  20. if (!options.videoName) console.error('--video-name is required.')
  21. if (!options.file) console.error('--file is required.')
  22. process.exit(-1)
  23. }
  24. if (isAbsolute(options.file) === false) {
  25. console.error('File path should be absolute.')
  26. process.exit(-1)
  27. }
  28. run(url, username, password).catch(err => {
  29. console.error(err)
  30. process.exit(-1)
  31. })
  32. })
  33. .catch(err => console.error(err))
  34. async function run (url: string, username: string, password: string) {
  35. const server = buildServer(url)
  36. await assignToken(server, username, password)
  37. await access(options.file, constants.F_OK)
  38. console.log('Uploading %s video...', options.videoName)
  39. const baseAttributes = await buildVideoAttributesFromCommander(server, program)
  40. const attributes = {
  41. ...baseAttributes,
  42. fixture: options.file,
  43. thumbnailfile: options.thumbnail,
  44. previewfile: options.preview
  45. }
  46. try {
  47. await server.videos.upload({ attributes })
  48. console.log(`Video ${options.videoName} uploaded.`)
  49. process.exit(0)
  50. } catch (err) {
  51. console.error(require('util').inspect(err))
  52. process.exit(-1)
  53. }
  54. }
  55. // ----------------------------------------------------------------------------