|
|
- #!/usr/bin/python
- # coding: utf-8
-
- # 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.
- # If we were to use them we would override configuration file values with default values of cli.
- # TODO: change `youtube-at` and `peertube-at` that are not easely expendable as options in my opinion
- """
- prismedia - tool to upload videos to different platforms (historicaly Peertube and Youtube)
-
- Usage:
- prismedia [options] --file=<file> | [<interface> [<parameters>...]]
- prismedia --hearthbeat
- prismedia -h | --help | -V | --version
-
- Options:
- -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>).
- --thumbnail=STRING Path to a file to use as a thumbnail for the video.
- --name=NAME Name of the video to upload. (default to video filename)
- -d, --description=STRING Description of the video. (default: default description)
- -t, --tag=STRING Tags for the video. comma separated.
- WARN: tags with punctuation (!, ', ", ?, ...)
- are not supported by Mastodon to be published from Peertube
- -c, --category=STRING Category for the videos, see below. (default: Films)
- --licence=STRING Creative Common licence tag (for exemple: CC-BY-SA) (default: proprietary)
- -p, --privacy=STRING Choose between public, unlisted or private. (default: private)
- --disable-comments Disable comments (Peertube only as YT API does not support) (default: comments are enabled)
- --nsfw Set the video as No Safe For Work (Peertube only as YT API does not support) (default: video is safe)
- --nfo=STRING Configure a specific nfo file to set options for the video.
- By default Prismedia search a .txt based on the video name and will
- decode the file as UTF-8 (so make sure your nfo file is UTF-8 encoded)
- See nfo_example.txt for more details
- --language=STRING Specify the default language for video. See below for supported language. (default is English)
- --publish-at=DATE Publish the video at the given DATE using local server timezone.
- DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00
- DATE should be in the future
- --peertube-at=DATE Override publish-at for the corresponding platform. Allow to create preview on specific platform
- --youtube-at=DATE Override publish-at for the corresponding platform. Allow to create preview on specific platform
- --original-date=DATE Configure the video as initially recorded at DATE
- DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00
- DATE should be in the past
- --auto-original-date Automatically use the file modification time as original date
- Supported types are jpg and jpeg.
- By default, prismedia search for an image based on video name followed by .jpg or .jpeg
- --channel=STRING Set the channel to use for the video (Peertube only)
- If the channel is not found, spawn an error except if --channelCreate is set.
- --channel-create Create the channel if not exists. (Peertube only, default do not create)
- Only relevant if --channel is set.
- --playlist=STRING Set the playlist to use for the video.
- If the playlist is not found, spawn an error except if --playlistCreate is set.
- --playlist-create Create the playlist if not exists. (default do not create)
- Only relevant if --playlist is set.
- --progress=STRING Set the progress bar view, one of percentage, bigFile, accurate. [default: percentage]
-
- --hearthbeat Use some credits to show some activity for you apikey so the platform know it is used and would not inactivate your keys.
-
- -h, --help Show this help. Note that calling `help` without the `--` calls a plugin showing a different help for the plugins.
- -V, --version Show the version.
-
- Plugins options:
- <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.
- --platform=STRING Platforms plugins to use. Usually one platform plugin upload to one platform website (comma separated list) (default: all)
- --consumer=STRING Consumers plugins to use. They are executed after an upload has been done (comma separated list) (default: all)
-
- Logging options:
- --log=STRING Log level, between debug, info, warning, error, critical. Ignored if --quiet is set (default to info)
- -q, --quiet Suppress any log except Critical (alias for --log=critical).
- -u, --url-only Display generated URL after upload directly on stdout, implies --quiet
- --batch Display generated URL after upload with platform information for easier parsing. Implies --quiet
- Be careful --batch and --url-only are mutually exclusives.
-
- Strict options:
- Strict options allow you to force some option to be present when uploading a video. It's useful to be sure you do not
- forget something when uploading a video, for example if you use multiples NFO. You may force the presence of description,
- tags, thumbnail, ...
- All strict option are optionals and are provided only to avoid errors when uploading :-)
- All strict options can be specified in NFO directly, the only strict option mandatory on cli is --withNFO
- All strict options are off by default
-
- --with-NFO Prevent the upload without a NFO, either specified via cli or found in the directory
- --with-thumbnail Prevent the upload without a thumbnail
- --with-name Prevent the upload if no name are found
- --with-description Prevent the upload without description
- --with-tag Prevent the upload without tags
- --with-playlist Prevent the upload if no playlist
- --with-publish-at Prevent the upload if no schedule
- --with-original-date Prevent the upload if no original date configured
- --with-platform Prevent the upload if at least one platform is not specified
- --with-category Prevent the upload if no category
- --with-language Prevent upload if no language
- --with-channel Prevent upload if no channel
-
- Categories:
- Category is the type of video you upload. Default is films.
- Here are available categories from Peertube and Youtube:
- music, films, vehicles, sports, travels, gaming, people,
- comedy, entertainment, news, how to, education, activism,
- science & technology, science, technology, animals
-
- Languages:
- Language of the video (audio track), choose one. Default is English
- Here are available languages from Peertube and Youtube:
- Arabic, English, French, German, Hindi, Italian, Japanese,
- Korean, Mandarin, Portuguese, Punjabi, Russian, Spanish
- """
-
- import cli
- import pluginInterfaces as pi
- import video as vid
-
- from docopt import docopt
- from yapsy.PluginManager import PluginManagerSingleton
- import os
- import logging
-
- # logging.basicConfig(level=logging.DEBUG)
-
- VERSION = "prismedia v1.0.0-plugins-alpha"
-
- def loadPlugins(basePluginsPath):
- pluginManager = PluginManagerSingleton.get()
- pluginManager.setPluginPlaces(basePluginsPath)
-
- # Define the various categories corresponding to the different
- # kinds of plugins you have defined
- pluginManager.setCategoriesFilter({
- pi.PluginTypes.ALL : pi.IPrismediaBasePlugin,
- pi.PluginTypes.INTERFACE : pi.IInterfacePlugin,
- pi.PluginTypes.PLATFORM : pi.IPlatformPlugin,
- pi.PluginTypes.CONSUMER : pi.IConsumerPlugin,
- })
-
- pluginManager.collectPlugins()
-
-
- def main():
- basePluginsPath = [os.path.dirname(os.path.abspath(__file__)) + "/plugins"]
- loadPlugins(basePluginsPath)
- pluginManager = PluginManagerSingleton.get()
-
- # TODO: add the arguments’s verification (copy/adapt the Schema table)
- options = docopt(__doc__, version=VERSION)
-
- # Helper functionnalities help the user but do not upload anything
- if not cli.helperFunctionnality(options):
- exit(os.EX_OK)
-
- video = cli.parseOptions(options)
- if options["<interface>"]:
- interface = pluginManager.getPluginByName(options["<interface>"], pi.PluginTypes.INTERFACE)
- if not interface.plugin_object.prepareOptions(video, options):
- # The plugin asked to stop execution.
- exit(os.EX_OK)
-
- if options["--platform"]:
- platforms = pluginManager.getPluginsOf(categories=pi.PluginTypes.PLATFORM, name=[options["--platform"].split(",")])
- else:
- platforms = pluginManager.getPluginsOfCategory(pi.PluginTypes.PLATFORM)
-
- if options["--consumer"]:
- consumers = pluginManager.getPluginsOf(categories=pi.PluginTypes.CONSUMER, name=[options["--consumer"].split(",")])
- else:
- consumers = pluginManager.getPluginsOfCategory(pi.PluginTypes.CONSUMER)
-
- # Let each plugin check its options before starting any upload
- for plugin in [*platforms, *consumers]:
- print("DEBUG:", plugin.name)
- # 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
- if plugin is None:
- # TODO: log instead to error ? critical ?
- print("No plugin installed name `" + plugin.name + "`.")
- exit(os.EX_USAGE)
-
- if not plugin.plugin_object.prepareOptions(video, options):
- # A plugin found ill formed options, it should have logged the precises infos
- print(plugin.name + " found a malformed option.")
- exit(os.EX_CONFIG)
-
- if video.path == "":
- # TODO: log instead to error ? critical ?
- print("No valid path to a video file has been provided.")
- exit(os.EX_USAGE)
-
- print("All options validated, starting uploads onto platforms")
-
- for platform in platforms:
- print("Uploading to: " + platform.name)
- platform.plugin_object.upload(video)
-
- print("All uploads have been done, calling consumers plugins")
-
- for consumer in consumers:
- print("Calling consumer: " + platform.name)
- consumer.plugin_object.finished(video)
-
-
- main()
|