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.

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