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.

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