mirror of
https://git.lecygnenoir.info/LecygneNoir/prismedia.git
synced 2025-10-05 02:09:26 +02:00
use refresh_token instead of access_token to plan video in cron, to be able to generate a new token even if token has expired
This commit is contained in:
parent
28f964bf2e
commit
4ec8960451
1 changed files with 13 additions and 6 deletions
19
lib/utils.py
19
lib/utils.py
|
@ -169,7 +169,7 @@ def upcaseFirstLetter(s):
|
||||||
return s[0].upper() + s[1:]
|
return s[0].upper() + s[1:]
|
||||||
|
|
||||||
|
|
||||||
def publishAt(publishAt, oauth, url, idvideo):
|
def publishAt(publishAt, oauth, url, idvideo, secret):
|
||||||
try:
|
try:
|
||||||
FNULL = open(devnull, 'w')
|
FNULL = open(devnull, 'w')
|
||||||
check_call(["at", "-V"], stdout=FNULL, stderr=STDOUT)
|
check_call(["at", "-V"], stdout=FNULL, stderr=STDOUT)
|
||||||
|
@ -188,13 +188,20 @@ def publishAt(publishAt, oauth, url, idvideo):
|
||||||
time[1] = time[1][:-3]
|
time[1] = time[1][:-3]
|
||||||
|
|
||||||
atTime = time[1] + " " + time[0]
|
atTime = time[1] + " " + time[0]
|
||||||
token=str(oauth.__dict__['_client'].__dict__['access_token'])
|
refresh_token=str(oauth.__dict__['_client'].__dict__['refresh_token'])
|
||||||
atFile = "/tmp/peertube_" + idvideo + "_" + publishAt + ".at"
|
atFile = "/tmp/peertube_" + idvideo + "_" + publishAt + ".at"
|
||||||
try:
|
try:
|
||||||
file = open(atFile,"w")
|
openfile = open(atFile,"w")
|
||||||
file.write("curl '" + url + "/api/v1/videos/" + idvideo + "' -X PUT -H 'Authorization: Bearer " + token + "' -H 'Content-Type: multipart/form-data' -F 'privacy=1'")
|
openfile.write('token=$(curl -X POST -d "client_id=' + str(secret.get('peertube', 'client_id')) +
|
||||||
file.write(" ") # atd needs an empty line at the end of the file to load...
|
'&client_secret=' + str(secret.get('peertube', 'client_secret')) +
|
||||||
file.close()
|
'&grant_type=refresh_token&refresh_token=' + str(refresh_token) +
|
||||||
|
'" "' + url + '/api/v1/users/token" | jq -r .access_token)')
|
||||||
|
openfile.write("\n")
|
||||||
|
openfile.write('curl "' + url + '/api/v1/videos/' + idvideo +
|
||||||
|
'" -X PUT -H "Authorization: Bearer ${token}"' +
|
||||||
|
' -H "Content-Type: multipart/form-data" -F "privacy=1"')
|
||||||
|
openfile.write("\n ") # atd needs an empty line at the end of the file to load...
|
||||||
|
openfile.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if hasattr(e, 'message'):
|
if hasattr(e, 'message'):
|
||||||
logging.error("Error: " + str(e.message))
|
logging.error("Error: " + str(e.message))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue