Now Playing lists an episode's chapters, and a tap plays from there (#477)

Where they come from, in order: the chapters file an item names
(<podcast:chapters url>, the Podcasting 2.0 namespace's JSON), stored on
the item as entries.chapters and read when someone opens Now Playing; else
the downloaded file's own chapters (ID3 CHAP frames, MP4 chapters), which
ffprobe reads as it does for DeadAir. A chapter with toc false is only
there to change the artwork and is left out.

GET /api/enclosures/{id}/chapters answers for a file, since a file is what
plays. With ?deadair=true the starts are moved into DeadAir's shortened
clock with to_copy, as positions are, or a chapter would start late by
every silence cut before it. A chapters file that cannot be read is an
empty list: the player plays on without them, and the step's span says why.

Items already stored get their chapters address when a scan next finds
them told differently; feeds that answer 304 add it with their next items.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RqkrVBuJRne2JAhFpaDV2U
This commit is contained in:
2026-11-22 12:02:22 -05:00
parent f633f3d692
commit 882cd5f03c
16 changed files with 310 additions and 7 deletions

View File

@@ -46,6 +46,9 @@ pub struct Entry {
pub duration: Option<i64>,
pub episode: Option<i64>,
pub season: Option<i64>,
/// Where its chapters are, `<podcast:chapters url>`: a JSON file of the Podcasting 2.0
/// namespace's, read when someone plays it (#477).
pub chapters: Option<String>,
pub enclosures: Vec<Enclosure>,
}
@@ -283,6 +286,7 @@ pub(crate) fn from_rss(ch: rss::Channel, bytes: &[u8]) -> ParsedFeed {
duration: it.and_then(|i| i.duration()).and_then(parse_duration),
episode: it.and_then(|i| i.episode()).and_then(|e| e.trim().parse().ok()),
season: it.and_then(|i| i.season()).and_then(|e| e.trim().parse().ok()),
chapters: podcast_chapters(item),
enclosures,
})
})
@@ -348,6 +352,7 @@ pub(crate) fn from_atom(feed: atom_syndication::Feed) -> ParsedFeed {
duration: None,
episode: None,
season: None,
chapters: None,
enclosures,
})
})
@@ -460,6 +465,12 @@ pub(crate) fn notes(content: Option<&str>, description: Option<&str>, markdown:
///
/// shortcut: found by the `source` prefix the namespace's own docs and feeds use; a feed binding
/// it to another prefix is not read, until one turns up.
/// `<podcast:chapters url="..." type="application/json+chapters">`, by the prefix feeds give it.
fn podcast_chapters(item: &rss::Item) -> Option<String> {
let url = item.extensions().get("podcast")?.get("chapters")?.first()?.attrs().get("url")?.trim();
(url.starts_with("http://") || url.starts_with("https://")).then(|| url.to_owned())
}
pub(crate) fn source_markdown(item: &rss::Item) -> Option<&str> {
item.extensions().get("source")?.get("markdown")?.first()?.value()
}
@@ -899,6 +910,21 @@ Some **bold** and [a link](https://x.example/).</description></item>
assert_eq!((p1.season, p1.episode), (Some(8), Some(1)));
}
#[test]
fn an_items_chapters_are_where_podcast_chapters_says() {
let xml = br#"<?xml version="1.0"?>
<rss version="2.0" xmlns:podcast="https://podcastindex.org/namespace/1.0">
<channel><title>Show</title><link>https://x</link><description>d</description>
<item><title>A</title><guid>a</guid>
<podcast:chapters url=" https://x/a.json " type="application/json+chapters"/></item>
<item><title>B</title><guid>b</guid><podcast:chapters url="file:///etc/passwd"/></item>
<item><title>C</title><guid>c</guid></item>
</channel></rss>"#;
let feed = parse(xml).unwrap();
let got: Vec<_> = feed.entries.iter().map(|e| e.chapters.as_deref()).collect();
assert_eq!(got, [Some("https://x/a.json"), None, None], "only a web address, trimmed");
}
#[test]
fn an_item_may_carry_several_enclosures() {
// The rss crate keeps only one per item -- the last -- so these come from the XML.