Browse Source

adding a podcast mode

technodisobedience
mb 12 months ago
parent
commit
d1bb14fab0
  1. 32
      octomode.py
  2. 2
      templates/base.html
  3. 10
      templates/podcast.rss

32
octomode.py

@ -4,6 +4,7 @@ from flask import Flask, request, render_template, render_template_string, redir
from urllib.request import urlopen from urllib.request import urlopen
from urllib.parse import urlencode, urlparse from urllib.parse import urlencode, urlparse
import subprocess import subprocess
from jinja2 import Template
# To sanitize Flask input fields # To sanitize Flask input fields
from markupsafe import Markup, escape from markupsafe import Markup, escape
@ -195,7 +196,13 @@ def wildcardtemplate(name):
@APP.route('/<name>/wildcard/') @APP.route('/<name>/wildcard/')
def wildcard(name): def wildcard(name):
app_root = get_app_root() app_root = get_app_root()
url = f"{ app_root }/{name}/wildcard.raw" url = url_for("wildcardpage", name=name)
return render_template('iframe.html', url=url, name=name.strip())
@APP.route('/<name>/podcast/')
def podcast(name):
app_root = get_app_root()
url = f"{ app_root }/{ name }/podcast.rss"
return render_template('iframe.html', url=url, name=name.strip()) return render_template('iframe.html', url=url, name=name.strip())
# ////////////////// # //////////////////
@ -243,7 +250,7 @@ def preview(name):
@APP.route('/<name>/pagedjs.html') @APP.route('/<name>/pagedjs.html')
def pagedjs(name): def pagedjs(name):
# TO GENERATE THE PAGED.JS WEBPAGE # TO GENERATE THE PAGED.JS PAGE
md_pad_content = get_pad_content(name, ext='.md') md_pad_content = get_pad_content(name, ext='.md')
html = md_to_html(md_pad_content, name) html = md_to_html(md_pad_content, name)
metadata = get_md_metadata(md_pad_content) metadata = get_md_metadata(md_pad_content)
@ -252,28 +259,39 @@ def pagedjs(name):
return render_template('pagedjs.html', name=name.strip(), pad_content=html, lang=lang, title=title) return render_template('pagedjs.html', name=name.strip(), pad_content=html, lang=lang, title=title)
@APP.route('/<name>/wildcard.raw') @APP.route('/<name>/wildcard.html')
def wildcardpage(name): def wildcardpage(name):
md_pad_content = get_pad_content(name, ext='.md') md_pad_content = get_pad_content(name, ext='.md')
wildcard_template_pad_content = get_pad_content(name, ext='.wildcard-template.html') wildcard_template_pad_content = get_pad_content(name, ext='.wildcard-template.html')
audio = [] audio = []
for line in md_pad_content.splitlines(): for line in md_pad_content.splitlines():
# if any(ext in line for ext in [".mp3", ".ogg"]):
if ".mp3" in line: if ".mp3" in line:
audio.append(line) audio.append(line)
elif ".ogg" in line:
audio.append(line)
return render_template_string(wildcard_template_pad_content, name=name.strip(), audio=audio) return render_template_string(wildcard_template_pad_content, name=name.strip(), audio=audio)
@APP.route('/<name>/podcast.rss') @APP.route('/<name>/podcast.rss')
def rss(name): def rss(name):
# parse for audio links
md_pad_content = get_pad_content(name, ext='.md') md_pad_content = get_pad_content(name, ext='.md')
audio = [] audio = []
for line in md_pad_content.splitlines(): for line in md_pad_content.splitlines():
# if any(ext in line for ext in [".mp3", ".ogg"]):
if ".mp3" in line: if ".mp3" in line:
audio.append(line) audio.append(line)
# parse metadata
return template_pad_content, 200, {'Content-Type': 'text/plain; charset=utf-8'} metadata = get_md_metadata(md_pad_content)
title = metadata['title'][0]
app_url = get_app_hostname() + get_app_root()
octomode_link = app_url + url_for("main", name=name)
rss_link = app_url + url_for("rss", name=name)
# render podcast.rss template
with open("templates/podcast.rss", "r") as t:
template = Template(t.read())
rss = template.render(name=name.strip(), title=title, audio=audio, octomode_link=octomode_link, rss_link=rss_link)
return rss, 200, {'Content-Type': 'text/xml; charset=utf-8'}
# ////////////////// # //////////////////

2
templates/base.html

@ -47,6 +47,8 @@ window.addEventListener('load', function () {
<a href="{{ url_for('wildcard', name=name) }}"><button>*</button></a> <a href="{{ url_for('wildcard', name=name) }}"><button>*</button></a>
<a class="link" href="{{ url_for('wildcardpage', name=name) }}" target="_blank"> 🔗</a> <a class="link" href="{{ url_for('wildcardpage', name=name) }}" target="_blank"> 🔗</a>
<a href="{{ url_for('podcast', name=name) }}"><button>podcast</button></a>
<a class="link" href="{{ url_for('rss', name=name) }}" target="_blank"> 🔗</a>
</div>`; </div>`;

10
templates/podcast.rss

@ -1,18 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel> <channel>
<title>{{title}}</title> <title>{{ title }}</title>
<link>https://later</link> <link>{{ octomode_link }}</link>
<description>Podcast generated etcot.</description> <description>Podcast generated etcot.</description>
<lastBuildDate>builtdate..todo</lastBuildDate> <lastBuildDate>builtdate..todo</lastBuildDate>
<atom:link href="todo.xml" rel="self" type="application/rss+xml" /> <atom:link href="{{ rss_link }}" rel="self" type="application/rss+xml" />
{% for link in audio %} {% for link in audio %}
<item> <item>
<pubDate>todo</pubDate> <pubDate>todo</pubDate>
<enclosure url="{{link}}" type="audio/mpeg" /> <enclosure url="{{ link }}" type="audio/mpeg" />
</item> </item>
{% endfor %} {% endfor %}
</channel> </channel>
</rss> </rss>

Loading…
Cancel
Save