Browse Source

Add option to disable comments on Peertube (Youtube has no option in API to do that)

develop
LecygneNoir 6 years ago
parent
commit
4be4a1727e
4 changed files with 15 additions and 7 deletions
  1. +1
    -0
      .gitignore
  2. +2
    -1
      README.md
  3. +8
    -4
      lib/pt_upload.py
  4. +4
    -2
      prismedia_upload.py

+ 1
- 0
.gitignore View File

@ -23,6 +23,7 @@ var/
*.egg-info/ *.egg-info/
.installed.cfg .installed.cfg
*.egg *.egg
.idea
# PyInstaller # PyInstaller
# Usually these files are written by a python script from a template # Usually these files are written by a python script from a template

+ 2
- 1
README.md View File

@ -34,6 +34,7 @@ Options:
-c, --category=STRING Category for the videos, see below. [ default: Films] -c, --category=STRING Category for the videos, see below. [ default: Films]
--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]
-h --help Show this help. -h --help Show this help.
--version Show version. --version Show version.
@ -57,7 +58,7 @@ Categories:
- [x] categories - [x] categories
- [x] license: cca or not, affect only Youtube as Peertube uses Attribution by design - [x] license: cca or not, affect only Youtube as Peertube uses Attribution by design
- [x] privacy (between public, unlisted or private) - [x] privacy (between public, unlisted or private)
- [ ] enabling/disabling comment
- [x] enabling/disabling comment (Peertube only as Youtube API has no option for that)
- [ ] nsfw - [ ] nsfw
- [ ] thumbnail/preview - [ ] thumbnail/preview
- [ ] Use a config file (NFO) file to retrieve videos arguments - [ ] Use a config file (NFO) file to retrieve videos arguments

+ 8
- 4
lib/pt_upload.py View File

@ -17,7 +17,7 @@ PEERTUBE_SECRETS_FILE = 'peertube_secret'
PEERTUBE_PRIVACY = { PEERTUBE_PRIVACY = {
"public": 1, "public": 1,
"unlisted": 2, "unlisted": 2,
"private:": 3
"private": 3
} }
@ -65,7 +65,6 @@ def upload_video(oauth, config, options):
("description", options.get('--description') or "default description"), ("description", options.get('--description') or "default description"),
# look at the list numbers at /videos/privacies # look at the list numbers at /videos/privacies
("nsfw", "0"), ("nsfw", "0"),
("commentsEnabled", "1"),
("channelId", get_userinfo()), ("channelId", get_userinfo()),
("videofile", get_videofile(path)) ("videofile", get_videofile(path))
] ]
@ -86,6 +85,11 @@ def upload_video(oauth, config, options):
else: else:
fields.append(("privacy", "3")) fields.append(("privacy", "3"))
if options.get('--disable-comments'):
fields.append(("commentsEnabled", "0"))
else:
fields.append(("commentsEnabled", "1"))
multipart_data = MultipartEncoder(fields) multipart_data = MultipartEncoder(fields)
headers = { headers = {
@ -114,6 +118,6 @@ def run(options):
upload_video(oauth, config, options) upload_video(oauth, config, options)
except Exception as e: except Exception as e:
if hasattr(e, 'message'): if hasattr(e, 'message'):
print(e.message)
print("Error: " + e.message)
else: else:
print(e)
print("Error: " + e)

+ 4
- 2
prismedia_upload.py View File

@ -15,7 +15,8 @@ Options:
-t, --tags=STRING Tags for the video. comma separated -t, --tags=STRING Tags for the video. comma separated
-c, --category=STRING Category for the videos, see below. [ default: Films] -c, --category=STRING Category for the videos, see below. [ default: Films]
--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]
-h --help Show this help. -h --help Show this help.
--version Show version. --version Show version.
@ -95,6 +96,7 @@ if __name__ == '__main__':
Optional('--category'): Or(None, And(str, validateCategory, error="Category not recognized, please see --help")), 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('--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,
'--help': bool, '--help': bool,
'--version': bool '--version': bool
}) })
@ -104,5 +106,5 @@ if __name__ == '__main__':
except SchemaError as e: except SchemaError as e:
exit(e) exit(e)
yt_upload.run(options)
# yt_upload.run(options)
pt_upload.run(options) pt_upload.run(options)

Loading…
Cancel
Save