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.

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