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.

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