From 2abcf711b83f69b870faf2dd4d2e733afc2e3c01 Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Fri, 9 Mar 2018 22:16:36 +0100 Subject: [PATCH] add possibility to choose privacy --- README.md | 11 +++++++---- lib/pt_upload.py | 13 +++++++++++-- prismedia_upload.py | 16 ++++++++++++---- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ed83772..5e4e8ef 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,12 @@ Usage: prismedia_upload.py --version Options: - --name=NAME Name of the video to upload. default to video file name - -d, --description=STRING Description of the video. + --name=NAME Name of the video to upload. [default: video filename] + -d, --description=STRING Description of the video. [default: default description] -t, --tags=STRING Tags for the video. comma separated - -c, --category=STRING Category for the videos, see below. Default to films + -c, --category=STRING Category for the videos, see below. [ default: Films] --cca License should be CreativeCommon Attribution (affects Youtube upload only) + -p, --privacy=STRING Choose between public, unlisted or private. [default: private] -h --help Show this help. --version Show version. @@ -44,7 +45,6 @@ Categories: comedy, entertainment, news, how to, education, activism, science & technology, science, technology, animals - ``` ## Features @@ -56,6 +56,9 @@ Categories: - [x] tags - [x] categories - [x] license: cca or not, affect only Youtube as Peertube uses Attribution by design + - [x] privacy (between public, unlisted or private) + - [ ] enabling/disabling comment + - [ ] nsfw - [ ] thumbnail/preview - [ ] Use a config file (NFO) file to retrieve videos arguments - [ ] Record and forget: put the video in a directory, and the script uploads it for you diff --git a/lib/pt_upload.py b/lib/pt_upload.py index 220b7ad..a711725 100644 --- a/lib/pt_upload.py +++ b/lib/pt_upload.py @@ -14,6 +14,11 @@ from requests_toolbelt.multipart.encoder import MultipartEncoder import utils PEERTUBE_SECRETS_FILE = 'peertube_secret' +PEERTUBE_PRIVACY = { + "public": 1, + "unlisted": 2, + "private:": 3 +} def get_authenticated_service(config): @@ -59,8 +64,7 @@ def upload_video(oauth, config, options): ("licence", "1"), ("description", options.get('--description') or "default description"), # look at the list numbers at /videos/privacies - ("privacy", str(options.get('--privacy') or 3)), - ("nsfw", str(options.get('--nsfw') or 0)), + ("nsfw", "0"), ("commentsEnabled", "1"), ("channelId", get_userinfo()), ("videofile", get_videofile(path)) @@ -77,6 +81,11 @@ def upload_video(oauth, config, options): #if no category, set default to 2 (Films) fields.append(("category", "2")) + if options.get('--privacy'): + fields.append(("privacy", str(PEERTUBE_PRIVACY[options.get('--privacy').lower()]))) + else: + fields.append(("privacy", "3")) + multipart_data = MultipartEncoder(fields) headers = { diff --git a/prismedia_upload.py b/prismedia_upload.py index 388795f..820426b 100755 --- a/prismedia_upload.py +++ b/prismedia_upload.py @@ -10,11 +10,12 @@ Usage: prismedia_upload.py --version Options: - --name=NAME Name of the video to upload. default to video file name - -d, --description=STRING Description of the video. + --name=NAME Name of the video to upload. [default: video filename] + -d, --description=STRING Description of the video. [default: default description] -t, --tags=STRING Tags for the video. comma separated - -c, --category=STRING Category for the videos, see below. Default to films + -c, --category=STRING Category for the videos, see below. [ default: Films] --cca License should be CreativeCommon Attribution (affects Youtube upload only) + -p, --privacy=STRING Choose between public, unlisted or private. [default: private] -h --help Show this help. --version Show version. @@ -48,7 +49,7 @@ except ImportError: try: import magic except ImportError: - exit('This program requires that the `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') @@ -76,6 +77,12 @@ def validateCategory(category): else: return False +def validatePrivacy(privacy): + if privacy.lower() in VALID_PRIVACY_STATUSES: + return True + else: + return False + if __name__ == '__main__': options = docopt(__doc__, version=VERSION) @@ -86,6 +93,7 @@ if __name__ == '__main__': 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, '--help': bool, '--version': bool