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.

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