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