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.

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