#!/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 easily expendable as options in my opinion # TODO: remove `--url-only` and `--batch` """ prismedia - tool to upload videos to different platforms (historically Peertube and Youtube) Usage: prismedia [cli] [options] --file= prismedia [...] prismedia --heartbeat prismedia --help | -h | --version | -V 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 ). --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 example: 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] --heartbeat 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 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 os import logging import pluginInterfaces as pi import configuration import utils import video as vid from docopt import docopt from yapsy.PluginManager import PluginManagerSingleton # logging.basicConfig(level=logging.DEBUG) VERSION = "prismedia v1.0.0-plugins-alpha" def loadPlugins(): from yapsy.ConfigurablePluginManager import ConfigurablePluginManager config = configuration.configuration_instance basePluginsPath = [config.root_path + "/plugins"] # TODO: check if AutoInstallPluginManager can help install new plugins or if it is already easy enough to download # and unzip a file. PluginManagerSingleton.setBehaviour([ConfigurablePluginManager]) pluginManager = PluginManagerSingleton.get() pluginManager.setPluginPlaces(directories_list=basePluginsPath) pluginManager.setPluginInfoExtension("prismedia-plugin") pluginManager.setConfigParser(config.config_parser, pluginManager.config_has_changed) # 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() return pluginManager # TODO: cut this function into smaller ones def main(): logger = logging.getLogger('Prismedia') # TODO: Check: Maybe this does not work good when installed via pip. pluginManager = loadPlugins() # TODO: add the arguments’s verification (copy/adapt the Schema table) options = docopt(__doc__, version=VERSION) # Helper functionalities help the user but do not upload anything if not utils.helperFunctionalities(options): exit(os.EX_OK) # Get all arguments needed by core only before calling any plugin listPlatforms = utils.getOption(options, "--platform") listConsumers = utils.getOption(options, "--consumer") if options[""]: interface_name = utils.getOption("") else: interface_name = "cli" interface = pluginManager.getPluginByName(interface_name, pi.PluginTypes.INTERFACE) video = vid.Video() try: if not interface.plugin_object.prepare_options(video, options): # The plugin asked to stop execution. exit(os.EX_OK) except Exception as e: logger.critical(utils.get_exception_string(e)) exit(os.EX_CONFIG) if listPlatforms: platforms = pluginManager.getPluginsOf(categories=pi.PluginTypes.PLATFORM, name=[listPlatforms.split(",")]) else: platforms = pluginManager.getPluginsOfCategory(pi.PluginTypes.PLATFORM) if listConsumers: consumers = pluginManager.getPluginsOf(categories=pi.PluginTypes.CONSUMER, name=[listConsumers.split(",")]) else: consumers = pluginManager.getPluginsOfCategory(pi.PluginTypes.CONSUMER) # Let each plugin check its options before starting any upload # We cannot merge this loop with the one from interface since the interface can change which plugin to use # We need to create each platform object in video, so we cannot merge this loop with the following one for plugin in platforms: # 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) try: video.platform[plugin.name] = vid.Platform() if not plugin.plugin_object.prepare_options(video, options): # A plugin found ill formed options, it should have logged the precises info print(plugin.name + " found a malformed option.") exit(os.EX_CONFIG) except Exception as e: logger.critical("Error while preparing plugin `" + plugin.name + "`: " + utils.get_exception_string(e)) exit(os.EX_CONFIG) for plugin in consumers: # 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) try: if not plugin.plugin_object.prepare_options(video, options): # A plugin found ill formed options, it should have logged the precises info print(plugin.name + " found a malformed option.") exit(os.EX_CONFIG) except Exception as e: logger.critical(utils.get_exception_string(e)) 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) try: platform.plugin_object.upload(video, options) except Exception as e: # TODO: Maybe not catch every Exception? logger.critical(utils.get_exception_string(e)) video.platform[platform.name].error = e video.platform[platform.name].publishAt = None video.platform[platform.name].url = None print("All uploads have been done, calling consumers plugins") for consumer in consumers: print("Calling consumer: " + consumer.name) consumer.plugin_object.finished(video, options) main()