This commit is contained in:
meewan 2018-03-08 22:48:16 +01:00
parent 117e58a807
commit 010931d8b7
3 changed files with 152 additions and 125 deletions

View file

@ -4,7 +4,7 @@
"""
ptyt_upload - tool to upload videos to Peertube and Youtube
Usage:
Usage:
ptyt_upload.py --file=<FILE> [options]
ptyt_upload.py -h | --help
ptyt_upload.py --version
@ -15,14 +15,17 @@ Options:
-t, --tags=STRING Tags for the video. comma separated
-h --help Show this help.
--version Show version.
"""
import argparse
from os.path import dirname, realpath
from sys.path import insert
from docopt import docopt
import yt_upload
import pt_upload
try:
from schema import Schema, And, Or, Use, Optional, SchemaError
from schema import Schema, And, Or, Optional, SchemaError
except ImportError:
exit('This program requires that the `schema` data-validation library'
' is installed: \n'
@ -34,9 +37,10 @@ except ImportError:
' is installed, NOT the Python bindings to libmagic API \n'
'see https://github.com/ahupp/python-magic\n')
VERSION="ptyt 0.1-alpha"
VERSION = "ptyt 0.1-alpha"
VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted')
def validateVideo(path):
supported_types = ['video/mp4']
if magic.from_file(path, mime=True) in supported_types:
@ -44,19 +48,15 @@ def validateVideo(path):
else:
return False
if __name__ == '__main__':
#Allows you to a relative import from the parent folder
import os.path, sys
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))+"/lib")
import yt_upload
import pt_upload
# Allows you to a relative import from the parent folder
insert(0, dirname(realpath(__file__)) + "/lib")
options = docopt(__doc__, version=VERSION)
schema = Schema({
'--file': And(str, lambda s: validateVideo(s), error='file is not supported, please use mp4'),
'--file': And(str, validateVideo, error='file is not supported, please use mp4'),
Optional('--name'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
Optional('--description'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
Optional('--tags'): Or(None, And(str, lambda x: not x.isdigit(), error="Tags should be a string")),
@ -68,6 +68,6 @@ if __name__ == '__main__':
options = schema.validate(options)
except SchemaError as e:
exit(e)
yt_upload.run(options)
pt_upload.run(options)
pt_upload.run(options)