#!/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 base64ify(url): #download url to object #run base64 lib on object #format a data: string #return base64string def linebreaks(text): if not text: return text else: import re br = re.compile(r"(\r\n|\r|\n)") return br.sub(r"
\n", text) 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')#, tags_one_of='audio') videos = response.to_dict() videos = videos['data'] template = env.get_template('video-feed.html') html = template.render(videos=videos, host=host) with open('video-feed-prototype.html','w') as f: f.write(html) print(html)