Update peertube "publish at" functionnality to use their API

This commit is contained in:
Zykino 2018-10-02 00:30:33 +02:00
parent 56873c0063
commit 8d02d5a3a1
2 changed files with 19 additions and 63 deletions

View file

@ -193,62 +193,6 @@ def parseNFO(options):
def upcaseFirstLetter(s):
return s[0].upper() + s[1:]
def publishAt(publishAt, oauth, url, idvideo, secret):
try:
FNULL = open(devnull, 'w')
check_call(["at", "-V"], stdout=FNULL, stderr=STDOUT)
except CalledProcessError:
logging.error("You need to install the atd daemon to use the publishAt option.")
exit(1)
try:
FNULL = open(devnull, 'w')
check_call(["curl", "-V"], stdout=FNULL, stderr=STDOUT)
except CalledProcessError:
logging.error("You need to install the curl command line to use the publishAt option.")
exit(1)
try:
FNULL = open(devnull, 'w')
check_call(["jq", "-V"], stdout=FNULL, stderr=STDOUT)
except CalledProcessError:
logging.error("You need to install the jq command line to use the publishAt option.")
exit(1)
time = publishAt.split("T")
# Remove leading seconds that atd does not manage
if time[1].count(":") == 2:
time[1] = time[1][:-3]
atTime = time[1] + " " + time[0]
refresh_token=str(oauth.__dict__['_client'].__dict__['refresh_token'])
atFile = "/tmp/peertube_" + idvideo + "_" + publishAt + ".at"
try:
openfile = open(atFile,"w")
openfile.write('token=$(curl -X POST -d "client_id=' + str(secret.get('peertube', 'client_id')) +
'&client_secret=' + str(secret.get('peertube', 'client_secret')) +
'&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:
if hasattr(e, 'message'):
logging.error("Error: " + str(e.message))
else:
logging.error("Error: " + str(e))
try:
FNULL = open(devnull, 'w')
check_call(["at", "-M", "-f", atFile, atTime], stdout=FNULL, stderr=STDOUT)
except Exception as e:
if hasattr(e, 'message'):
logging.error("Error: " + str(e.message))
else:
logging.error("Error: " + str(e))
def mastodonTag(tag):
tags = tag.split(' ')
mtag = ''