mirror of
https://git.lecygnenoir.info/LecygneNoir/prismedia.git
synced 2025-10-03 17:39:16 +02:00
correction to be more pep8 compliant (mostly typo)
This commit is contained in:
parent
7c12bcbc31
commit
5d68cc79f7
5 changed files with 79 additions and 56 deletions
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
@ -77,7 +76,7 @@ def upload_video(oauth, config, options):
|
||||||
if options.get('--category'):
|
if options.get('--category'):
|
||||||
fields.append(("category", str(utils.getCategory(options.get('--category'), 'peertube'))))
|
fields.append(("category", str(utils.getCategory(options.get('--category'), 'peertube'))))
|
||||||
else:
|
else:
|
||||||
#if no category, set default to 2 (Films)
|
# if no category, set default to 2 (Films)
|
||||||
fields.append(("category", "2"))
|
fields.append(("category", "2"))
|
||||||
|
|
||||||
if options.get('--privacy'):
|
if options.get('--privacy'):
|
||||||
|
@ -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))
|
||||||
|
|
69
lib/utils.py
69
lib/utils.py
|
@ -4,47 +4,48 @@
|
||||||
|
|
||||||
### FOR CATEGORIE ###
|
### FOR CATEGORIE ###
|
||||||
YOUTUBE_CATEGORY = {
|
YOUTUBE_CATEGORY = {
|
||||||
"music":10,
|
"music": 10,
|
||||||
"films":1,
|
"films": 1,
|
||||||
"vehicles":2,
|
"vehicles": 2,
|
||||||
"sport":17,
|
"sport": 17,
|
||||||
"travels":19,
|
"travels": 19,
|
||||||
"gaming":20,
|
"gaming": 20,
|
||||||
"people":22,
|
"people": 22,
|
||||||
"comedy":23,
|
"comedy": 23,
|
||||||
"entertainment":24,
|
"entertainment": 24,
|
||||||
"news":25,
|
"news": 25,
|
||||||
"how to":26,
|
"how to": 26,
|
||||||
"education":27,
|
"education": 27,
|
||||||
"activism":29,
|
"activism": 29,
|
||||||
"science & technology":28,
|
"science & technology": 28,
|
||||||
"science":28,
|
"science": 28,
|
||||||
"technology":28,
|
"technology": 28,
|
||||||
"animals":15
|
"animals": 15
|
||||||
}
|
}
|
||||||
|
|
||||||
PEERTUBE_CATEGORY = {
|
PEERTUBE_CATEGORY = {
|
||||||
"music":1,
|
"music": 1,
|
||||||
"films":2,
|
"films": 2,
|
||||||
"vehicles":3,
|
"vehicles": 3,
|
||||||
"sport":5,
|
"sport": 5,
|
||||||
"travels":6,
|
"travels": 6,
|
||||||
"gaming":7,
|
"gaming": 7,
|
||||||
"people":8,
|
"people": 8,
|
||||||
"comedy":9,
|
"comedy": 9,
|
||||||
"entertainment":10,
|
"entertainment": 10,
|
||||||
"news":11,
|
"news": 11,
|
||||||
"how to":12,
|
"how to": 12,
|
||||||
"education":13,
|
"education": 13,
|
||||||
"activism":14,
|
"activism": 14,
|
||||||
"science & technology":15,
|
"science & technology": 15,
|
||||||
"science":15,
|
"science": 15,
|
||||||
"technology":15,
|
"technology": 15,
|
||||||
"animals":16
|
"animals": 16
|
||||||
}
|
}
|
||||||
|
|
||||||
######################
|
######################
|
||||||
|
|
||||||
|
|
||||||
def getCategory(category, type):
|
def getCategory(category, type):
|
||||||
if type == "youtube":
|
if type == "youtube":
|
||||||
return YOUTUBE_CATEGORY[category.lower()]
|
return YOUTUBE_CATEGORY[category.lower()]
|
||||||
|
|
|
@ -90,7 +90,7 @@ def initialize_upload(youtube, options):
|
||||||
"title": options.get('--name') or splitext(basename(path))[0],
|
"title": options.get('--name') or splitext(basename(path))[0],
|
||||||
"description": options.get('--description'),
|
"description": options.get('--description'),
|
||||||
"tags": tags,
|
"tags": tags,
|
||||||
#if no category, set default to 1 (Films)
|
# if no category, set default to 1 (Films)
|
||||||
"categoryId": str(category or 1),
|
"categoryId": str(category or 1),
|
||||||
},
|
},
|
||||||
"status": {
|
"status": {
|
||||||
|
|
|
@ -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')
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ VALID_CATEGORIES = (
|
||||||
"comedy", "entertainment", "news",
|
"comedy", "entertainment", "news",
|
||||||
"how to", "education", "activism", "science & technology",
|
"how to", "education", "activism", "science & technology",
|
||||||
"science", "technology", "animals"
|
"science", "technology", "animals"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def validateVideo(path):
|
def validateVideo(path):
|
||||||
|
@ -73,17 +73,20 @@ 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__':
|
||||||
|
|
||||||
|
@ -91,11 +94,31 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue