Browse Source

video feed generator tailored to hugo

pull/1/head
rra 3 years ago
parent
commit
5840b01cf6
  1. 14
      index_template.md
  2. 4
      streams-feed.py
  3. 167
      video-feed-prototype.html
  4. 91
      video-feed.py

14
index_template.md

@ -0,0 +1,14 @@
---
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 }}"
category: "tv"
---
{{ v.description }}

4
streams-feed.py

@ -45,11 +45,11 @@ configuration = peertube.Configuration(
host = host+"/api/v1"
)
client = peertube.ApiClient(configuration)
client = peertube.ApiClient(configuration)
v = peertube.VideoApi(client)
response = v.videos_get(count=6, filter='local')#, tags_one_of='audio')
response = v.videos_get(count=6, filter='local')#, tags_one_of='publish')
videos = response.to_dict()
videos = videos['data']

167
video-feed-prototype.html

@ -9,7 +9,7 @@
<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="https://tv.lumbung.space/lazy-static/previews/295dcb6d-7409-4bf7-8c3c-97b67b3775bc.jpg">
<meta property="og:image" content="https://tv.lumbung.space/lazy-static/previews/709054e1-dd2e-4cbc-a3fa-5bee1e18c56e.jpg">
<meta property="og:image:alt" content="Image description">
<meta property="og:locale" content="en_GB">
<meta property="og:type" content="website">
@ -200,13 +200,12 @@
<div class='wrapper'>
<div class='video-box'>
<div class='media'>
<a class='video-thumbnail' href="https://tv.lumbung.space/videos/watch/75fbc455-2491-4df2-994c-92062801ecf3">
<img src="https://tv.lumbung.space/lazy-static/previews/295dcb6d-7409-4bf7-8c3c-97b67b3775bc.jpg">
<!-- <iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" src="https://tv.lumbung.space/videos/embed/75fbc455-2491-4df2-994c-92062801ecf3" frameborder="0" allowfullscreen></iframe> -->
<div class='media' id='media-93'>
<span class='video-thumbnail' id='thumb-93' onclick="loadPlayer('93', 'https://tv.lumbung.space/videos/embed/31650645-820e-45b5-a068-05479eaa3fa8')" href="https://tv.lumbung.space/videos/watch/31650645-820e-45b5-a068-05479eaa3fa8">
<img src="https://tv.lumbung.space/lazy-static/previews/709054e1-dd2e-4cbc-a3fa-5bee1e18c56e.jpg">
<div class="video-thumbnail-duration-overlay">
0:47:37
1:06:35
</div>
<div class="play-overlay">
@ -215,31 +214,25 @@
</a>
</div>
<div class='metadata'>
<div class='title'>Sonic Liberation Front - 24/05/21</div>
<span class="description collapsed" id='vid-40'> Mirror from Radio Alhara<br />
https://yamakan.place/palestine/<br />
<br />
Recording on 24/5/21 from 15:00 - 15:45 Betlehem time.<br />
<br />
Radio Alhara is a radio station based in Bethlehem, Ramallah and Amman. Launched during a global lockdown crisis in March 2020,...</span>
<div class='title'>[AUDIO] DENDANG PETANG - SEMAKBELUKAR Live at Kineruku, Bandung (08 December 2013)</div>
<span class="description collapsed" id='meta-93'> What SEMAKBELUKAR or Belukaria Orkestar performed at their last concert at Kineruku, Bandung in 2013 was not a sad celebration like a farewell that will certainly not meet again in the future. More than that, they know how to celebrate the reperto...</span>
<div class='footer'>
<span class='channel'><a href='https://tv.lumbung.space/video-channels/sonicliberation'> Sonic Liberation Front</a></span>
<span class='channel'><a href='https://tv.lumbung.space/video-channels/rahmat.arham_channel'> Main rahmat.arham channel</a></span>
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#vid-40')"> <a href='#'> </a></span>
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#meta-93')"> <a href='#'> </a></span>
<span class='date'> <a href='https://tv.lumbung.space/videos/watch/75fbc455-2491-4df2-994c-92062801ecf3'> 2021-05-24</a></span>
<span class='date'> <a href='https://tv.lumbung.space/videos/watch/31650645-820e-45b5-a068-05479eaa3fa8'> 2021-07-05</a></span>
</div>
</div>
</div>
<div class='video-box'>
<div class='media'>
<a class='video-thumbnail' href="https://tv.lumbung.space/videos/watch/698d6eb1-c76a-4b0a-ae32-e11692b356fb">
<img src="https://tv.lumbung.space/lazy-static/previews/464da572-89da-46ae-90c8-82dae3cea325.jpg">
<!-- <iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" src="https://tv.lumbung.space/videos/embed/698d6eb1-c76a-4b0a-ae32-e11692b356fb" frameborder="0" allowfullscreen></iframe> -->
<div class='media' id='media-90'>
<span class='video-thumbnail' id='thumb-90' onclick="loadPlayer('90', 'https://tv.lumbung.space/videos/embed/e6d5bb2a-d77f-4a00-a449-992a579c8c0d')" href="https://tv.lumbung.space/videos/watch/e6d5bb2a-d77f-4a00-a449-992a579c8c0d">
<img src="https://tv.lumbung.space/lazy-static/previews/32291aa2-a391-4219-a413-87521ff373ba.jpg">
<div class="video-thumbnail-duration-overlay">
4:30:16
0:14:39
</div>
<div class="play-overlay">
@ -248,31 +241,25 @@ Radio Alhara is a radio station based in Bethlehem, Ramallah and Amman. Launched
</a>
</div>
<div class='metadata'>
<div class='title'>Sonic Liberation Front - 23/05/2021</div>
<span class="description collapsed" id='vid-35'> Mirror from Radio Alhara<br />
https://yamakan.place/palestine/<br />
<br />
Recording on 22/5/21 from 17:30 - 22:15 Betlehem time.<br />
<br />
Radio Alhara is a radio station based in Bethlehem, Ramallah and Amman. Launched during a global lockdown crisis in March 2020,...</span>
<div class='title'>Keroncong Tugu Cafrinho, Live at RURU Gallery, ruangrupa, Jakarta (19 August 2014)</div>
<span class="description collapsed" id='meta-90'> None</span>
<div class='footer'>
<span class='channel'><a href='https://tv.lumbung.space/video-channels/sonicliberation'> Sonic Liberation Front</a></span>
<span class='channel'><a href='https://tv.lumbung.space/video-channels/ruangrupa_ruru_channel'> ruangrupa</a></span>
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#vid-35')"> <a href='#'> </a></span>
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#meta-90')"> <a href='#'> </a></span>
<span class='date'> <a href='https://tv.lumbung.space/videos/watch/698d6eb1-c76a-4b0a-ae32-e11692b356fb'> 2021-05-23</a></span>
<span class='date'> <a href='https://tv.lumbung.space/videos/watch/e6d5bb2a-d77f-4a00-a449-992a579c8c0d'> 2021-07-03</a></span>
</div>
</div>
</div>
<div class='video-box'>
<div class='media'>
<a class='video-thumbnail' href="https://tv.lumbung.space/videos/watch/752f7991-995d-4a2f-a1a4-41cc5688b078">
<img src="https://tv.lumbung.space/lazy-static/previews/ce21bca7-c866-4093-b3d6-06e155291dfa.jpg">
<!-- <iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" src="https://tv.lumbung.space/videos/embed/752f7991-995d-4a2f-a1a4-41cc5688b078" frameborder="0" allowfullscreen></iframe> -->
<div class='media' id='media-88'>
<span class='video-thumbnail' id='thumb-88' onclick="loadPlayer('88', 'https://tv.lumbung.space/videos/embed/4ab2ce65-7cdd-4cb5-b197-20bebd626c17')" href="https://tv.lumbung.space/videos/watch/4ab2ce65-7cdd-4cb5-b197-20bebd626c17">
<img src="https://tv.lumbung.space/lazy-static/previews/c1291d9a-2dd5-453f-b13a-2c476b379a35.jpg">
<div class="video-thumbnail-duration-overlay">
0:56:42
0:11:55
</div>
<div class="play-overlay">
@ -281,29 +268,25 @@ Radio Alhara is a radio station based in Bethlehem, Ramallah and Amman. Launched
</a>
</div>
<div class='metadata'>
<div class='title'>MAJÁLIS - A Lumbung tagok bemutatása | Politikai ágencia</div>
<span class="description collapsed" id='vid-39'> POLITICAL AGENCY<br />
The discussion will explore the possibilities for art’s funding and political agency from the perspective of grassroots collectives.<br />
<br />
A conversation with the participation of Question of Funding (Palestine), hosted by OFF-Biennale...</span>
<div class='title'>ruangrupa (2000-2014)</div>
<span class="description collapsed" id='meta-88'> ruangrupa (selalu ditulis dalam huruf kecil dan tanpa spasi) adalah organisasi seni rupa kontemporer yang didirikan pada tahun 2000 oleh sekelompok seniman di Jakarta. Sebagai organisasi nirlaba, ruangrupa bergiat mendorong kemajuan gagasan seni r...</span>
<div class='footer'>
<span class='channel'><a href='https://tv.lumbung.space/video-channels/majelis'> Majelis</a></span>
<span class='channel'><a href='https://tv.lumbung.space/video-channels/ruangrupa_ruru_channel'> ruangrupa</a></span>
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#vid-39')"> <a href='#'> </a></span>
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#meta-88')"> <a href='#'> </a></span>
<span class='date'> <a href='https://tv.lumbung.space/videos/watch/752f7991-995d-4a2f-a1a4-41cc5688b078'> 2021-05-23</a></span>
<span class='date'> <a href='https://tv.lumbung.space/videos/watch/4ab2ce65-7cdd-4cb5-b197-20bebd626c17'> 2021-07-03</a></span>
</div>
</div>
</div>
<div class='video-box'>
<div class='media'>
<a class='video-thumbnail' href="https://tv.lumbung.space/videos/watch/4eff6150-b688-4c42-958f-6e206319554d">
<img src="https://tv.lumbung.space/lazy-static/previews/9ce1f7f8-13cb-436b-8313-01d020bc8d1c.jpg">
<!-- <iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" src="https://tv.lumbung.space/videos/embed/4eff6150-b688-4c42-958f-6e206319554d" frameborder="0" allowfullscreen></iframe> -->
<div class='media' id='media-86'>
<span class='video-thumbnail' id='thumb-86' onclick="loadPlayer('86', 'https://tv.lumbung.space/videos/embed/65fd5f7f-1303-4d7b-92e4-033cbcf28515')" href="https://tv.lumbung.space/videos/watch/65fd5f7f-1303-4d7b-92e4-033cbcf28515">
<img src="https://tv.lumbung.space/lazy-static/previews/b0c69309-2efb-4047-a78f-afc405533a50.jpg">
<div class="video-thumbnail-duration-overlay">
5:07:46
1:31:07
</div>
<div class="play-overlay">
@ -312,31 +295,34 @@ A conversation with the participation of Question of Funding (Palestine), hosted
</a>
</div>
<div class='metadata'>
<div class='title'>Sonic Liberation Front / Frente de Liberación Sonoro - 22/5/2021</div>
<span class="description collapsed" id='vid-30'> Mirror from Radio Alhara<br />
https://yamakan.place/palestine/<br />
<div class='title'>lumbung calling: Humor</div>
<span class="description collapsed" id='meta-86'> lumbung calling: Humor<br />
Saturday, May 1st, 2021<br />
2.30 pm (CET), 3.30 pm (IDT), 7.30 pm (WIB)<br />
In English with translation into International Sign Language<br />
<br />
Recording on 22/5/21 from 19:00 - 24:00 Betlehem time.<br />
Guests: <br />
Sourabh Phadke, Architect and School Teacher<br />
Gridthiya Gaweewong, Curator <br />
<br />
Radio Alhara is a radio station based in Bethlehem, Ramallah and Amman. Launched during a global lockdown crisis in March 2020,...</span>
...</span>
<div class='footer'>
<span class='channel'><a href='https://tv.lumbung.space/video-channels/sonicliberation'> Sonic Liberation Front</a></span>
<span class='channel'><a href='https://tv.lumbung.space/video-channels/lumbung_calling'> lumbung calling</a></span>
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#vid-30')"> <a href='#'> </a></span>
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#meta-86')"> <a href='#'> </a></span>
<span class='date'> <a href='https://tv.lumbung.space/videos/watch/4eff6150-b688-4c42-958f-6e206319554d'> 2021-05-22</a></span>
<span class='date'> <a href='https://tv.lumbung.space/videos/watch/65fd5f7f-1303-4d7b-92e4-033cbcf28515'> 2021-07-03</a></span>
</div>
</div>
</div>
<div class='video-box'>
<div class='media'>
<a class='video-thumbnail' href="https://tv.lumbung.space/videos/watch/73d9f872-ea75-490c-a1be-60a398bac45e">
<img src="https://tv.lumbung.space/lazy-static/previews/6df9f482-ac52-45aa-a46b-5265df4439ee.jpg">
<!-- <iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" src="https://tv.lumbung.space/videos/embed/73d9f872-ea75-490c-a1be-60a398bac45e" frameborder="0" allowfullscreen></iframe> -->
<div class='media' id='media-87'>
<span class='video-thumbnail' id='thumb-87' onclick="loadPlayer('87', 'https://tv.lumbung.space/videos/embed/9691360d-5362-4754-84ad-f62c140eea3a')" href="https://tv.lumbung.space/videos/watch/9691360d-5362-4754-84ad-f62c140eea3a">
<img src="https://tv.lumbung.space/lazy-static/previews/3494d661-4a00-4e27-8282-93a7a5d1c667.jpg">
<div class="video-thumbnail-duration-overlay">
6:28:45
1:24:29
</div>
<div class="play-overlay">
@ -345,31 +331,32 @@ Radio Alhara is a radio station based in Bethlehem, Ramallah and Amman. Launched
</a>
</div>
<div class='metadata'>
<div class='title'>Sonic Liberation Front - 21/5/21</div>
<span class="description collapsed" id='vid-20'> Mirror from Radio Alhara<br />
https://yamakan.place/palestine/<br />
<div class='title'>lumbung calling: Independence</div>
<span class="description collapsed" id='meta-87'> lumbung calling: Independence<br />
<br />
Recording on 21/5/21 from 14:00 - 19:00 Betlehem time. <br />
Saturday, June 5, 2021<br />
8.30 am (CDT), 2.30 pm (CET), 3.30 pm (EEST), 7.30 pm (WIB) <br />
In English with translation into International Sign Language<br />
<br />
Radio Alhara is a radio station based in Bethlehem, Ramallah and Amman. Launched during a global lockdown crisis in March 2020...</span>
Guests: <br />
Tania Bruguera, founder of Instituto de Artivismo Hann...</span>
<div class='footer'>
<span class='channel'><a href='https://tv.lumbung.space/video-channels/sonicliberation'> Sonic Liberation Front</a></span>
<span class='channel'><a href='https://tv.lumbung.space/video-channels/lumbung_calling'> lumbung calling</a></span>
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#vid-20')"> <a href='#'> </a></span>
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#meta-87')"> <a href='#'> </a></span>
<span class='date'> <a href='https://tv.lumbung.space/videos/watch/73d9f872-ea75-490c-a1be-60a398bac45e'> 2021-05-21</a></span>
<span class='date'> <a href='https://tv.lumbung.space/videos/watch/9691360d-5362-4754-84ad-f62c140eea3a'> 2021-07-03</a></span>
</div>
</div>
</div>
<div class='video-box'>
<div class='media'>
<a class='video-thumbnail' href="https://tv.lumbung.space/videos/watch/b4aafef4-892f-4036-a4bc-2e09027e2b4b">
<img src="https://tv.lumbung.space/lazy-static/previews/330965b6-f172-47bc-a914-d7d790858352.jpg">
<!-- <iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" src="https://tv.lumbung.space/videos/embed/b4aafef4-892f-4036-a4bc-2e09027e2b4b" frameborder="0" allowfullscreen></iframe> -->
<div class='media' id='media-85'>
<span class='video-thumbnail' id='thumb-85' onclick="loadPlayer('85', 'https://tv.lumbung.space/videos/embed/e34800e2-1065-4945-8e02-958719e456a9')" href="https://tv.lumbung.space/videos/watch/e34800e2-1065-4945-8e02-958719e456a9">
<img src="https://tv.lumbung.space/lazy-static/previews/d6e8befd-ce10-4f6c-9bdc-b52124af1325.jpg">
<div class="video-thumbnail-duration-overlay">
LIVE
1:42:16
</div>
<div class="play-overlay">
@ -378,18 +365,20 @@ Radio Alhara is a radio station based in Bethlehem, Ramallah and Amman. Launched
</a>
</div>
<div class='metadata'>
<div class='title'>Sonic Liberation Front</div>
<span class="description collapsed" id='vid-21'> Ongoing mirror of Radio Alhara<br />
<br />
https://yamakan.place/palestine/<br />
<div class='title'>lumbung calling: Local Anchor</div>
<span class="description collapsed" id='meta-85'> lumbung calling: Local Anchor <br />
Saturday, April 3, 2021<br />
2.30 pm (CET), 7.30 pm (WIB), 8.30 pm (WITA)<br />
In English with translation into International Sign Language<br />
<br />
Radio Alhara is a radio station based in Bethlehem, Ramallah and Amman. Launched during a global lockdown crisis in March 2020, it encompasses the idea of a public space. The ra...</span>
Guests: <br />
Melani Budianta, Professor of Literature and Cultural Studies at Unive...</span>
<div class='footer'>
<span class='channel'><a href='https://tv.lumbung.space/video-channels/sonicliberation'> Sonic Liberation Front</a></span>
<span class='channel'><a href='https://tv.lumbung.space/video-channels/lumbung_calling'> lumbung calling</a></span>
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#vid-21')"> <a href='#'> </a></span>
<span class='descr_button' id='toggle-button' onclick="toggleDescription('#meta-85')"> <a href='#'> </a></span>
<span class='date'> <a href='https://tv.lumbung.space/videos/watch/b4aafef4-892f-4036-a4bc-2e09027e2b4b'> 2021-05-21</a></span>
<span class='date'> <a href='https://tv.lumbung.space/videos/watch/e34800e2-1065-4945-8e02-958719e456a9'> 2021-07-03</a></span>
</div>
</div>
</div>
@ -401,5 +390,17 @@ Radio Alhara is a radio station based in Bethlehem, Ramallah and Amman. Launched
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>

