Allows to publish videos uploaded on tv.lumbung.space to the frontpage of lumbung.space
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

61 lines
1.1 KiB

#!/bin/python3
#lumbung.space video feed generator
#c 2021 roel roscam abbing gpvl3 etc
import peertube
import jinja2
import json
import os
import datetime
def duration(n):
"""
convert '6655' in '1:50:55'
"""
return str(datetime.timedelta(seconds = n))
def linebreaks(text):
import re
br = re.compile(r"(\r\n|\r|\n)")
return br.sub(r"<br />\n", text)
#def base64ify(url):
#download url to object
#run base64 lib on object
#format a data: string
#return base64string
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.curdir)
)
env.filters['duration'] = duration
env.filters['linebreaks'] = linebreaks
host = 'https://tv.lumbung.space'
configuration = peertube.Configuration(
host = host+"/api/v1"
)
client = peertube.ApiClient(configuration)
v = peertube.VideoApi(client)
response = v.videos_get(count=6, filter='local')
videos = response.to_dict()
videos = videos['data']
template = env.get_template('video-feed.html')
html = template.render(videos=videos, host=host, description=description)
with open('video-feed-prototype.html','w') as f:
f.write(html)
print(html)