Scripting way to upload videos to peertube and youtube
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.

74 lines
2.1 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. #!/usr/bin/python
  2. # coding: utf-8
  3. """
  4. ptyt_upload - tool to upload videos to Peertube and Youtube
  5. Usage:
  6. ptyt_upload.py --file=<FILE> [options]
  7. ptyt_upload.py -h | --help
  8. ptyt_upload.py --version
  9. Options:
  10. --name=NAME Name of the video to upload. default to video file name
  11. -d, --description=STRING Description of the video.
  12. -t, --tags=STRING Tags for the video. comma separated
  13. -h --help Show this help.
  14. --version Show version.
  15. """
  16. from os.path import dirname, realpath
  17. import sys
  18. from docopt import docopt
  19. # Allows you to a relative import from the parent folder
  20. sys.path.insert(0, dirname(realpath(__file__)) + "/lib")
  21. import yt_upload
  22. import pt_upload
  23. try:
  24. from schema import Schema, And, Or, Optional, SchemaError
  25. except ImportError:
  26. exit('This program requires that the `schema` data-validation library'
  27. ' is installed: \n'
  28. 'see https://github.com/halst/schema\n')
  29. try:
  30. import magic
  31. except ImportError:
  32. exit('This program requires that the `magic` library'
  33. ' is installed, NOT the Python bindings to libmagic API \n'
  34. 'see https://github.com/ahupp/python-magic\n')
  35. VERSION = "ptyt 0.1-alpha"
  36. VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted')
  37. def validateVideo(path):
  38. supported_types = ['video/mp4']
  39. if magic.from_file(path, mime=True) in supported_types:
  40. return path
  41. else:
  42. return False
  43. if __name__ == '__main__':
  44. options = docopt(__doc__, version=VERSION)
  45. schema = Schema({
  46. '--file': And(str, validateVideo, error='file is not supported, please use mp4'),
  47. Optional('--name'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
  48. Optional('--description'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
  49. Optional('--tags'): Or(None, And(str, lambda x: not x.isdigit(), error="Tags should be a string")),
  50. '--help': bool,
  51. '--version': bool
  52. })
  53. try:
  54. options = schema.validate(options)
  55. except SchemaError as e:
  56. exit(e)
  57. yt_upload.run(options)
  58. pt_upload.run(options)