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.

196 lines
11 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 override 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> [<parameters>...]]
  10. prismedia --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 except if you provide the name of a plugin interface (see <interface>).
  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. Note that calling `help` without the `--` calls a plugin showing a different help for the plugins.
  52. -V, --version Show the version.
  53. Plugins options:
  54. <interface> Interface plugin to use to provide the video to upload. Select the interface you want to use. If `--file` is provided instead the interface will be 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. Logging options:
  58. --log=STRING Log level, between debug, info, warning, error, critical. Ignored if --quiet is set (default to info)
  59. -q, --quiet Suppress any log except Critical (alias for --log=critical).
  60. -u, --url-only Display generated URL after upload directly on stdout, implies --quiet
  61. --batch Display generated URL after upload with platform information for easier parsing. Implies --quiet
  62. Be careful --batch and --url-only are mutually exclusives.
  63. Strict options:
  64. Strict options allow you to force some option to be present when uploading a video. It's useful to be sure you do not
  65. forget something when uploading a video, for example if you use multiples NFO. You may force the presence of description,
  66. tags, thumbnail, ...
  67. All strict option are optionals and are provided only to avoid errors when uploading :-)
  68. All strict options can be specified in NFO directly, the only strict option mandatory on cli is --withNFO
  69. All strict options are off by default
  70. --with-NFO Prevent the upload without a NFO, either specified via cli or found in the directory
  71. --with-thumbnail Prevent the upload without a thumbnail
  72. --with-name Prevent the upload if no name are found
  73. --with-description Prevent the upload without description
  74. --with-tag Prevent the upload without tags
  75. --with-playlist Prevent the upload if no playlist
  76. --with-publish-at Prevent the upload if no schedule
  77. --with-original-date Prevent the upload if no original date configured
  78. --with-platform Prevent the upload if at least one platform is not specified
  79. --with-category Prevent the upload if no category
  80. --with-language Prevent upload if no language
  81. --with-channel Prevent upload if no channel
  82. Categories:
  83. Category is the type of video you upload. Default is films.
  84. Here are available categories from Peertube and Youtube:
  85. music, films, vehicles, sports, travels, gaming, people,
  86. comedy, entertainment, news, how to, education, activism,
  87. science & technology, science, technology, animals
  88. Languages:
  89. Language of the video (audio track), choose one. Default is English
  90. Here are available languages from Peertube and Youtube:
  91. Arabic, English, French, German, Hindi, Italian, Japanese,
  92. Korean, Mandarin, Portuguese, Punjabi, Russian, Spanish
  93. """
  94. import cli
  95. import pluginInterfaces as pi
  96. import video as vid
  97. from docopt import docopt
  98. from yapsy.PluginManager import PluginManagerSingleton
  99. import os
  100. import logging
  101. # logging.basicConfig(level=logging.DEBUG)
  102. VERSION = "prismedia v1.0.0-plugins-alpha"
  103. def loadPlugins(basePluginsPath):
  104. pluginManager = PluginManagerSingleton.get()
  105. pluginManager.setPluginPlaces(basePluginsPath)
  106. # Define the various categories corresponding to the different
  107. # kinds of plugins you have defined
  108. pluginManager.setCategoriesFilter({
  109. pi.PluginTypes.ALL : pi.IPrismediaBasePlugin,
  110. pi.PluginTypes.INTERFACE : pi.IInterfacePlugin,
  111. pi.PluginTypes.PLATFORM : pi.IPlatformPlugin,
  112. pi.PluginTypes.CONSUMER : pi.IConsumerPlugin,
  113. })
  114. pluginManager.collectPlugins()
  115. def main():
  116. basePluginsPath = [os.path.dirname(os.path.abspath(__file__)) + "/plugins"]
  117. loadPlugins(basePluginsPath)
  118. pluginManager = 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 not cli.helperFunctionnality(options):
  123. exit(os.EX_OK)
  124. video = cli.parseOptions(options)
  125. if options["<interface>"]:
  126. interface = pluginManager.getPluginByName(options["<interface>"], pi.PluginTypes.INTERFACE)
  127. if not interface.plugin_object.prepareOptions(video, options):
  128. # The plugin asked to stop execution.
  129. exit(os.EX_OK)
  130. if options["--platform"]:
  131. platforms = pluginManager.getPluginsOf(categories=pi.PluginTypes.PLATFORM, name=[options["--platform"].split(",")])
  132. else:
  133. platforms = pluginManager.getPluginsOfCategory(pi.PluginTypes.PLATFORM)
  134. if options["--consumer"]:
  135. consumers = pluginManager.getPluginsOf(categories=pi.PluginTypes.CONSUMER, name=[options["--consumer"].split(",")])
  136. else:
  137. consumers = pluginManager.getPluginsOfCategory(pi.PluginTypes.CONSUMER)
  138. # Let each plugin check its options before starting any upload
  139. for plugin in [*platforms, *consumers]:
  140. print("DEBUG:", plugin.name)
  141. # TODO: Check this is needed or not: in case of no plugin or wrong name maybe the list is empty instead of there being a None value
  142. if plugin is None:
  143. # TODO: log instead to error ? critical ?
  144. print("No plugin installed name `" + plugin.name + "`.")
  145. exit(os.EX_USAGE)
  146. if not plugin.plugin_object.prepareOptions(video, options):
  147. # A plugin found ill formed options, it should have logged the precises infos
  148. print(plugin.name + " found a malformed option.")
  149. exit(os.EX_CONFIG)
  150. if video.path == "":
  151. # TODO: log instead to error ? critical ?
  152. print("No valid path to a video file has been provided.")
  153. exit(os.EX_USAGE)
  154. print("All options validated, starting uploads onto platforms")
  155. for platform in platforms:
  156. print("Uploading to: " + platform.name)
  157. platform.plugin_object.upload(video)
  158. print("All uploads have been done, calling consumers plugins")
  159. for consumer in consumers:
  160. print("Calling consumer: " + platform.name)
  161. consumer.plugin_object.finished(video)
  162. main()