Files
MyPodcastCollection/genfeed.py
2022-03-25 16:17:04 +01:00

57 lines
2.0 KiB
Python
Executable File

#!/usr/bin/python
import rfeed
import datetime
import os
import pathlib
items = []
weblist = []
for file in os.listdir("files"):
try:
day, month, year = list(map(int, file.split("_")[-1][:-4].split(".")))
except ValueError:
print(f"{file}: name malformed?")
continue
date = datetime.datetime(year, month, day)
items.append(rfeed.Item(
title=f"Podcast {file}",
link = "",
description = "",
author = "",
guid = rfeed.Guid(file),
enclosure = rfeed.Enclosure(url=f"https://dukun.de/xox/mycast/files/{file}", length=os.path.getsize(f"files/{file}"), type="audio/mpeg"),
pubDate = date
))
weblist.append([f"{year}-{month}-{day}", file])
feed = rfeed.Feed(
title = "My podcast collection from anywhere",
link = "",
description = "",
language = "de-DE",
lastBuildDate = datetime.datetime.now(),
items = items)
with open("feed.xml", "w") as f:
f.write(feed.rss())
# generate web listener
weblist.sort()
with open("index.html", "w") as f:
# site header
f.write("""<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><link rel="stylesheet" type="text/css" href="../ZanderZeichen/style.css"><link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico"><meta name="robots" content="noindex,nofollow" /></head><body class=body><div class=head></div><h3>&nbsp;</h3><div class=box><h2>Podcastsammlung Webplayer</h2><a href=feed.xml><img style="float:right;" src=316px-Feed-icon_headphones.svg_from_commons.wikimedia.org_by_Marek_Mazurkiewicz.png /></a><br>""")
# sort list
weblist.sort(reverse=True, key=lambda x: f"{x[-1][2]:0>4d}-{x[-1][1]:0>2d}-{x[-1][0]:0>2d}")
# site entries
for entry in weblist:
date, filename = entry
f.write(f"{filename}<br><audio controls><source src=\"files/{filename}\" type=\"audio/mp3\"></audio><br><br>")
# site footer
f.write("""</div><div class=foot><a href="https://dukun.de">dukun.de</a></div></body></html>""")