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

#!/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 overide 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>
prismedia --list-plugins | --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.
--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.
-V, --version Show the version.
Plugins options:
<interface> Interface plugin to use. Select the interface you want to use. By default the interface is 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)
--list-plugins List all the plugins currently installed by category.
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):
manager = PluginManagerSingleton.get()
manager.setPluginPlaces(basePluginsPath)
# Define the various categories corresponding to the different
# kinds of plugins you have defined
manager.setCategoriesFilter({
pi.PluginTypes.INTERFACE : pi.IInterfacePlugin,
pi.PluginTypes.PLATFORM : pi.IPlatformPlugin,
pi.PluginTypes.CONSUMER : pi.IConsumerPlugin,
})
manager.collectPlugins()
def main():
basePluginsPath = [os.path.dirname(os.path.abspath(__file__)) + "/plugins"]
loadPlugins(basePluginsPath)
manager = 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 cli.helperFunctionnality(options):
print(options)
exit(0) # TODO: Magic error code
video = cli.parseOptions(options)
if options["<interface>"]:
pass # TODO: call the interface the user asked for
if video.path is None:
# TODO: log instead to error ? critical ?
print("No valid path to a video file has been provided.")
exit(1) # TODO: Magic error code
print(options)
print()
print("# Plugins")
#def test_loadPlugins(arg):
# Loop round the plugins and print their names.
print("debug")
print(manager.getAllPlugins())
print("all plugins")
for plugin in manager.getAllPlugins():
print(plugin.name)
# plugin.plugin_object.print_name()
print()
print("# Video")
v = vid.Video()
v.name = "vidéo"
print(v.__dict__)
print(v.thumbnail)
# def startInterface():
# interface = loadPlugins()
#
# options = interface["default"].run() # Do I need this to extract basic cli? like an option "--interface=xxx"
# if options.get('--interface'):
# if interface[options.get('--interface')]:
# options = interface[options.get('--interface')].run(options)
# else:
# options = interface["cli"].run(options)
# options = interface["nfo"].run(options)
#
# def uploadToPlatforms(options):
# platforms = loadPlugins("platform")
# for platform in options.get('--platform'):
# platforms[platform].run(options)
# TODO: REMOVE ME
main()