Browse Source

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

LecygneNoir 1 year 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/
23 23
 *.egg-info/
24 24
 .installed.cfg
25 25
 *.egg
26
+.idea
26 27
 
27 28
 # PyInstaller
28 29
 #  Usually these files are written by a python script from a template

+ 2
- 1
README.md View File

@@ -34,6 +34,7 @@ Options:
34 34
   -c, --category=STRING  Category for the videos, see below. [ default: Films]
35 35
   --cca  License should be CreativeCommon Attribution (affects Youtube upload only)
36 36
   -p, --privacy=STRING Choose between public, unlisted or private. [default: private]
37
+  --disable-comments  Disable comments (Peertube only) [default: comments are enabled]
37 38
   -h --help  Show this help.
38 39
   --version  Show version.
39 40
 
@@ -57,7 +58,7 @@ Categories:
57 58
   - [x] categories
58 59
   - [x] license: cca or not, affect only Youtube as Peertube uses Attribution by design
59 60
   - [x] privacy (between public, unlisted or private)
60
-  - [ ] enabling/disabling comment
61
+  - [x] enabling/disabling comment (Peertube only as Youtube API has no option for that)
61 62
   - [ ] nsfw
62 63
   - [ ] thumbnail/preview
63 64
 - [ ] 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'
17 17
 PEERTUBE_PRIVACY = {
18 18
     "public": 1,
19 19
     "unlisted": 2,
20
-    "private:": 3
20
+    "private": 3
21 21
 }
22 22
 
23 23
 
@@ -65,7 +65,6 @@ def upload_video(oauth, config, options):
65 65
         ("description", options.get('--description') or "default description"),
66 66
         # look at the list numbers at /videos/privacies
67 67
         ("nsfw", "0"),
68
-        ("commentsEnabled", "1"),
69 68
         ("channelId", get_userinfo()),
70 69
         ("videofile", get_videofile(path))
71 70
     ]
@@ -86,6 +85,11 @@ def upload_video(oauth, config, options):
86 85
     else:
87 86
         fields.append(("privacy", "3"))
88 87
 
88
+    if options.get('--disable-comments'):
89
+        fields.append(("commentsEnabled", "0"))
90
+    else:
91
+        fields.append(("commentsEnabled", "1"))
92
+
89 93
     multipart_data = MultipartEncoder(fields)
90 94
 
91 95
     headers = {
@@ -114,6 +118,6 @@ def run(options):
114 118
         upload_video(oauth, config, options)
115 119
     except Exception as e:
116 120
         if hasattr(e, 'message'):
117
-            print(e.message)
121
+            print("Error: " + e.message)
118 122
         else:
119
-            print(e)
123
+            print("Error: " + e)

+ 4
- 2
prismedia_upload.py View File

@@ -15,7 +15,8 @@ Options:
15 15
   -t, --tags=STRING  Tags for the video. comma separated
16 16
   -c, --category=STRING  Category for the videos, see below. [ default: Films]
17 17
   --cca  License should be CreativeCommon Attribution (affects Youtube upload only)
18
-  -p, --privacy=STRING Choose between public, unlisted or private. [default: private]
18
+  -p, --privacy=STRING  Choose between public, unlisted or private. [default: private]
19
+  --disable-comments  Disable comments (Peertube only) [default: comments are enabled]
19 20
   -h --help  Show this help.
20 21
   --version  Show version.
21 22
 
@@ -95,6 +96,7 @@ if __name__ == '__main__':
95 96
         Optional('--category'): Or(None, And(str, validateCategory, error="Category not recognized, please see --help")),
96 97
         Optional('--privacy'): Or(None, And(str, validatePrivacy, error="Please use recognized privacy between public, unlisted or private")),
97 98
         Optional('--cca'): bool,
99
+        Optional('--disable-comments'): bool,
98 100
         '--help': bool,
99 101
         '--version': bool
100 102
     })
@@ -104,5 +106,5 @@ if __name__ == '__main__':
104 106
     except SchemaError as e:
105 107
         exit(e)
106 108
 
107
-    yt_upload.run(options)
109
+    # yt_upload.run(options)
108 110
     pt_upload.run(options)

Loading…
Cancel
Save