forked from ruangrupa/lumbung.space
ack + repos
This commit is contained in:
27
lumbung-video-prototype/README.md
Normal file
27
lumbung-video-prototype/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# video feed prototypes
|
||||
|
||||
These scripts poll a peertube instance to return a list of videos and construct a static page for it using jinja2.
|
||||
|
||||
See it in action on <https://roelof.info/lumbung/>
|
||||
|
||||
## video-feed.py
|
||||
|
||||
Utility that returns Peertube videos tagged as `publish` and turns them in to `hugo` page bundles. Videos no longer tagged as `publish` are deleted.
|
||||
|
||||
### index-template.md
|
||||
|
||||
Jinja2 template of a hugo post for use with the above.
|
||||
|
||||
## streams-feed.py
|
||||
|
||||
Returns only livestreams and displays them differently depending on the tags associated with the video. E.g. audio stream or video stream. WIP.
|
||||
|
||||
### video-feed.html
|
||||
The jinja template for creating video feeds. This is now used in the HUGO theme.
|
||||
|
||||
### video-feed-prototype.html
|
||||
rendered example of above
|
||||
|
||||
|
||||
|
||||
|
15
lumbung-video-prototype/index_template.md
Normal file
15
lumbung-video-prototype/index_template.md
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
title: "{{ v.name }}"
|
||||
date: "{{ v.published_at }}" #2021-06-10T10:46:33+02:00
|
||||
draft: false
|
||||
uuid: "{{v.uuid}}"
|
||||
video_duration: "{{ v.duration | duration }} "
|
||||
video_channel: "{{ v.channel.display_name }}"
|
||||
channel_url: "{{ v.channel.url }}"
|
||||
preview_image: "{{ preview_image }}"
|
||||
categories: ["tv","{{ v.channel.display_name }}"]
|
||||
is_live: {{ v.is_live }}
|
||||
|
||||
---
|
||||
|
||||
{{ v.description }}
|
12
lumbung-video-prototype/requirements.txt
Normal file
12
lumbung-video-prototype/requirements.txt
Normal file
@ -0,0 +1,12 @@
|
||||
# Automatically generated by https://github.com/damnever/pigar.
|
||||
|
||||
# video_feed/streams-feed.py: 7
|
||||
# video_feed/video-feed.py: 7
|
||||
Jinja2 == 2.10
|
||||
|
||||
# video_feed/streams-feed.py: 6
|
||||
# video_feed/video-feed.py: 6
|
||||
git+https://framagit.org/framasoft/peertube/clients/python.git
|
||||
|
||||
# video_feed/video-feed.py: 12
|
||||
requests == 2.21.0
|
251
lumbung-video-prototype/video-feed.html
Normal file
251
lumbung-video-prototype/video-feed.html
Normal file
@ -0,0 +1,251 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
|
||||
<title>lumbung.space video archive prototype</title>
|
||||
|
||||
<meta name="description" content="this page is generated on the basis of a peertube instance">
|
||||
<meta property="og:title" content="lumbung.space video archive prototype">
|
||||
<meta property="og:description" content="this page is generated on the basis of a peertube instance">
|
||||
<meta property="og:image" content="{{ host }}{{videos[0].preview_path}}">
|
||||
<meta property="og:image:alt" content="Image description">
|
||||
<meta property="og:locale" content="en_GB">
|
||||
<meta property="og:type" content="website">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta property="og:url" content="https://lumbung.space/videofeedprototype.html">
|
||||
<link rel="canonical" href="https://lumbung.space/videofeedprototype.html">
|
||||
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
||||
<link rel="manifest" href="/my.webmanifest">
|
||||
<meta name="theme-color" content="#FF00FF">
|
||||
<style type="text/css">
|
||||
@font-face{
|
||||
font-family: "Space Grotesk";
|
||||
src:url('SpaceGrotesk[wght].woff2')
|
||||
}
|
||||
|
||||
body {font-size:1.3rem;font-family: sans-serif;}
|
||||
.wrapper {
|
||||
width: 50%;
|
||||
margin: auto;
|
||||
}
|
||||
.video-box {
|
||||
border:2px solid #0e0e22;
|
||||
max-width:560px;
|
||||
margin:auto;
|
||||
box-shadow:1em 1em 0 #d2d1c8;
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
.video-box img {
|
||||
max-width: 100%;
|
||||
}
|
||||
.video-box .media {
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
.metadata{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #fff09d;
|
||||
font-size:0.9rem;
|
||||
}
|
||||
|
||||
|
||||
.title{
|
||||
margin-top:0;
|
||||
border-top: 2px solid #0e0e22;
|
||||
padding:0.5em;
|
||||
font-weight:700;
|
||||
font-size:1.3rem;
|
||||
}
|
||||
|
||||
.footer{
|
||||
margin-top:0;
|
||||
border-top: 2px solid #0e0e22;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.channel{
|
||||
border-right: 2px solid #0e0e22;
|
||||
padding-left: 1em;
|
||||
padding-right: 1em;
|
||||
padding-top: 0.2em;
|
||||
display: inline-block;
|
||||
padding-bottom: 0.2em;
|
||||
}
|
||||
|
||||
.date {
|
||||
float:right;
|
||||
border-left: 2px solid #0e0e22;
|
||||
padding-left: 1em;
|
||||
padding-right: 1em;
|
||||
padding-top: 0.2em;
|
||||
display: inline-block;
|
||||
padding-bottom: 0.2em;
|
||||
}
|
||||
|
||||
.description{
|
||||
padding: 1em;
|
||||
display: block;
|
||||
/*transition: height 0.5s linear;*/
|
||||
overflow: hidden;
|
||||
border-top: 2px solid #0e0e22;
|
||||
}
|
||||
|
||||
.collapsed {
|
||||
border-top: 0px;
|
||||
/*transform:scaleY(0);*/
|
||||
height: 0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
.descr_button {
|
||||
cursor: pointer;
|
||||
flex-grow: 1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.descr_button a {
|
||||
color:inherit;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
.descr_button a:before {
|
||||
content:'↕';
|
||||
vertical-align: sub;
|
||||
}
|
||||
|
||||
.descr_button:hover {
|
||||
box-shadow: inset 2px 2px 0px #95948c;
|
||||
}
|
||||
|
||||
.play-icon {
|
||||
width: 0;
|
||||
height: 0;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%,-50%) scale(.5);
|
||||
border-top: 13px solid transparent;
|
||||
border-bottom: 13px solid transparent;
|
||||
border-left: 18px solid hsla(0,0%,100%,.95);
|
||||
}
|
||||
|
||||
.video-thumbnail {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
}
|
||||
.video-thumbnail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
background-color: #ececec;
|
||||
transition: filter .2s ease;
|
||||
}
|
||||
|
||||
.video-thumbnail-duration-overlay {
|
||||
display: inline-block;
|
||||
background-color: rgb(255, 240, 157);
|
||||
color: #0e0e22;
|
||||
font-size: 14px;
|
||||
line-height: 1.1;
|
||||
z-index: 10;
|
||||
position: absolute;
|
||||
padding: 1px 3px 1px 3px;
|
||||
right: 5px;
|
||||
bottom: 5px;
|
||||
border: 2px solid #0e0e22;
|
||||
}
|
||||
|
||||
.play-overlay {
|
||||
transition: all .2s ease;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
width: inherit;
|
||||
height: inherit;
|
||||
opacity: 0;
|
||||
background-color: rgba(0,0,0,.3);
|
||||
}
|
||||
|
||||
.video-thumbnail:hover {
|
||||
text-decoration:none!important
|
||||
}
|
||||
.video-thumbnail:hover .play-overlay {
|
||||
opacity:1
|
||||
}
|
||||
.video-thumbnail:hover .play-overlay .play-icon {
|
||||
transform:translate(-50%,-50%) scale(1)
|
||||
}
|
||||
|
||||
/* @media screen and (min-width: 480px) {
|
||||
* {
|
||||
background: silver
|
||||
}*/
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- Content -->
|
||||
|
||||
<div class='wrapper'>
|
||||
{% for video in videos %}
|
||||
<div class='video-box'>
|
||||
<div class='media' id='media-{{ video.id }}'>
|
||||
<span class='video-thumbnail' id='thumb-{{ video.id }}' onclick="loadPlayer('{{ video.id }}', '{{ host }}{{ video.embed_path }}')" href="{{ host }}/videos/watch/{{ video.uuid }}">
|
||||
<img src="{{ host }}{{ video.preview_path }}">
|
||||
<div class="video-thumbnail-duration-overlay">
|
||||
{% if video.is_live %}
|
||||
LIVE
|
||||
{% else %}
|
||||
{{ video.duration | duration }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="play-overlay">
|
||||
<div class="play-icon"></div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class='metadata'>
|
||||
<div class='title'>{{ video.name }}</div>
|
||||
<span class="description collapsed" id='meta-{{ video.id }}'> {{ video.description | linebreaks }}</span>
|
||||
<div class='footer'>
|
||||
<span class='channel'><a href='{{ video.channel.url }}'> {{ video.channel.display_name }}</a></span>
|
||||
|
||||
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#meta-{{ video.id }}')"> <a href='#'> </a></span>
|
||||
|
||||
<span class='date'> <a href='{{ host }}/videos/watch/{{ video.uuid }}'> {{ video.published_at.strftime('%Y-%m-%d') }}</a></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
</body>
|
||||
<script>
|
||||
function toggleDescription(id){
|
||||
document.querySelector(id).classList.toggle("collapsed");
|
||||
}
|
||||
function loadPlayer(id, embed_path){
|
||||
media = document.querySelector('#media-'+ id)
|
||||
|
||||
var iframe = document.createElement('iframe');
|
||||
iframe.src = embed_path + '?autoplay=1&title=0'
|
||||
iframe.width = 560;
|
||||
iframe.height = 315;
|
||||
iframe.frameBorder = 0;
|
||||
iframe.sandbox = "allow-same-origin allow-scripts allow-popups"
|
||||
media.appendChild(iframe)
|
||||
document.querySelector('#thumb-'+ id).remove()
|
||||
}
|
||||
</script>
|
||||
</html>
|
131
lumbung-video-prototype/video-feed.py
Normal file
131
lumbung-video-prototype/video-feed.py
Normal file
@ -0,0 +1,131 @@
|
||||
#!/bin/python3
|
||||
|
||||
#lumbung.space video feed generator
|
||||
#c 2021 roel roscam abbing gpvl3 etc
|
||||
|
||||
import peertube
|
||||
import jinja2
|
||||
import json
|
||||
import os
|
||||
import datetime
|
||||
import shutil
|
||||
import requests
|
||||
import ast
|
||||
import arrow
|
||||
|
||||
|
||||
#jinja filters & config
|
||||
def duration(n):
|
||||
"""
|
||||
convert '6655' in '1:50:55'
|
||||
|
||||
"""
|
||||
return str(datetime.timedelta(seconds = n))
|
||||
|
||||
def linebreaks(text):
|
||||
if not text:
|
||||
return text
|
||||
else:
|
||||
import re
|
||||
br = re.compile(r"(\r\n|\r|\n)")
|
||||
return br.sub(r"<br />\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=100, filter='local', tags_one_of='publish')
|
||||
|
||||
videos = response.to_dict()
|
||||
videos = videos['data']
|
||||
|
||||
|
||||
def create_post(post_directory, video_metadata):
|
||||
global client #lazy
|
||||
|
||||
if not os.path.exists(post_dir):
|
||||
os.mkdir(post_directory)
|
||||
|
||||
preview_image = video_metadata['preview_path'].split('/')[-1]
|
||||
|
||||
if not os.path.exists(os.path.join(post_directory, preview_image)):
|
||||
#download preview image
|
||||
response = requests.get(host+video_metadata['preview_path'], stream=True)
|
||||
with open(os.path.join(post_directory, preview_image), 'wb') as img_file:
|
||||
shutil.copyfileobj(response.raw, img_file)
|
||||
print('Downloaded cover image')
|
||||
|
||||
#replace the truncated description with the full video description
|
||||
#peertube api is some broken thing in between a py dict and a json file
|
||||
api_response = peertube.VideoApi(client).videos_id_description_get(video_metadata['uuid'])
|
||||
long_description = ast.literal_eval(api_response)
|
||||
video_metadata['description'] = long_description['description']
|
||||
|
||||
|
||||
with open(os.path.join(post_directory,'index.md'),'w') as f:
|
||||
post = template.render(v=video_metadata, host=host, preview_image=preview_image)
|
||||
f.write(post)
|
||||
|
||||
|
||||
with open(os.path.join(post_directory, '.timestamp'), 'w') as f:
|
||||
timestamp = arrow.get(video_metadata['updated_at'])
|
||||
f.write(timestamp.format('X'))
|
||||
|
||||
def update_post(post_directory, video_metadata):
|
||||
if os.path.exists(post_directory):
|
||||
if os.path.exists(os.path.join(post_directory,'.timestamp')):
|
||||
old_timestamp = open(os.path.join(post_directory,'.timestamp')).read()
|
||||
|
||||
#FIXME: this is ugly but I need to do this because arrow removes miliseconds
|
||||
current_timestamp = arrow.get(video_metadata['updated_at'])
|
||||
current_timestamp = arrow.get(current_timestamp.format('X'))
|
||||
|
||||
if current_timestamp > arrow.get(old_timestamp):
|
||||
print('Updating', video_metadata['name'], '({})'.format(video_metadata['uuid']))
|
||||
create_post(post_dir, video_metadata)
|
||||
else:
|
||||
print('Video current: ', video_metadata['name'], '({})'.format(video_metadata['uuid']))
|
||||
else:
|
||||
#compat for when there is no timestamp yet..
|
||||
create_post(post_dir, video_metadata)
|
||||
|
||||
|
||||
output_dir = os.environ.get('OUTPUT_DIR', '/home/r/Programming/lumbung.space/lumbung.space-web/content/video')
|
||||
|
||||
if not os.path.exists(output_dir):
|
||||
os.mkdir(output_dir)
|
||||
|
||||
template = env.get_template('index_template.md')
|
||||
|
||||
existing_posts = os.listdir(output_dir)
|
||||
|
||||
for video_metadata in videos:
|
||||
post_dir = os.path.join(output_dir, video_metadata['uuid'])
|
||||
|
||||
if video_metadata['uuid'] not in existing_posts: #if there is a video we dont already have, make it
|
||||
print('New: ', video_metadata['name'], '({})'.format(video_metadata['uuid']))
|
||||
create_post(post_dir, video_metadata)
|
||||
|
||||
elif video_metadata['uuid'] in existing_posts: # if we already have the video do nothing, possibly update
|
||||
update_post(post_dir, video_metadata)
|
||||
existing_posts.remove(video_metadata['uuid']) # create list of posts which have not been returned by peertube
|
||||
|
||||
for post in existing_posts:
|
||||
print('deleted', post) #rm posts not returned
|
||||
shutil.rmtree(os.path.join(output_dir,post))
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user