Commit be0a387

benny-dou <60535774+benny-dou@users.noreply.github.com>
2026-06-16 08:34:31
feat(podcast): add audio in HTML
1 parent 41956df
Changed files (1)
src
podcast
src/podcast/main.py
@@ -47,9 +47,10 @@ from ytdlp.download import ytdlp_download
 
 async def summary_pods(client: Client):
     """Summary podcast RSS feeds."""
-    pods = await get_feed_url_with_title()
+    pods = await get_feed_url_with_title()  # {feed_url: title}
     if not pods:
         return
+    # pods = {"https://feed.xyzfm.space/q88qwmydeuw8": "声动早咖啡"}  # for debug
     for feed_url, feed_title in pods.items():
         feed = await parse_feed(feed_url)
         if not feed:
@@ -76,6 +77,9 @@ async def summary_pods(client: Client):
                 caption = f"🎧[{feed_title}]({homepage})\n📝[{entry['title']}]({entry['link']})\n🕒{pubdate}\n⏳{duration} #️⃣字数: {count_subtitles(transcripts)}"
                 desc = glom(entry, Coalesce("content.0.value", "summary"), default="")
                 desc_html = desc if desc.startswith("<") else convert2html(desc)
+                enclosure_url = next((x["href"] for x in entry["links"] if x.get("rel", "") == "enclosure"), "")
+                enclosure_mime = next((x["type"] for x in entry["links"] if x.get("rel", "") == "enclosure"), "audio/mp4")
+                desc_html = f'<audio controls preload="metadata" style="width:100%;"><source src="{enclosure_url}" type="{enclosure_mime}">该浏览器不支持音频播放</audio>\n' + desc_html
                 prompt = f"该转录稿对应于播客栏目《{feed_title}》的一期节目,节目详情:\n标题: {entry['title']}\n日期: {pubdate}\n时长: {duration}\n节目简介: {desc}"
                 summary = await summarize(
                     sources=[{"type": "system_prompt", "text": prompt}, {"type": "transcripts", "text": transcripts}],