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

@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Now Playing lists the episode's chapters, when its podcast has them, with the one playing in bold; a tap plays from there (#477).
- A podcast told in seasons lists its episodes in its own order, season 1 episode 1 first, until a heading is clicked to sort it otherwise, with each season's start marked. A season picker under its tabs lists one season at a time, or the episodes in none, and a season picked can be downloaded whole (#482).
- Smart playlists, in a folder of their own in the feed list: choose the podcasts, which of them play first, unplayed episodes only or all, newest or oldest first, and the playlist keeps itself up to date. Playing from one goes on through it once Up Next is empty (#476).
- Now Playing: tap the player bar to see what is playing with its artwork large, its podcast (a tap opens it), its show notes and what follows in Up Next; Esc or the bar closes it (#475).

View File

@@ -711,6 +711,12 @@ body.scan-this .fhead [data-a=scan] .i,body.scan-any .fhead [data-a=scanall] .i,
.nowmeta small{color:var(--dim);font-size:12.5px;font-variant-numeric:tabular-nums}
#nowsheet h3{font-size:14px;font-weight:600;margin:22px 0 10px;color:var(--dim)}
#nowqueue{display:flex;flex-direction:column;gap:6px}
/* Chapters (#477): a tap plays from there; the one playing reads bold. */
.chapters{list-style:none;margin:0;padding:0;display:flex;flex-direction:column}
.chapters button{display:flex;gap:14px;width:100%;padding:8px 6px;border-radius:8px;text-align:left;font-size:14px}
.chapters button:hover{background:var(--raise)}
.chapters .ctime{min-width:4.5em;color:var(--dim);font-variant-numeric:tabular-nums}
.chapters button[aria-current]{font-weight:600}
#pnow{cursor:pointer;border-radius:8px}
@media (max-width:820px){
.nowhead{grid-template-columns:1fr;justify-items:center;text-align:center;gap:18px}

View File

@@ -34,6 +34,7 @@ function drawNow(){
<small>${[dateOf(e.published),e.duration?clock(e.duration):''].filter(Boolean).join(', ')}</small>
</div>
</div>
<div id="nowchaps"></div>
${upNext.length?`<h3>Up Next</h3><div class="childlist" id="nowqueue"></div>`:''}
<h3>Show notes</h3>
<div class="dbody">${textOf(e)}</div>`;
@@ -41,6 +42,52 @@ function drawNow(){
$<HTMLButtonElement>('.nowshow',nowSheet).onclick=()=>{ closeNow(); selectFeed(e.feed_id); };
const q=$('#nowqueue');
for(const x of upNext) q?.appendChild(listenRow(x,'Remove from Up Next',()=>saveUpNext(upNext.filter(y=>entryKey(y)!==entryKey(x)))));
drawChapters();
}
/// Chapters of what plays (#477), asked for once a file and clock: DeadAir's copy has its own
/// times. A failure is forgotten, so the next opening asks again.
const chapterLists=new Map<string,Promise<Chapter[]>>();
let nowChapters: Chapter[]=[];
function chaptersOf(enc: number, deadair: boolean): Promise<Chapter[]> {
const k=`${enc}${deadair?'d':''}`;
let got=chapterLists.get(k);
if(!got){
got=api(`/api/enclosures/${enc}/chapters${deadair?'?deadair=true':''}`).catch(()=>{ chapterLists.delete(k); return []; });
chapterLists.set(k,got);
}
return got;
}
function drawChapters(){
const enc=player.enc;
nowChapters=[];
if(enc==null) return;
chaptersOf(enc,!!player.src?.includes('/deadair')).then(cs=>{
const box=$('#nowchaps');
if(!box||!nowOpen()||player.enc!==enc||!cs.length) return;
nowChapters=cs;
box.innerHTML=`<h3>Chapters</h3><ol class="chapters">${cs.map((c,i)=>
`<li><button type="button" data-i="${i}"><span class="ctime">${clock(c.start)}</span><span>${esc(c.title)||`Chapter ${i+1}`}</span></button></li>`).join('')}</ol>`;
for(const b of $$<HTMLButtonElement>('button',box)) b.onclick=()=>{
audio.currentTime=cs[Number(b.dataset.i)]!.start;
// Marked now: a player still loading says nothing until it plays.
markChapter();
if(audio.paused) audio.play();
};
markChapter();
});
}
/// The chapter playing now, marked as the one current.
function markChapter(){
if(!nowChapters.length||!nowOpen()) return;
// A seek to a chapter's start can land a frame before it.
const t=audio.currentTime+.25;
let at=-1;
nowChapters.forEach((c,i)=>{ if(c.start<=t) at=i; });
$$<HTMLButtonElement>('#nowchaps button').forEach((b,i)=>{
if(i===at) b.setAttribute('aria-current','true'); else b.removeAttribute('aria-current');
});
}
audio.addEventListener('timeupdate',markChapter);
$('#pnow').onclick=()=>nowOpen()?closeNow():openNow();
$('#pnow').onkeydown=(ev: KeyboardEvent)=>{ if(ev.key==='Enter'||ev.key===' '){ ev.preventDefault(); $('#pnow').click(); } };

View File

@@ -151,6 +151,13 @@ interface State {
sort: {col: string, dir: 'asc' | 'desc'};
}
/// One chapter of a file, `/api/enclosures/{id}/chapters` (chapters.rs Chapter, #477): its start
/// in seconds, in the clock of what plays.
interface Chapter {
start: number;
title: string;
}
/// One season of a podcast, `/api/feeds/{id}/seasons` (db.rs SeasonCount, #482). No season is
/// the episodes that name none.
interface SeasonCount {