Browse Source

add possibility to choose privacy

develop
LecygneNoir 6 years ago
parent
commit
2abcf711b8
3 changed files with 30 additions and 10 deletions
  1. +7
    -4
      README.md
  2. +11
    -2
      lib/pt_upload.py
  3. +12
    -4
      prismedia_upload.py

+ 7
- 4
README.md View File

@ -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

+ 11
- 2
lib/pt_upload.py View File

@ -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 = {

+ 12
- 4
prismedia_upload.py View File

@ -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

Loading…
Cancel
Save