A seasoned podcast runs in its own order, and a season downloads whole (#482)

Asked for on the issue: lowest to highest, by season and then episode,
and a way to download every episode of a season.

sort=episode orders by season, episode, then date, with the episodes in
none last either way round; a podcast told in seasons opens in it until a
heading is clicked, and its seasons are offered lowest first.
download-latest takes a season and queues every file of it not on iPX,
first episode first, up to 300; the page asks first, since a season can
be gigabytes. The picked season scrolls into view in the picker, and the
count under the list is the season's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RqkrVAJFkEgz9cXG3jG1Zy
This commit is contained in:
2026-11-19 09:21:50 -05:00
parent 4eb6fbb286
commit c441215c62
12 changed files with 168 additions and 44 deletions

View File

@@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- A podcast told in seasons has a season picker under its tabs, to list one season at a time or the episodes in none, and listed all together, newest or oldest first, each season's start is marked (#482).
- 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).
- Podcasts: your podcasts as a shelf of their artwork, each with how many episodes are new; the search box narrows it, and a tap opens one (#474).

View File

@@ -107,16 +107,20 @@ function renderFeed(){
/// natural way round (A to Z; newest, largest and kept first) and the next one reverses it.
const COLS=[['kept','Pinned',ICON.pin],['title','Title'],['feed','Feed'],['type','File'],['size','Size'],['published','Published']];
function sortHead(){
const now=sortFor(S.feed ?? '');
return '<div class="ephead"><span></span>'+COLS.map(([k,label,icon])=>{
const on=S.sort.col===k;
const on=now.col===k;
return `<button class="hs${on?' on':''}${k==='feed'?' h-fd':''}${icon?' h-ic':''}" data-sort="${k}"`+
` title="Sort by ${label.toLowerCase()}" aria-label="Sort by ${label.toLowerCase()}">${icon||label}`+
`${on?`<span class="arr ${S.sort.dir}">${ICON.caret}</span>`:''}</button>`;
`${on?`<span class="arr ${now.dir}">${ICON.caret}</span>`:''}</button>`;
}).join('')+'<span></span></div>';
}
function sortBy(col: string){
const first=['published','size','kept'].includes(col)?'desc':'asc';
S.sort={col,dir:S.sort.col===col?(S.sort.dir==='asc'?'desc':'asc'):first};
// From a seasoned podcast's own order (#482), the first click is that column's first way round.
const now=sortFor(S.feed ?? '');
S.sort={col,dir:now.col===col?(now.dir==='asc'?'desc':'asc'):first};
sortPicked=true;
try{ localStorage.setItem('ipx.sort',JSON.stringify(S.sort)); }catch{}
S.offset=0; renderFeed(); loadEntries();
}

View File

@@ -202,7 +202,7 @@ function renderFeeds(){
done();
}
function selectFeed(id: string){
S.feed=id; S.offset=0; S.sel=null; S.q=''; S.season=''; $<HTMLInputElement>('#epSearch').value='';
S.feed=id; S.offset=0; S.sel=null; S.q=''; S.season=''; sortPicked=false; $<HTMLInputElement>('#epSearch').value='';
try{ localStorage.setItem('ipx.feed',id); }catch{}
renderFeeds(); renderFeed(); loadEntries();
}

View File

@@ -16,9 +16,9 @@ const LISTS_KEPT=40;
const fetching=new Map<string,Promise<ListPage>>();
// A season is of the podcast open (#482): another feed's list, fetched ahead, is of every season.
const seasonFor=(feed: string)=>feed===S.feed?S.season:'';
const listKey=(feed: string, filter=S.filter)=>[feed,filter,S.sort.col,S.sort.dir,S.q,seasonFor(feed)].join('\n');
const listKey=(feed: string, filter=S.filter)=>[feed,filter,sortFor(feed).col,sortFor(feed).dir,S.q,seasonFor(feed)].join('\n');
function listUrl(feed: string, filter=S.filter, offset=0){
const p=new URLSearchParams({offset:String(offset),limit:String(LIMIT),filter,sort:S.sort.col,dir:S.sort.dir});
const p=new URLSearchParams({offset:String(offset),limit:String(LIMIT),filter,sort:sortFor(feed).col,dir:sortFor(feed).dir});
if(S.q) p.set('q',S.q);
if(seasonFor(feed)) p.set('season',seasonFor(feed));
const sg=signalId(feed);
@@ -146,7 +146,7 @@ function renderEntries(){
const f=S.feeds.find(x=>x.id===S.feed), v=VIEWS[S.feed ?? ''], sg=signalOf(S.feed);
// An OPML's own row counts nothing: its shows do.
const kids=f?S.feeds.filter(c=>c.group===f.id):[];
const unread=kids.length?kids.reduce((n,x)=>n+x.unread,0):f?f.unread:sg?sg.unread:S.feeds.reduce((n,x)=>n+(x.unread||0),0);
const unread=kids.length?kids.reduce((n,x)=>n+x.unread,0):f?(seasonUnread(f.id)??f.unread):sg?sg.unread:S.feeds.reduce((n,x)=>n+(x.unread||0),0);
$('#count').textContent=
`${f?(f.title||f.id):sg?sg.name:v?v.title:''}: ${S.total} item${S.total===1?'':'s'}, ${unread} unread`;
const pane=$('#list'), top=pane?pane.scrollTop:0;

View File

@@ -24,9 +24,16 @@ function seasonsHTML(list: SeasonCount[]): string{
}
function drawSeasons(f: Feed, list: SeasonCount[]|undefined){
const bar=$('#content .toolbar'); if(!bar||S.feed!==f.id) return;
bar.querySelector('.seasons')?.remove();
bar.querySelector('.seasons')?.remove(); bar.querySelector('.seasondl')?.remove();
if(!list||!seasonsShown(list)) return;
bar.insertAdjacentHTML('beforeend',seasonsHTML(list));
if(S.season) bar.insertAdjacentHTML('beforeend',`<button class="btn ico seasondl" title="Download ${esc(seasonName(list.find(s=>seasonKey(s)===S.season)?.season))}"
aria-label="Download ${esc(seasonName(list.find(s=>seasonKey(s)===S.season)?.season))}">${ICON.download}</button>`);
bar.querySelector<HTMLButtonElement>('.seasondl')?.addEventListener('click',()=>downloadSeason(f));
// The one picked in view: on a phone Season 3 of six is past the edge, and the picker looked as
// if every season were still showing.
const track=bar.querySelector<HTMLElement>('.seasons'), on=track?.querySelector<HTMLElement>('.on');
if(track&&on) track.scrollLeft+=on.getBoundingClientRect().left-track.getBoundingClientRect().left-(track.clientWidth-on.offsetWidth)/2;
$$<HTMLButtonElement>('.seasons button',bar).forEach(b=>b.onclick=()=>{
S.season=b.dataset.season!; S.offset=0;
renderFeed(); loadEntries();
@@ -34,17 +41,51 @@ function drawSeasons(f: Feed, list: SeasonCount[]|undefined){
// The dividers in the list wait on knowing the podcast is told in seasons.
if(S.entries.length) renderEntries();
}
/// A podcast's seasons onto its page: kept ones at once, then the server's.
/// A podcast's seasons onto its page: kept ones at once, then the server's. Told in seasons only
/// once the answer came, its list is asked for again in its own order.
async function loadSeasons(f: Feed){
const had=seasonsShown(seasonsOf.get(f.id));
drawSeasons(f,seasonsOf.get(f.id));
try{
const got: SeasonCount[]=await api(`/api/feeds/${encodeURIComponent(f.id)}/seasons`);
seasonsOf.set(f.id,got);
drawSeasons(f,got);
// Drawn again, so the headings say the order too.
if(!had&&seasonsShown(got)&&!sortPicked&&S.feed===f.id){ S.offset=0; renderFeed(); loadEntries(); }
}catch{}
}
/// Whether a heading was clicked to sort the podcast open: until one is, a podcast told in
/// seasons runs in its own order, season 1 episode 1 first, not by date (#482).
let sortPicked=false;
/// The order a list is asked for in: the page's, or a seasoned podcast's own.
function sortFor(feed: string): {col: string, dir: 'asc'|'desc'}{
return feed===S.feed&&!sortPicked&&seasonsShown(seasonsOf.get(feed)) ? {col:'episode',dir:'asc'} : S.sort;
}
/// The unread of the season picked, for the count under the list; null for every season.
function seasonUnread(feed: string): number|null{
if(!S.season) return null;
return seasonsOf.get(feed)?.find(s=>seasonKey(s)===S.season)?.unread ?? null;
}
/// Where a season starts in the list, said above its first episode: only for every season at
/// once, newest or oldest first, where the episodes run season by season.
function seasonBreaks(): boolean{
return !S.season && S.sort.col==='published' && seasonsShown(seasonsOf.get(S.feed ?? ''));
const feed=S.feed ?? '', col=sortFor(feed).col;
return !S.season && (col==='episode'||col==='published') && seasonsShown(seasonsOf.get(feed));
}
/// Every episode of the season picked onto iPX, after asking: a season can be a few gigabytes.
function downloadSeason(f: Feed){
const s=seasonsOf.get(f.id)?.find(x=>seasonKey(x)===S.season); if(!s) return;
const name=seasonName(s.season);
openModal(`<h3>Download ${esc(name)}?</h3>
<p style="color:var(--dim)">Every episode of ${esc(name)} of <b>${esc(f.title||f.id)}</b> not on iPX yet, ${
plural(s.episodes,'episode')} in all, is downloaded in order, the first episode first.</p>
<div class="cardacts"><button class="btn ico" onclick="closeModal()" title="Cancel" aria-label="Cancel">${ICON.close}</button>
<button class="btn ico primary" id="sgo" title="Download ${esc(name)}" aria-label="Download ${esc(name)}">${ICON.download}</button></div>`);
$<HTMLButtonElement>('#sgo').onclick=async()=>{
try{
const r=await api(`/api/feeds/${encodeURIComponent(f.id)}/download-latest`,{method:'POST',body:JSON.stringify({season:S.season})});
closeModal();
toast(r.queued?`Downloading ${plural(r.queued,'episode')} of ${name}`:`All of ${name} is on iPX already`);
}catch(e){ toast(why(e),true); }
};
}