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.

71 lines
2.1 KiB

  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. import argparse
  17. from docopt import docopt
  18. try:
  19. from schema import Schema, And, Or, Use, Optional, SchemaError
  20. except ImportError:
  21. exit('This program requires that the `schema` data-validation library'
  22. ' is installed: \n'
  23. 'see https://github.com/halst/schema\n')
  24. try:
  25. import magic
  26. except ImportError:
  27. exit('This program requires that the `magic` library'
  28. ' is installed, NOT the Python bindings to libmagic API \n'
  29. 'see https://github.com/ahupp/python-magic\n')
  30. VERSION="ptyt 0.1-alpha"
  31. VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted')
  32. def validateVideo(path):
  33. supported_types = ['video/mp4']
  34. if magic.from_file(path, mime=True) in supported_types:
  35. return path
  36. else:
  37. return False
  38. if __name__ == '__main__':
  39. #Allows you to a relative import from the parent folder
  40. import os.path, sys
  41. sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))+"/lib")
  42. import yt_upload
  43. import pt_upload
  44. options = docopt(__doc__, version=VERSION)
  45. schema = Schema({
  46. '--file': And(str, lambda s: validateVideo(s), 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)