mirror of
https://git.lecygnenoir.info/LecygneNoir/prismedia.git
synced 2025-10-04 18:09:16 +02:00
Add thumbnail support for peertube
This commit is contained in:
parent
c822a10d0e
commit
b442f15b17
1 changed files with 13 additions and 11 deletions
|
@ -47,12 +47,11 @@ def upload_video(oauth, secret, options):
|
||||||
user_info = json.loads(oauth.get(url + "/api/v1/users/me").content)
|
user_info = json.loads(oauth.get(url + "/api/v1/users/me").content)
|
||||||
return str(user_info["id"])
|
return str(user_info["id"])
|
||||||
|
|
||||||
def get_videofile(path):
|
def get_file(path):
|
||||||
mimetypes.init()
|
mimetypes.init()
|
||||||
return (basename(path), open(abspath(path), 'rb'),
|
return (basename(path), open(abspath(path), 'rb'),
|
||||||
mimetypes.types_map[splitext(path)[1]])
|
mimetypes.types_map[splitext(path)[1]])
|
||||||
|
|
||||||
path = options.get('--file')
|
|
||||||
url = secret.get('peertube', 'peertube_url')
|
url = secret.get('peertube', 'peertube_url')
|
||||||
|
|
||||||
# We need to transform fields into tuple to deal with tags as
|
# We need to transform fields into tuple to deal with tags as
|
||||||
|
@ -65,7 +64,7 @@ def upload_video(oauth, secret, options):
|
||||||
("description", options.get('--description') or "default description"),
|
("description", options.get('--description') or "default description"),
|
||||||
("nsfw", str(int(options.get('--nsfw')) or "0")),
|
("nsfw", str(int(options.get('--nsfw')) or "0")),
|
||||||
("channelId", get_userinfo()),
|
("channelId", get_userinfo()),
|
||||||
("videofile", get_videofile(path))
|
("videofile", get_file(options.get('--file')))
|
||||||
]
|
]
|
||||||
|
|
||||||
if options.get('--tags'):
|
if options.get('--tags'):
|
||||||
|
@ -76,7 +75,7 @@ def upload_video(oauth, secret, options):
|
||||||
continue
|
continue
|
||||||
# Tag more than 30 chars crashes Peertube, so exit and check tags
|
# Tag more than 30 chars crashes Peertube, so exit and check tags
|
||||||
if len(strtag) >= 30:
|
if len(strtag) >= 30:
|
||||||
logging.warning("Sorry, Peertube does not support tag with more than 30 characters, please reduce your tag size")
|
logging.warning("Peertube: Sorry, Peertube does not support tag with more than 30 characters, please reduce your tag size")
|
||||||
exit(1)
|
exit(1)
|
||||||
# If Mastodon compatibility is enabled, clean tags from special characters
|
# If Mastodon compatibility is enabled, clean tags from special characters
|
||||||
if options.get('--mt'):
|
if options.get('--mt'):
|
||||||
|
@ -105,6 +104,9 @@ def upload_video(oauth, secret, options):
|
||||||
else:
|
else:
|
||||||
fields.append(("commentsEnabled", "1"))
|
fields.append(("commentsEnabled", "1"))
|
||||||
|
|
||||||
|
if options.get('--thumbnail'):
|
||||||
|
fields.append(("thumbnailfile", get_file(options.get('--thumbnail'))))
|
||||||
|
|
||||||
multipart_data = MultipartEncoder(fields)
|
multipart_data = MultipartEncoder(fields)
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
|
@ -120,13 +122,13 @@ def upload_video(oauth, secret, options):
|
||||||
jresponse = jresponse['video']
|
jresponse = jresponse['video']
|
||||||
uuid = jresponse['uuid']
|
uuid = jresponse['uuid']
|
||||||
idvideo = str(jresponse['id'])
|
idvideo = str(jresponse['id'])
|
||||||
template = ('Peertube : Video was successfully uploaded.\n'
|
logging.info('Peertube : Video was successfully uploaded.')
|
||||||
'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'):
|
if options.get('--publishAt'):
|
||||||
utils.publishAt(str(options.get('--publishAt')), oauth, url, idvideo, secret)
|
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)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
@ -136,16 +138,16 @@ def run(options):
|
||||||
try:
|
try:
|
||||||
secret.read(PEERTUBE_SECRETS_FILE)
|
secret.read(PEERTUBE_SECRETS_FILE)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Error loading " + str(PEERTUBE_SECRETS_FILE) + ": " + str(e))
|
logging.error("Peertube: Error loading " + str(PEERTUBE_SECRETS_FILE) + ": " + str(e))
|
||||||
exit(1)
|
exit(1)
|
||||||
insecure_transport = secret.get('peertube', 'OAUTHLIB_INSECURE_TRANSPORT')
|
insecure_transport = secret.get('peertube', 'OAUTHLIB_INSECURE_TRANSPORT')
|
||||||
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = insecure_transport
|
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = insecure_transport
|
||||||
oauth = get_authenticated_service(secret)
|
oauth = get_authenticated_service(secret)
|
||||||
try:
|
try:
|
||||||
logging.info('Peertube : Uploading file...')
|
logging.info('Peertube: Uploading video...')
|
||||||
upload_video(oauth, secret, options)
|
upload_video(oauth, secret, options)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if hasattr(e, 'message'):
|
if hasattr(e, 'message'):
|
||||||
logging.error("Error: " + str(e.message))
|
logging.error("Peertube: Error: " + str(e.message))
|
||||||
else:
|
else:
|
||||||
logging.error("Error: " + str(e))
|
logging.error("Peertube: Error: " + str(e))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue