Browse Source

Merge branch 'develop' into feature/playlist

LecygneNoir 1 year ago
parent
commit
64908a75ca
4 changed files with 21 additions and 70 deletions
  1. 1
    0
      CHANGELOG.md
  2. 1
    7
      README.md
  3. 19
    7
      lib/pt_upload.py
  4. 0
    56
      lib/utils.py

+ 1
- 0
CHANGELOG.md View File

@@ -4,6 +4,7 @@
4 4
 
5 5
 ### Features
6 6
  - Add the possibility to upload thumbnail
7
+ - Use the API instead of external binaries for publishAt (thanks @zykino)
7 8
 
8 9
 ## v0.5
9 10
 

+ 1
- 7
README.md View File

@@ -15,11 +15,6 @@ Search in your package manager, otherwise use ``pip install --upgrade``
15 15
  - requests-toolbelt
16 16
  - tzlocal
17 17
 
18
-For Peertube and if you want to use the publishAt option, you also need some utilities on you local system
19
- - [atd](https://linux.die.net/man/8/atd) daemon
20
- - [curl](https://linux.die.net/man/1/curl)
21
- - [jq](https://stedolan.github.io/jq/)
22
-
23 18
 ## Configuration
24 19
 
25 20
 Edit peertube_secret and youtube_secret.json with your credentials.
@@ -118,7 +113,6 @@ Options:
118 113
   --publishAt=DATE  Publish the video at the given DATE using local server timezone.
119 114
                     DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00
120 115
                     DATE should be in the future
121
-                    For Peertube, requires the "atd" and "curl utilities installed on the system
122 116
   --thumbnail=STRING    Path to a file to use as a thumbnail for the video.
123 117
                         Supported types are jpg and jpeg.
124 118
                         By default, prismedia search for an image based on video name followed by .jpg or .jpeg
@@ -161,7 +155,7 @@ Languages:
161 155
   - [ ] add videos to playlist for Youtube
162 156
 - [x] Use a config file (NFO) file to retrieve videos arguments
163 157
 - [x] Allow to choose peertube or youtube upload (to resume failed upload for example)
164
-- [x] Add publishAt option to plan your videos (need the [atd](https://linux.die.net/man/8/atd) daemon, [curl](https://linux.die.net/man/1/curl) and [jq](https://stedolan.github.io/jq/))
158
+- [x] Add publishAt option to plan your videos
165 159
 - [ ] Record and forget: put the video in a directory, and the script uploads it for you
166 160
 - [ ] Usable on Desktop (Linux and/or Windows and/or MacOS)
167 161
 - [ ] Graphical User Interface

+ 19
- 7
lib/pt_upload.py View File

@@ -5,7 +5,10 @@ import os
5 5
 import mimetypes
6 6
 import json
7 7
 import logging
8
+import datetime
9
+import pytz
8 10
 from os.path import splitext, basename, abspath
11
+from tzlocal import get_localzone
9 12
 
10 13
 from ConfigParser import RawConfigParser
11 14
 from requests_oauthlib import OAuth2Session
@@ -140,16 +143,27 @@ def upload_video(oauth, secret, options):
140 143
         # if no language, set default to 1 (English)
141 144
         fields.append(("language", "en"))
142 145
 
143
-    if options.get('--privacy'):
144
-        fields.append(("privacy", str(PEERTUBE_PRIVACY[options.get('--privacy').lower()])))
145
-    else:
146
-        fields.append(("privacy", "3"))
147
-
148 146
     if options.get('--disable-comments'):
149 147
         fields.append(("commentsEnabled", "0"))
150 148
     else:
151 149
         fields.append(("commentsEnabled", "1"))
152 150
 
151
+    privacy = None
152
+    if options.get('--privacy'):
153
+        privacy = options.get('--privacy').lower()
154
+
155
+    if options.get('--publishAt'):
156
+        publishAt = options.get('--publishAt')
157
+        publishAt = datetime.datetime.strptime(publishAt, '%Y-%m-%dT%H:%M:%S')
158
+        tz = get_localzone()
159
+        tz = pytz.timezone(str(tz))
160
+        publishAt = tz.localize(publishAt).isoformat()
161
+        fields.append(("scheduleUpdate[updateAt]", publishAt))
162
+        fields.append(("scheduleUpdate[privacy]", str(PEERTUBE_PRIVACY["public"])))
163
+        fields.append(("privacy", str(PEERTUBE_PRIVACY["private"])))
164
+    else:
165
+        fields.append(("privacy", str(PEERTUBE_PRIVACY[privacy or "private"])))
166
+
153 167
     if options.get('--thumbnail'):
154 168
         fields.append(("thumbnailfile", get_file(options.get('--thumbnail'))))
155 169
         fields.append(("previewfile", get_file(options.get('--thumbnail'))))
@@ -182,8 +196,6 @@ def upload_video(oauth, secret, options):
182 196
             logging.info('Peertube : Video was successfully uploaded.')
183 197
             template = 'Peertube: Watch it at %s/videos/watch/%s.'
184 198
             logging.info(template % (url, uuid))
185
-            if options.get('--publishAt'):
186
-                utils.publishAt(str(options.get('--publishAt')), oauth, url, idvideo, secret)
187 199
         else:
188 200
             logging.error(('Peertube: The upload failed with an unexpected response: '
189 201
                            '%s') % response)

+ 0
- 56
lib/utils.py View File

@@ -193,62 +193,6 @@ def parseNFO(options):
193 193
 def upcaseFirstLetter(s):
194 194
     return s[0].upper() + s[1:]
195 195
 
196
-
197
-def publishAt(publishAt, oauth, url, idvideo, secret):
198
-    try:
199
-        FNULL = open(devnull, 'w')
200
-        check_call(["at", "-V"], stdout=FNULL, stderr=STDOUT)
201
-    except CalledProcessError:
202
-        logging.error("You need to install the atd daemon to use the publishAt option.")
203
-        exit(1)
204
-    try:
205
-        FNULL = open(devnull, 'w')
206
-        check_call(["curl", "-V"], stdout=FNULL, stderr=STDOUT)
207
-    except CalledProcessError:
208
-        logging.error("You need to install the curl command line to use the publishAt option.")
209
-        exit(1)
210
-    try:
211
-        FNULL = open(devnull, 'w')
212
-        check_call(["jq", "-V"], stdout=FNULL, stderr=STDOUT)
213
-    except CalledProcessError:
214
-        logging.error("You need to install the jq command line to use the publishAt option.")
215
-        exit(1)
216
-    time = publishAt.split("T")
217
-    # Remove leading seconds that atd does not manage
218
-    if time[1].count(":") == 2:
219
-        time[1] = time[1][:-3]
220
-
221
-    atTime = time[1] + " " + time[0]
222
-    refresh_token=str(oauth.__dict__['_client'].__dict__['refresh_token'])
223
-    atFile = "/tmp/peertube_" + idvideo + "_" + publishAt + ".at"
224
-    try:
225
-        openfile = open(atFile,"w")
226
-        openfile.write('token=$(curl -X POST -d "client_id=' + str(secret.get('peertube', 'client_id')) +
227
-                        '&client_secret=' + str(secret.get('peertube', 'client_secret')) +
228
-                        '&grant_type=refresh_token&refresh_token=' + str(refresh_token) +
229
-                        '" "' + url + '/api/v1/users/token" | jq -r .access_token)')
230
-        openfile.write("\n")
231
-        openfile.write('curl "' + url + '/api/v1/videos/' + idvideo +
232
-                        '" -X PUT -H "Authorization: Bearer ${token}"' +
233
-                        ' -H "Content-Type: multipart/form-data" -F "privacy=1"')
234
-        openfile.write("\n ")  # atd needs an empty line at the end of the file to load...
235
-        openfile.close()
236
-    except Exception as e:
237
-        if hasattr(e, 'message'):
238
-            logging.error("Error: " + str(e.message))
239
-        else:
240
-            logging.error("Error: " + str(e))
241
-
242
-    try:
243
-        FNULL = open(devnull, 'w')
244
-        check_call(["at", "-M", "-f", atFile, atTime], stdout=FNULL, stderr=STDOUT)
245
-    except Exception as e:
246
-        if hasattr(e, 'message'):
247
-            logging.error("Error: " + str(e.message))
248
-        else:
249
-            logging.error("Error: " + str(e))
250
-
251
-
252 196
 def mastodonTag(tag):
253 197
     tags = tag.split(' ')
254 198
     mtag = ''

Loading…
Cancel
Save