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
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. """
  6. prismedia - tool to upload videos to different platforms (historicaly Peertube and Youtube)
  7. Usage:
  8. prismedia [options] --file=<file> | <interface>
  9. prismedia --list-plugins | --hearthbeat
  10. prismedia -h | --help | -V | --version
  11. Options:
  12. -f, --file=STRING Path to the video file to upload in mp4. This is the only mandatory option.
  13. --thumbnail=STRING Path to a file to use as a thumbnail for the video.
  14. --name=NAME Name of the video to upload. (default to video filename)
  15. -d, --description=STRING Description of the video. (default: default description)
  16. -t, --tags=STRING Tags for the video. comma separated.
  17. WARN: tags with punctuation (!, ', ", ?, ...)
  18. are not supported by Mastodon to be published from Peertube
  19. -c, --category=STRING Category for the videos, see below. (default: Films)
  20. --licence=STRING Creative Common licence tag (for exemple: CC-BY-SA) (default: proprietary)
  21. -p, --privacy=STRING Choose between public, unlisted or private. (default: private)
  22. --disable-comments Disable comments (Peertube only as YT API does not support) (default: comments are enabled)
  23. --nsfw Set the video as No Safe For Work (Peertube only as YT API does not support) (default: video is safe)
  24. --nfo=STRING Configure a specific nfo file to set options for the video.
  25. By default Prismedia search a .txt based on the video name and will
  26. decode the file as UTF-8 (so make sure your nfo file is UTF-8 encoded)
  27. See nfo_example.txt for more details
  28. --language=STRING Specify the default language for video. See below for supported language. (default is English)
  29. --publish-at=DATE Publish the video at the given DATE using local server timezone.
  30. DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00
  31. DATE should be in the future
  32. --peertube-at=DATE Override publish-at for the corresponding platform. Allow to create preview on specific platform
  33. --youtube-at=DATE Override publish-at for the corresponding platform. Allow to create preview on specific platform
  34. --original-date=DATE Configure the video as initially recorded at DATE
  35. DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00
  36. DATE should be in the past
  37. --auto-original-date Automatically use the file modification time as original date
  38. Supported types are jpg and jpeg.
  39. By default, prismedia search for an image based on video name followed by .jpg or .jpeg
  40. --channel=STRING Set the channel to use for the video (Peertube only)
  41. If the channel is not found, spawn an error except if --channelCreate is set.
  42. --channel-create Create the channel if not exists. (Peertube only, default do not create)
  43. Only relevant if --channel is set.
  44. --playlist=STRING Set the playlist to use for the video.
  45. If the playlist is not found, spawn an error except if --playlistCreate is set.
  46. --playlist-create Create the playlist if not exists. (default do not create)
  47. Only relevant if --playlist is set.
  48. --progress=STRING Set the progress bar view, one of percentage, bigFile, accurate. [default: percentage]
  49. --hearthbeat Use some credits to show some activity for you apikey so the platform know it is used and would not inactivate your keys.
  50. -h, --help Show this help.
  51. -V, --version Show the version.
  52. Plugins options:
  53. <interface> Interface plugin to use. Select the interface you want to use. By default the interface is the command line.
  54. --platform=STRING Platforms plugins to use. Usually one platform plugin upload to one platform website (comma separated list) (default: all)
  55. --consumer=STRING Consumers plugins to use. They are executed after an upload has been done (comma separated list) (default: all)
  56. --list-plugins List all the plugins currently installed by category.
  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. --withNFO Prevent the upload without a NFO, either specified via cli or found in the directory
  71. --withThumbnail Prevent the upload without a thumbnail
  72. --withName Prevent the upload if no name are found
  73. --withDescription Prevent the upload without description
  74. --withTags Prevent the upload without tags
  75. --withPlaylist Prevent the upload if no playlist
  76. --withPublishAt Prevent the upload if no schedule
  77. --withOriginalDate Prevent the upload if no original date configured
  78. --withPlatform Prevent the upload if at least one platform is not specified
  79. --withCategory Prevent the upload if no category
  80. --withLanguage Prevent upload if no language
  81. --withChannel 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 video
  95. from docopt import docopt
  96. from yapsy.PluginManager import PluginManagerSingleton
  97. import pluginInterfaces as pi
  98. import os
  99. import logging
  100. # logging.basicConfig(level=logging.DEBUG)
  101. VERSION = "prismedia v1.0.0-plugins-alpha"
  102. def loadPlugins(basePluginsPath):
  103. manager = PluginManagerSingleton.get()
  104. manager.setPluginPlaces(basePluginsPath)
  105. # Define the various categories corresponding to the different
  106. # kinds of plugins you have defined
  107. manager.setCategoriesFilter({
  108. pi.PluginTypes.INTERFACE : pi.IInterfacePlugin,
  109. pi.PluginTypes.PLATFORM : pi.IPlatformPlugin,
  110. pi.PluginTypes.CONSUMER : pi.IConsumerPlugin,
  111. })
  112. manager.collectPlugins()
  113. def listPlugins():
  114. manager = PluginManagerSingleton.get()
  115. print("The plugins are stored in the following folders:", manager.getPluginLocator().plugins_places)
  116. print("Category:", pi.PluginTypes.INTERFACE.value)
  117. for plugin in manager.getPluginsOfCategory(pi.PluginTypes.INTERFACE):
  118. print(plugin.name)
  119. print("Category:", pi.PluginTypes.PLATFORM.value)
  120. for plugin in manager.getPluginsOfCategory(pi.PluginTypes.PLATFORM):
  121. print(plugin.name)
  122. print("Category:", pi.PluginTypes.CONSUMER.value)
  123. for plugin in manager.getPluginsOfCategory(pi.PluginTypes.CONSUMER):
  124. print(plugin.name)
  125. def main():
  126. basePluginsPath = [os.path.dirname(os.path.abspath(__file__)) + "/plugins"]
  127. manager = loadPlugins(basePluginsPath)
  128. options = docopt(__doc__, version=VERSION)
  129. print(options)
  130. if options.get('--list-plugins'):
  131. listPlugins()
  132. exit(0)
  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 = video.Video("/path/to/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()