diff --git a/crates/ipx/CHANGELOG.md b/crates/ipx/CHANGELOG.md index 78860ae..2e9ee62 100644 --- a/crates/ipx/CHANGELOG.md +++ b/crates/ipx/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- A feed in `/api/feeds` says whether it has audio or video (`podcast`), for the page's Podcasts shelf (#474). - Up Next, a queue of episodes kept per account so every device shares it: `GET /api/queue` lists it in order, `PUT /api/queue` sets it, and an episode leaves it once it is 90% played (#473). - The API answers in protobuf as well as JSON: a client that sends `Accept: application/x-protobuf` gets protobuf, and one that sends `Content-Type: application/x-protobuf` may send its body so; JSON stays the default for a client that does not ask, and an answer of null stays JSON. The messages are in `crates/wire/proto/ipx.proto`. ipx's own calls to the directory and ipx-play go in protobuf too, so both need their protobuf releases first. Answers and those calls go through structs generated from the `.proto` files, about four times quicker to read than the JSON (#465, #470). - Sharing an episode gives a link to its page on ipx-play, which anyone can open and play, set up in Admin, Directory, Sharing episodes; private and paid feeds still share their own address (#447). diff --git a/crates/ipx/src/db.rs b/crates/ipx/src/db.rs index 93cc075..c77903c 100644 --- a/crates/ipx/src/db.rs +++ b/crates/ipx/src/db.rs @@ -611,6 +611,16 @@ impl Db { ), vec![user_id.into(), one()], ); + // Whether a feed has any audio or video, for the Podcasts shelf (#474). EXISTS, so a podcast + // stops at its first episode, and a feed with no files is one probe of enclosures_entry. + let media = counts( + "media", + "SELECT sub.feed_id, CAST(1 AS BIGINT) AS n FROM subscriptions sub + WHERE sub.user_id = $1 AND (CAST($2 AS TEXT) IS NULL OR sub.feed_id = $2) + AND EXISTS (SELECT 1 FROM enclosures x WHERE x.feed_id = sub.feed_id + AND (lower(x.mime) LIKE 'audio/%' OR lower(x.mime) LIKE 'video/%'))", + vec![user_id.into(), one()], + ); let blocked = Instrument::instrument( blocklists::Entity::find().filter(blocklists::Column::UserId.eq(user_id)).all(&self.orm), step("blocked"), @@ -620,10 +630,11 @@ impl Db { rows = rows.filter(feeds::Column::Id.eq(id)); } let rows = Instrument::instrument(rows.all(&self.orm), step("feeds")); - let (entries, downloaded, unread, blocked, rows) = tokio::try_join!( + let (entries, downloaded, unread, media, blocked, rows) = tokio::try_join!( entries, downloaded, unread, + media, async { blocked.await.map_err(anyhow::Error::from) }, async { rows.await.map_err(anyhow::Error::from) }, )?; @@ -649,6 +660,7 @@ impl Db { ttl_mins: f.ttl_mins.map(|t| t.max(0) as u64), blocked: blocked.remove(&id).unwrap_or_default(), unread: unread.get(&id).copied().unwrap_or(0), + podcast: media.contains_key(&id), }; (id, listing) }) @@ -663,6 +675,8 @@ pub struct FeedListing { pub ttl_mins: Option, pub blocked: Vec, pub unread: i64, + /// It has an audio or video file, so it is on the Podcasts shelf (#474). + pub podcast: bool, } /// Everything `fetch` needs to decide whether to poll a feed, and how. @@ -3639,12 +3653,15 @@ mod tests { INSERT INTO entries (feed_id, guid, first_seen) VALUES ('f','a',0),('f','b',0),('f','c',0),('g','d',0),('h','e',0); INSERT INTO entry_state (user_id, feed_id, guid, read) VALUES (1,'f','a',true),(2,'f','b',true); INSERT INTO hidden (user_id, feed_id, guid) VALUES (1,'f','c'); - INSERT INTO enclosures (id, feed_id, guid, url, path, state) VALUES - (1,'f','a','u1','/tmp/a','done'),(2,'f','b','u2',null,'pending'); + INSERT INTO enclosures (id, feed_id, guid, url, path, state, mime) VALUES + (1,'f','a','u1','/tmp/a','done','Audio/MPEG'),(2,'f','b','u2',null,'pending',null), + (3,'g','d','u3',null,'skipped','image/jpeg'); INSERT INTO blocklists (user_id, feed_id, words) VALUES (1,'g','[\"spoiler\"]');", ).await .unwrap(); let list = db.feed_list(1, None).await.unwrap(); + // On the Podcasts shelf by having sound, whatever the case of its type; a picture is not (#474). + assert!(list["f"].podcast && !list["g"].podcast); let g = db.feed_list(1, Some("g")).await.unwrap(); assert_eq!(g.keys().collect::>(), ["g"]); assert_eq!( diff --git a/crates/ipx/src/web.rs b/crates/ipx/src/web.rs index ded3a02..18f48a4 100644 --- a/crates/ipx/src/web.rs +++ b/crates/ipx/src/web.rs @@ -1004,6 +1004,8 @@ struct FeedRow { private: bool, /// Private whatever it is marked, for a login or an address with a key in it. private_by_address: bool, + /// Has an audio or video file: on the Podcasts shelf (#474). + podcast: bool, } #[derive(Serialize)] @@ -1052,7 +1054,8 @@ async fn feed_rows(state: &WebState, user: &crate::db::User, only: Option<&str>) let up = feed.group.as_deref().and_then(|g| mine.get(g)); let Some(mine) = mine.get(id) else { continue }; // A feed not scanned yet has no row: blank, as feed_summary gave it. - let crate::db::FeedListing { summary: s, ttl_mins, blocked, unread } = listed.remove(id).unwrap_or_default(); + let crate::db::FeedListing { summary: s, ttl_mins, blocked, unread, podcast } = + listed.remove(id).unwrap_or_default(); out.push(FeedRow { private: feed.private, private_by_address: crate::directory::looks_private(&crate::config::Feed { @@ -1115,6 +1118,7 @@ async fn feed_rows(state: &WebState, user: &crate::db::User, only: Option<&str>) kept: kept.contains(id), hide_from_all: hidden.contains(id), hide_from_signals: quiet.contains(id), + podcast, }); } Ok(out) diff --git a/crates/wire/proto/ipx.proto b/crates/wire/proto/ipx.proto index 3b91651..610c7bc 100644 --- a/crates/wire/proto/ipx.proto +++ b/crates/wire/proto/ipx.proto @@ -134,6 +134,8 @@ message FeedRow { bool hide_from_signals = 32; bool private = 33; bool private_by_address = 34; + // Has an audio or video file: on the Podcasts shelf (#474). + bool podcast = 35; } // GET /api/feeds. diff --git a/tests/ui/app.spec.ts b/tests/ui/app.spec.ts index 96552a5..197f699 100644 --- a/tests/ui/app.spec.ts +++ b/tests/ui/app.spec.ts @@ -462,6 +462,19 @@ test('Up Next lines episodes up, moves them, and plays the next when one ends (# await page.evaluate(() => api('/api/entries/test-show/ui-2/position', { method: 'POST', body: JSON.stringify({ secs: 0 }) })); }); +test('the Podcasts shelf shows the feeds with episodes, as their artwork, and opens one (#474)', async ({ page }) => { + await page.locator('#feedlist .place', { hasText: 'Podcasts' }).click(); + const shows = page.locator('#content .shelf .show'); + await expect(shows.filter({ hasText: 'Test Show' })).toBeVisible(); + // A blog of pictures has files, and no episodes. + await expect(shows.filter({ hasText: 'Picture Blog' })).toHaveCount(0); + await page.locator('#epSearch').fill('multi'); + await expect(shows).toHaveText([/Multi Show/]); + await page.locator('#epSearch').fill(''); + await shows.filter({ hasText: 'Test Show' }).click(); + await expect(page.locator('#eps .ep', { hasText: 'First Episode' })).toBeVisible(); +}); + test('a player nobody has played since it last saved does not save again', async ({ page }) => { // A tab left paused at 41:15 saved that as it reloaded, over the 32:48 another had reached, // and the episode dropped out of Currently Listening. The fixture audio does not decode, so diff --git a/web/CHANGELOG.md b/web/CHANGELOG.md index 52dcd2c..ce1d801 100644 --- a/web/CHANGELOG.md +++ b/web/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- 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). - Up Next: line episodes up with the list button on a row or in the reader (`q`, or `Shift Q` to play one next), move them by their handles, and each plays when the one before it ends. The player has a Next button while something is lined up, and the lock screen's next-track button does the same (#473). - The page reads ipx's answers in protobuf, with a decoder of its own and no library, and in JSON from a server that has none; offline, a kept answer still shows what was read offline (#470). - On a phone, back and the item's actions (read, pin, open, share) float over the text as it scrolls, so they are at hand anywhere in a long post without scrolling back to the top; pressing one there keeps your place (#456). diff --git a/web/app.css b/web/app.css index cc1a423..1e24887 100644 --- a/web/app.css +++ b/web/app.css @@ -696,6 +696,14 @@ body.scan-this .fhead [data-a=scan] .i,body.scan-any .fhead [data-a=scanall] .i, #listening .txt small .fd{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} #listening .txt small .left{flex:none;color:var(--dim)} #listening .childrow:not(.now) .eq{display:none} +/* The Podcasts shelf (#474): the artwork is the podcast, as on a shelf of records, so nothing + frames it: no card, no shadow, the name and its new episodes under it. */ +.shelf{display:grid;grid-template-columns:repeat(auto-fill,minmax(112px,1fr));gap:20px 14px;padding:4px 2px 24px} +.shelf .show{display:flex;flex-direction:column;gap:6px;min-width:0;text-align:left;cursor:pointer;border-radius:10px} +.shelf .show .art{width:100%;height:auto;aspect-ratio:1;border-radius:10px;font-size:26px} +.shelf .show b{font-weight:500;font-size:13px;line-height:1.3;color:var(--fg);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden} +.shelf .show small{color:var(--dim);font-size:11.5px;min-height:1em;margin-top:-3px} +@media (hover:hover){.shelf .show:hover .art{outline:2px solid var(--accent);outline-offset:2px}} /* Up Next's handle: dragged, it takes the pointer, so the list does not scroll under the finger. */ #listening .grip{width:22px;margin-left:-4px;color:var(--faint);cursor:grab;touch-action:none} #listening .grip svg{width:12px;height:12px} diff --git a/web/src/dialogs.ts b/web/src/dialogs.ts index f4a99c4..c091e68 100644 --- a/web/src/dialogs.ts +++ b/web/src/dialogs.ts @@ -310,6 +310,7 @@ async function renderListed(v: {title: string, icon: string, url?: string, blurb await renderDirectory(v.url!,$('#directory'),n=>{ if(VIEWS[S.feed ?? '']===v) $('#count').textContent=`${v.title}: ${plural(n,'feed')}`; }); return; } + if(v===VIEWS[':podcasts']){ drawShelf(box); return; } $('#epSearch').setAttribute('aria-label','Search items'); box.innerHTML=`
@@ -324,6 +325,25 @@ async function renderListed(v: {title: string, icon: string, url?: string, blurb n=>{ if(VIEWS[S.feed ?? '']===v) $('#count').textContent=`${v.title}: ${plural(n,'episode')}`; }); } +/// The Podcasts shelf (#474): every feed with audio or video, as its artwork, with how many of its +/// episodes are new. A tap opens it. The search box narrows it by name. +function drawShelf(box: HTMLElement){ + $('#epSearch').setAttribute('aria-label','Search podcasts'); + const q=S.q.trim().toLowerCase(); + const shows=S.feeds.filter(f=>f.podcast&&(!q||(f.title||f.id).toLowerCase().includes(q))); + $('#count').textContent=`Podcasts: ${plural(shows.length,'podcast')}`; + box.innerHTML=shows.length?'
' + :`

${q?`No podcast is called “${esc(S.q)}”.`:'No podcasts yet. Add a feed with episodes in it, and it shows here.'}

`; + const shelf=$('.shelf',box); + for(const f of shows){ + const name=f.title||f.id, b=document.createElement('button'); + b.type='button'; b.className='show'; + b.innerHTML=`${artHTML(f.image,name)}${esc(name)}${f.unread?`${f.unread} new`:''}`; + b.onclick=()=>selectFeed(f.id); + shelf.appendChild(b); + } +} + /// Currently Listening: episodes you started and have not finished, across every feed you /// subscribe to. A row resumes the episode in the player bar on click -- a shortcut back to /// where you left off, not another way to browse. The one in the player pauses instead. @@ -410,7 +430,7 @@ $('#epSearch').oninput=(ev: Event)=>{ clearTimeout(searchT); // server (#126, #127). searchT=setTimeout(()=>{ S.q=(ev.target as HTMLInputElement).value; S.offset=0; if(S.feed===':directory'){ dirShow=null; drawDirectory(); } - else if(S.feed===':listening') renderListed(VIEWS[':listening']); + else if(S.feed===':listening'||S.feed===':podcasts') renderListed(VIEWS[S.feed]); else loadEntries(); },250); }; // Crossing the phone breakpoint moves the files between their pane and the text. window.matchMedia?.('(max-width:820px)')?.addEventListener?.('change',()=>{ const e=cur(); if(e) showDetail(e); }); diff --git a/web/src/feeds.ts b/web/src/feeds.ts index 7660082..bc3c3d3 100644 --- a/web/src/feeds.ts +++ b/web/src/feeds.ts @@ -36,6 +36,8 @@ const VIEWS: Record={ // shape. Drawn here, so the two are the same list and differ only in that mark. queue:fa('0 0 512 512',''), queued:fa('0 0 512 512',''), + // Font Awesome's podcast, for the Podcasts shelf (#474). + podcasts:fa('0 0 448 512',''), next:fa('0 0 320 512',''), grip:fa('0 0 320 512',''), subbed:fa('0 0 512 512',''), // solid/circle-check