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:
@@ -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); }
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user