Browse Source

correction to be more pep8 compliant (mostly typo)

develop
LecygneNoir 6 years ago
parent
commit
5d68cc79f7
5 changed files with 79 additions and 56 deletions
  1. +2
    -2
      README.md
  2. +2
    -3
      lib/pt_upload.py
  3. +35
    -34
      lib/utils.py
  4. +1
    -1
      lib/yt_upload.py
  5. +39
    -16
      prismedia_upload.py

+ 2
- 2
README.md View File

@ -35,7 +35,7 @@ Options:
--cca License should be CreativeCommon Attribution (affects Youtube upload only)
-p, --privacy=STRING Choose between public, unlisted or private. [default: private]
--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.
--version Show version.
@ -57,7 +57,7 @@ Categories:
- [x] description
- [x] tags
- [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] enabling/disabling comment (Peertube only as Youtube API does not support it)
- [x] nsfw (Peertube only as Youtube API does not support it)

+ 2
- 3
lib/pt_upload.py View File

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

+ 35
- 34
lib/utils.py View File

@ -4,47 +4,48 @@
### FOR CATEGORIE ###
YOUTUBE_CATEGORY = {
"music":10,
"films":1,
"vehicles":2,
"sport":17,
"travels":19,
"gaming":20,
"people":22,
"comedy":23,
"entertainment":24,
"news":25,
"how to":26,
"education":27,
"activism":29,
"science & technology":28,
"science":28,
"technology":28,
"animals":15
"music": 10,
"films": 1,
"vehicles": 2,
"sport": 17,
"travels": 19,
"gaming": 20,
"people": 22,
"comedy": 23,
"entertainment": 24,
"news": 25,
"how to": 26,
"education": 27,
"activism": 29,
"science & technology": 28,
"science": 28,
"technology": 28,
"animals": 15
}
PEERTUBE_CATEGORY = {
"music":1,
"films":2,
"vehicles":3,
"sport":5,
"travels":6,
"gaming":7,
"people":8,
"comedy":9,
"entertainment":10,
"news":11,
"how to":12,
"education":13,
"activism":14,
"science & technology":15,
"science":15,
"technology":15,
"animals":16
"music": 1,
"films": 2,
"vehicles": 3,
"sport": 5,
"travels": 6,
"gaming": 7,
"people": 8,
"comedy": 9,
"entertainment": 10,
"news": 11,
"how to": 12,
"education": 13,
"activism": 14,
"science & technology": 15,
"science": 15,
"technology": 15,
"animals": 16
}
######################
def getCategory(category, type):
if type == "youtube":
return YOUTUBE_CATEGORY[category.lower()]

+ 1
- 1
lib/yt_upload.py View File

@ -90,7 +90,7 @@ def initialize_upload(youtube, options):
"title": options.get('--name') or splitext(basename(path))[0],
"description": options.get('--description'),
"tags": tags,
#if no category, set default to 1 (Films)
# if no category, set default to 1 (Films)
"categoryId": str(category or 1),
},
"status": {

+ 39
- 16
prismedia_upload.py View File

@ -17,7 +17,7 @@ Options:
--cca License should be CreativeCommon Attribution (affects Youtube upload only)
-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 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.
--version Show version.
@ -36,7 +36,7 @@ import sys
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")
import yt_upload
@ -45,13 +45,13 @@ import pt_upload
try:
from schema import Schema, And, Or, Optional, SchemaError
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'
'see https://github.com/halst/schema\n')
try:
import magic
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'
'see https://github.com/ahupp/python-magic\n')
@ -63,7 +63,7 @@ VALID_CATEGORIES = (
"comedy", "entertainment", "news",
"how to", "education", "activism", "science & technology",
"science", "technology", "animals"
)
)
def validateVideo(path):
@ -73,17 +73,20 @@ def validateVideo(path):
else:
return False
def validateCategory(category):
if category.lower() in VALID_CATEGORIES:
return True
else:
return False
def validatePrivacy(privacy):
if privacy.lower() in VALID_PRIVACY_STATUSES:
return True
else:
return False
if privacy.lower() in VALID_PRIVACY_STATUSES:
return True
else:
return False
if __name__ == '__main__':
@ -91,11 +94,31 @@ if __name__ == '__main__':
schema = Schema({
'--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")),
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('--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")
),
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('--disable-comments'): bool,
Optional('--nsfw'): bool,
@ -106,7 +129,7 @@ if __name__ == '__main__':
try:
options = schema.validate(options)
except SchemaError as e:
e(e)
exit(e)
# yt_upload.run(options)
yt_upload.run(options)
pt_upload.run(options)

Loading…
Cancel
Save