91
video-feed.py

@ -8,8 +8,12 @@ import jinja2
import json
import os
import datetime
import shutil
import requests
from slugify import slugify
#jinja filters & config
def duration(n):
"""
convert '6655' in '1:50:55'
@ -18,23 +22,20 @@ def duration(n):
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
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
env.filters['slugify'] = slugify
host = 'https://tv.lumbung.space'
@ -42,20 +43,74 @@ configuration = peertube.Configuration(
host = host+"/api/v1"
)
client = peertube.ApiClient(configuration)
client = peertube.ApiClient(configuration)
v = peertube.VideoApi(client)
response = v.videos_get(count=6, filter='local')
response = v.videos_get(count=1000, filter='local', tags_one_of='publish')
videos = response.to_dict()
videos = videos['data']
template = env.get_template('video-feed.html')
html = template.render(videos=videos, host=host, description=description)
def create_post(post_directory, video_metadata):
global client
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('got image')
else:
print('image exists')
#FIXME replace the truncated description with the full video description
api_response = peertube.VideoApi(client).videos_id_description_get(v['uuid'])
import ast
long_description = ast.literal_eval(api_response)
v['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)
print(video_metadata['uuid'], 'written')
output_dir = '/home/r/Programming/lumbung.space/ssg_experiment/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)
#compare returned video uuid to existing posts to determine:
# video - existing post
# 1 0 > create
# 0 1 > delete
# 1 1 > ignore or update
# 0 0 > nothing
for v in videos:
if v['uuid'] not in existing_posts: #if there is a video we dont already have, make it
post_dir = os.path.join(output_dir,v['uuid'])
create_post(post_dir, v)
elif v['uuid'] in existing_posts: # if we already have the video do nothing, possibly update
print(v['uuid'],'already exists')
existing_posts.remove(v['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))
with open('video-feed-prototype.html','w') as f:
f.write(html)
print(html)

Loading…
Cancel
Save