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.

110 lines
3.6 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
  1. #!/usr/bin/python
  2. # coding: utf-8
  3. """
  4. prismedia_upload - tool to upload videos to Peertube and Youtube
  5. Usage:
  6. prismedia_upload.py --file=<FILE> [options]
  7. prismedia_upload.py -h | --help
  8. prismedia_upload.py --version
  9. Options:
  10. --name=NAME Name of the video to upload. [default: video filename]
  11. -d, --description=STRING Description of the video. [default: default description]
  12. -t, --tags=STRING Tags for the video. comma separated
  13. -c, --category=STRING Category for the videos, see below. [ default: Films]
  14. --cca License should be CreativeCommon Attribution (affects Youtube upload only)
  15. -p, --privacy=STRING Choose between public, unlisted or private. [default: private]
  16. --disable-comments Disable comments (Peertube only) [default: comments are enabled]
  17. -h --help Show this help.
  18. --version Show version.
  19. Categories:
  20. Category is the type of video you upload. Default is films.
  21. Here are available categories from Peertube and Youtube:
  22. music, films, vehicles,
  23. sports, travels, gaming, people,
  24. comedy, entertainment, news,
  25. how to, education, activism, science & technology,
  26. science, technology, animals
  27. """
  28. from os.path import dirname, realpath
  29. import sys
  30. from docopt import docopt
  31. # Allows you to a relative import from the parent folder
  32. sys.path.insert(0, dirname(realpath(__file__)) + "/lib")
  33. import yt_upload
  34. import pt_upload
  35. try:
  36. from schema import Schema, And, Or, Optional, SchemaError
  37. except ImportError:
  38. exit('This program requires that the `schema` data-validation library'
  39. ' is installed: \n'
  40. 'see https://github.com/halst/schema\n')
  41. try:
  42. import magic
  43. except ImportError:
  44. exit('This program requires that the `python-magic` library'
  45. ' is installed, NOT the Python bindings to libmagic API \n'
  46. 'see https://github.com/ahupp/python-magic\n')
  47. VERSION = "prismedia 0.2-alpha"
  48. VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted')
  49. VALID_CATEGORIES = (
  50. "music", "films", "vehicles",
  51. "sports", "travels", "gaming", "people",
  52. "comedy", "entertainment", "news",
  53. "how to", "education", "activism", "science & technology",
  54. "science", "technology", "animals"
  55. )
  56. def validateVideo(path):
  57. supported_types = ['video/mp4']
  58. if magic.from_file(path, mime=True) in supported_types:
  59. return path
  60. else:
  61. return False
  62. def validateCategory(category):
  63. if category.lower() in VALID_CATEGORIES:
  64. return True
  65. else:
  66. return False
  67. def validatePrivacy(privacy):
  68. if privacy.lower() in VALID_PRIVACY_STATUSES:
  69. return True
  70. else:
  71. return False
  72. if __name__ == '__main__':
  73. options = docopt(__doc__, version=VERSION)
  74. schema = Schema({
  75. '--file': And(str, validateVideo, error='file is not supported, please use mp4'),
  76. Optional('--name'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
  77. Optional('--description'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
  78. Optional('--tags'): Or(None, And(str, lambda x: not x.isdigit(), error="Tags should be a string")),
  79. Optional('--category'): Or(None, And(str, validateCategory, error="Category not recognized, please see --help")),
  80. Optional('--privacy'): Or(None, And(str, validatePrivacy, error="Please use recognized privacy between public, unlisted or private")),
  81. Optional('--cca'): bool,
  82. Optional('--disable-comments'): bool,
  83. '--help': bool,
  84. '--version': bool
  85. })
  86. try:
  87. options = schema.validate(options)
  88. except SchemaError as e:
  89. exit(e)
  90. # yt_upload.run(options)
  91. pt_upload.run(options)