mirror of
https://git.lecygnenoir.info/LecygneNoir/prismedia.git
synced 2025-10-03 09:29:16 +02:00
Update peertube "publish at" functionnality to use their API
This commit is contained in:
parent
56873c0063
commit
8d02d5a3a1
2 changed files with 19 additions and 63 deletions
|
@ -5,7 +5,10 @@ import os
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import datetime
|
||||||
|
import pytz
|
||||||
from os.path import splitext, basename, abspath
|
from os.path import splitext, basename, abspath
|
||||||
|
from tzlocal import get_localzone
|
||||||
|
|
||||||
from ConfigParser import RawConfigParser
|
from ConfigParser import RawConfigParser
|
||||||
from requests_oauthlib import OAuth2Session
|
from requests_oauthlib import OAuth2Session
|
||||||
|
@ -101,16 +104,27 @@ def upload_video(oauth, secret, options):
|
||||||
# if no language, set default to 1 (English)
|
# if no language, set default to 1 (English)
|
||||||
fields.append(("language", "en"))
|
fields.append(("language", "en"))
|
||||||
|
|
||||||
if options.get('--privacy'):
|
|
||||||
fields.append(("privacy", str(PEERTUBE_PRIVACY[options.get('--privacy').lower()])))
|
|
||||||
else:
|
|
||||||
fields.append(("privacy", "3"))
|
|
||||||
|
|
||||||
if options.get('--disable-comments'):
|
if options.get('--disable-comments'):
|
||||||
fields.append(("commentsEnabled", "0"))
|
fields.append(("commentsEnabled", "0"))
|
||||||
else:
|
else:
|
||||||
fields.append(("commentsEnabled", "1"))
|
fields.append(("commentsEnabled", "1"))
|
||||||
|
|
||||||
|
privacy = None
|
||||||
|
if options.get('--privacy'):
|
||||||
|
privacy = options.get('--privacy').lower()
|
||||||
|
|
||||||
|
if options.get('--publishAt'):
|
||||||
|
publishAt = options.get('--publishAt')
|
||||||
|
publishAt = datetime.datetime.strptime(publishAt, '%Y-%m-%dT%H:%M:%S')
|
||||||
|
tz = get_localzone()
|
||||||
|
tz = pytz.timezone(str(tz))
|
||||||
|
publishAt = tz.localize(publishAt).isoformat()
|
||||||
|
fields.append(("scheduleUpdate[updateAt]", publishAt))
|
||||||
|
fields.append(("scheduleUpdate[privacy]", str(PEERTUBE_PRIVACY["public"])))
|
||||||
|
fields.append(("privacy", str(PEERTUBE_PRIVACY["private"])))
|
||||||
|
else:
|
||||||
|
fields.append(("privacy", str(PEERTUBE_PRIVACY[privacy or "private"])))
|
||||||
|
|
||||||
if options.get('--thumbnail'):
|
if options.get('--thumbnail'):
|
||||||
fields.append(("thumbnailfile", get_file(options.get('--thumbnail'))))
|
fields.append(("thumbnailfile", get_file(options.get('--thumbnail'))))
|
||||||
fields.append(("previewfile", get_file(options.get('--thumbnail'))))
|
fields.append(("previewfile", get_file(options.get('--thumbnail'))))
|
||||||
|
@ -133,8 +147,6 @@ def upload_video(oauth, secret, options):
|
||||||
logging.info('Peertube : Video was successfully uploaded.')
|
logging.info('Peertube : Video was successfully uploaded.')
|
||||||
template = 'Peertube: Watch it at %s/videos/watch/%s.'
|
template = 'Peertube: Watch it at %s/videos/watch/%s.'
|
||||||
logging.info(template % (url, uuid))
|
logging.info(template % (url, uuid))
|
||||||
if options.get('--publishAt'):
|
|
||||||
utils.publishAt(str(options.get('--publishAt')), oauth, url, idvideo, secret)
|
|
||||||
else:
|
else:
|
||||||
logging.error(('Peertube: The upload failed with an unexpected response: '
|
logging.error(('Peertube: The upload failed with an unexpected response: '
|
||||||
'%s') % response)
|
'%s') % response)
|
||||||
|
|
56
lib/utils.py
56
lib/utils.py
|
@ -193,62 +193,6 @@ def parseNFO(options):
|
||||||
def upcaseFirstLetter(s):
|
def upcaseFirstLetter(s):
|
||||||
return s[0].upper() + s[1:]
|
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):
|
def mastodonTag(tag):
|
||||||
tags = tag.split(' ')
|
tags = tag.split(' ')
|
||||||
mtag = ''
|
mtag = ''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue