correction to be more pep8 compliant (mostly typo)

This commit is contained in:
LecygneNoir 2018-03-12 11:08:08 +01:00
parent 7c12bcbc31
commit 5d68cc79f7
5 changed files with 79 additions and 56 deletions

View file

@ -35,7 +35,7 @@ Options:
--cca License should be CreativeCommon Attribution (affects Youtube upload only) --cca License should be CreativeCommon Attribution (affects Youtube upload only)
-p, --privacy=STRING Choose between public, unlisted or private. [default: private] -p, --privacy=STRING Choose between public, unlisted or private. [default: private]
--disable-comments Disable comments (Peertube only) [default: comments are enabled] --disable-comments Disable comments (Peertube only) [default: comments are enabled]
--nsfw Set the video as NSFW (Peertube only as YT API does not support) [default: video is not restricted] --nsfw Set the video as No Safe For Work (Peertube only as YT API does not support) [default: video is safe]
-h --help Show this help. -h --help Show this help.
--version Show version. --version Show version.
@ -57,7 +57,7 @@ Categories:
- [x] description - [x] description
- [x] tags - [x] tags
- [x] categories - [x] categories
- [x] license: cca or not, affect only Youtube as Peertube uses Attribution by design - [x] license: cca or not (Youtube only as Peertube uses Attribution by design)
- [x] privacy (between public, unlisted or private) - [x] privacy (between public, unlisted or private)
- [x] enabling/disabling comment (Peertube only as Youtube API does not support it) - [x] enabling/disabling comment (Peertube only as Youtube API does not support it)
- [x] nsfw (Peertube only as Youtube API does not support it) - [x] nsfw (Peertube only as Youtube API does not support it)

View file

@ -52,7 +52,6 @@ def upload_video(oauth, config, options):
path = options.get('--file') path = options.get('--file')
url = config.get('peertube', 'peertube_url') url = config.get('peertube', 'peertube_url')
tags = None
# We need to transform fields into tuple to deal with tags as # We need to transform fields into tuple to deal with tags as
# MultipartEncoder does not support list refer # MultipartEncoder does not support list refer
@ -120,4 +119,4 @@ def run(options):
if hasattr(e, 'message'): if hasattr(e, 'message'):
print("Error: " + e.message) print("Error: " + e.message)
else: else:
print("Error: " + e) print("Error: " + str(e))

View file

@ -45,6 +45,7 @@ PEERTUBE_CATEGORY = {
###################### ######################
def getCategory(category, type): def getCategory(category, type):
if type == "youtube": if type == "youtube":
return YOUTUBE_CATEGORY[category.lower()] return YOUTUBE_CATEGORY[category.lower()]

View file

@ -17,7 +17,7 @@ Options:
--cca License should be CreativeCommon Attribution (affects Youtube upload only) --cca License should be CreativeCommon Attribution (affects Youtube upload only)
-p, --privacy=STRING Choose between public, unlisted or private. [default: private] -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] --disable-comments Disable comments (Peertube only as YT API does not support) [default: comments are enabled]
--nsfw Set the video as NSFW (Peertube only as YT API does not support) [default: video is not restricted] --nsfw Set the video as No Safe For Work (Peertube only as YT API does not support) [default: video is safe]
-h --help Show this help. -h --help Show this help.
--version Show version. --version Show version.
@ -36,7 +36,7 @@ import sys
from docopt import docopt from docopt import docopt
# Allows you to a relative import from the parent folder # Allows a relative import from the parent folder
sys.path.insert(0, dirname(realpath(__file__)) + "/lib") sys.path.insert(0, dirname(realpath(__file__)) + "/lib")
import yt_upload import yt_upload
@ -45,13 +45,13 @@ import pt_upload
try: try:
from schema import Schema, And, Or, Optional, SchemaError from schema import Schema, And, Or, Optional, SchemaError
except ImportError: except ImportError:
e('This program requires that the `schema` data-validation library' exit('This program requires that the `schema` data-validation library'
' is installed: \n' ' is installed: \n'
'see https://github.com/halst/schema\n') 'see https://github.com/halst/schema\n')
try: try:
import magic import magic
except ImportError: except ImportError:
e('This program requires that the `python-magic` library' exit('This program requires that the `python-magic` library'
' is installed, NOT the Python bindings to libmagic API \n' ' is installed, NOT the Python bindings to libmagic API \n'
'see https://github.com/ahupp/python-magic\n') 'see https://github.com/ahupp/python-magic\n')
@ -73,29 +73,52 @@ def validateVideo(path):
else: else:
return False return False
def validateCategory(category): def validateCategory(category):
if category.lower() in VALID_CATEGORIES: if category.lower() in VALID_CATEGORIES:
return True return True
else: else:
return False return False
def validatePrivacy(privacy): def validatePrivacy(privacy):
if privacy.lower() in VALID_PRIVACY_STATUSES: if privacy.lower() in VALID_PRIVACY_STATUSES:
return True return True
else: else:
return False return False
if __name__ == '__main__': if __name__ == '__main__':
options = docopt(__doc__, version=VERSION) options = docopt(__doc__, version=VERSION)
schema = Schema({ schema = Schema({
'--file': And(str, validateVideo, 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('--name'): Or(None, And(
Optional('--description'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")), str,
Optional('--tags'): Or(None, And(str, lambda x: not x.isdigit(), error="Tags should be a string")), lambda x: not x.isdigit(),
Optional('--category'): Or(None, And(str, validateCategory, error="Category not recognized, please see --help")), error="The video name should be a string")
Optional('--privacy'): Or(None, And(str, validatePrivacy, error="Please use recognized privacy between public, unlisted or private")), ),
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")
),
Optional('--category'): Or(None, And(
str,
validateCategory,
error="Category not recognized, please see --help")
),
Optional('--privacy'): Or(None, And(
str,
validatePrivacy,
error="Please use recognized privacy between public, unlisted or private")
),
Optional('--cca'): bool, Optional('--cca'): bool,
Optional('--disable-comments'): bool, Optional('--disable-comments'): bool,
Optional('--nsfw'): bool, Optional('--nsfw'): bool,
@ -106,7 +129,7 @@ if __name__ == '__main__':
try: try:
options = schema.validate(options) options = schema.validate(options)
except SchemaError as e: except SchemaError as e:
e(e) exit(e)
# yt_upload.run(options) yt_upload.run(options)
pt_upload.run(options) pt_upload.run(options)