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.

195 lines
9.8 KiB

  1. #!/usr/bin/python
  2. # coding: utf-8
  3. # NOTE: Since we use config file to set some defaults values, it is not possible to use the standard syntax with brackets, we use parenthesis instead.
  4. # If we were to use them we would overide configuration file values with default values of cli.
  5. # TODO: change `youtube-at` and `peertube-at` that are not easely expendable as options in my opinion
  6. """
  7. prismedia - tool to upload videos to different platforms (historicaly Peertube and Youtube)
  8. Usage:
  9. prismedia [options] --file=<file> | <interface>
  10. prismedia --list-plugins | --hearthbeat
  11. prismedia -h | --help | -V | --version
  12. Options:
  13. -f, --file=STRING Path to the video file to upload in mp4. This is the only mandatory option.
  14. --thumbnail=STRING Path to a file to use as a thumbnail for the video.
  15. --name=NAME Name of the video to upload. (default to video filename)
  16. -d, --description=STRING Description of the video. (default: default description)
  17. -t, --tag=STRING Tags for the video. comma separated.
  18. WARN: tags with punctuation (!, ', ", ?, ...)
  19. are not supported by Mastodon to be published from Peertube
  20. -c, --category=STRING Category for the videos, see below. (default: Films)
  21. --licence=STRING Creative Common licence tag (for exemple: CC-BY-SA) (default: proprietary)
  22. -p, --privacy=STRING Choose between public, unlisted or private. (default: private)
  23. --disable-comments Disable comments (Peertube only as YT API does not support) (default: comments are enabled)
  24. --nsfw Set the video as No Safe For Work (Peertube only as YT API does not support) (default: video is safe)
  25. --nfo=STRING Configure a specific nfo file to set options for the video.
  26. By default Prismedia search a .txt based on the video name and will
  27. decode the file as UTF-8 (so make sure your nfo file is UTF-8 encoded)
  28. See nfo_example.txt for more details
  29. --language=STRING Specify the default language for video. See below for supported language. (default is English)
  30. --publish-at=DATE Publish the video at the given DATE using local server timezone.
  31. DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00
  32. DATE should be in the future
  33. --peertube-at=DATE Override publish-at for the corresponding platform. Allow to create preview on specific platform
  34. --youtube-at=DATE Override publish-at for the corresponding platform. Allow to create preview on specific platform
  35. --original-date=DATE Configure the video as initially recorded at DATE
  36. DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00
  37. DATE should be in the past
  38. --auto-original-date Automatically use the file modification time as original date
  39. Supported types are jpg and jpeg.
  40. By default, prismedia search for an image based on video name followed by .jpg or .jpeg
  41. --channel=STRING Set the channel to use for the video (Peertube only)
  42. If the channel is not found, spawn an error except if --channelCreate is set.
  43. --channel-create Create the channel if not exists. (Peertube only, default do not create)
  44. Only relevant if --channel is set.
  45. --playlist=STRING Set the playlist to use for the video.
  46. If the playlist is not found, spawn an error except if --playlistCreate is set.
  47. --playlist-create Create the playlist if not exists. (default do not create)
  48. Only relevant if --playlist is set.
  49. --progress=STRING Set the progress bar view, one of percentage, bigFile, accurate. [default: percentage]
  50. --hearthbeat Use some credits to show some activity for you apikey so the platform know it is used and would not inactivate your keys.
  51. -h, --help Show this help.
  52. -V, --version Show the version.
  53. Plugins options:
  54. <interface> Interface plugin to use. Select the interface you want to use. By default the interface is the command line.
  55. --platform=STRING Platforms plugins to use. Usually one platform plugin upload to one platform website (comma separated list) (default: all)
  56. --consumer=STRING Consumers plugins to use. They are executed after an upload has been done (comma separated list) (default: all)
  57. --list-plugins List all the plugins currently installed by category.
  58. Logging options:
  59. --log=STRING Log level, between debug, info, warning, error, critical. Ignored if --quiet is set (default to info)
  60. -q, --quiet Suppress any log except Critical (alias for --log=critical).
  61. -u, --url-only Display generated URL after upload directly on stdout, implies --quiet
  62. --batch Display generated URL after upload with platform information for easier parsing. Implies --quiet
  63. Be careful --batch and --url-only are mutually exclusives.
  64. Strict options:
  65. Strict options allow you to force some option to be present when uploading a video. It's useful to be sure you do not
  66. forget something when uploading a video, for example if you use multiples NFO. You may force the presence of description,
  67. tags, thumbnail, ...
  68. All strict option are optionals and are provided only to avoid errors when uploading :-)
  69. All strict options can be specified in NFO directly, the only strict option mandatory on cli is --withNFO
  70. All strict options are off by default
  71. --with-NFO Prevent the upload without a NFO, either specified via cli or found in the directory
  72. --with-thumbnail Prevent the upload without a thumbnail
  73. --with-name Prevent the upload if no name are found
  74. --with-description Prevent the upload without description
  75. --with-tag Prevent the upload without tags
  76. --with-playlist Prevent the upload if no playlist
  77. --with-publish-at Prevent the upload if no schedule
  78. --with-original-date Prevent the upload if no original date configured
  79. --with-platform Prevent the upload if at least one platform is not specified
  80. --with-category Prevent the upload if no category
  81. --with-language Prevent upload if no language
  82. --with-channel Prevent upload if no channel
  83. Categories:
  84. Category is the type of video you upload. Default is films.
  85. Here are available categories from Peertube and Youtube:
  86. music, films, vehicles, sports, travels, gaming, people,
  87. comedy, entertainment, news, how to, education, activism,
  88. science & technology, science, technology, animals
  89. Languages:
  90. Language of the video (audio track), choose one. Default is English
  91. Here are available languages from Peertube and Youtube:
  92. Arabic, English, French, German, Hindi, Italian, Japanese,
  93. Korean, Mandarin, Portuguese, Punjabi, Russian, Spanish
  94. """
  95. import cli
  96. import pluginInterfaces as pi
  97. import video as vid
  98. from docopt import docopt
  99. from yapsy.PluginManager import PluginManagerSingleton
  100. import os
  101. import logging
  102. # logging.basicConfig(level=logging.DEBUG)
  103. VERSION = "prismedia v1.0.0-plugins-alpha"
  104. def loadPlugins(basePluginsPath):
  105. manager = PluginManagerSingleton.get()
  106. manager.setPluginPlaces(basePluginsPath)
  107. # Define the various categories corresponding to the different
  108. # kinds of plugins you have defined
  109. manager.setCategoriesFilter({
  110. pi.PluginTypes.INTERFACE : pi.IInterfacePlugin,
  111. pi.PluginTypes.PLATFORM : pi.IPlatformPlugin,
  112. pi.PluginTypes.CONSUMER : pi.IConsumerPlugin,
  113. })
  114. manager.collectPlugins()
  115. def main():
  116. basePluginsPath = [os.path.dirname(os.path.abspath(__file__)) + "/plugins"]
  117. loadPlugins(basePluginsPath)
  118. manager = PluginManagerSingleton.get()
  119. # TODO: add the arguments’s verification (copy/adapt the Schema table)
  120. options = docopt(__doc__, version=VERSION)
  121. # Helper functionnalities help the user but do not upload anything
  122. if cli.helperFunctionnality(options):
  123. print(options)
  124. exit(0) # TODO: Magic error code
  125. video = cli.parseOptions(options)
  126. if options["<interface>"]:
  127. pass # TODO: call the interface the user asked for
  128. if video.path is None:
  129. # TODO: log instead to error ? critical ?
  130. print("No valid path to a video file has been provided.")
  131. exit(1) # TODO: Magic error code
  132. print(options)
  133. print()
  134. print("# Plugins")
  135. #def test_loadPlugins(arg):
  136. # Loop round the plugins and print their names.
  137. print("debug")
  138. print(manager.getAllPlugins())
  139. print("all plugins")
  140. for plugin in manager.getAllPlugins():
  141. print(plugin.name)
  142. # plugin.plugin_object.print_name()
  143. print()
  144. print("# Video")
  145. v = vid.Video()
  146. v.name = "vidéo"
  147. print(v.__dict__)
  148. print(v.thumbnail)
  149. # def startInterface():
  150. # interface = loadPlugins()
  151. #
  152. # options = interface["default"].run() # Do I need this to extract basic cli? like an option "--interface=xxx"
  153. # if options.get('--interface'):
  154. # if interface[options.get('--interface')]:
  155. # options = interface[options.get('--interface')].run(options)
  156. # else:
  157. # options = interface["cli"].run(options)
  158. # options = interface["nfo"].run(options)
  159. #
  160. # def uploadToPlatforms(options):
  161. # platforms = loadPlugins("platform")
  162. # for platform in options.get('--platform'):
  163. # platforms[platform].run(options)
  164. # TODO: REMOVE ME
  165. main()