A podcast told in seasons can be listed one season at a time (#482)
GET /api/feeds/{id}/seasons counts a podcast's episodes and unread by
season, from the same FROM as its list, so a count is what picking it
shows; season= on its entries narrows the list to one, or to the
episodes naming none. The page puts the seasons under the tabs, as the
tabs' own track, when a podcast is told in them: two or more, holding
most of its episodes. That leaves out Ken and Robin, whose "seasons" are
years on a quarter of 767 episodes, and The Vintage RPG Podcast's 2 of
366. Listed all together by date, a heading marks where each season
starts.
A fixture podcast in seasons is in the browser suite, which now
configures six feeds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RqkrVAJFkEgz9cXG3jG1Zy
This commit is contained in:
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Added
|
||||
|
||||
- `GET /api/feeds/{id}/seasons` gives a podcast's seasons with how many episodes and unread each has, and a podcast's episodes can be asked for one season at a time, or for those naming none (`season=none`) (#482).
|
||||
- Smart playlists: `GET` and `POST /api/playlists`, `PATCH` and `DELETE /api/playlists/{id}`, and `GET /api/playlists/{id}/entries`, the episodes of the podcasts chosen in the playlist's order, those set to play first ahead of the rest (#476).
|
||||
- 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).
|
||||
|
||||
@@ -1342,6 +1342,7 @@ fn entries_from(
|
||||
search: Option<&str>,
|
||||
guid: Option<&str>,
|
||||
signal: Option<i64>,
|
||||
season: Season,
|
||||
pg: bool,
|
||||
) -> String {
|
||||
let user = a.p(user_id);
|
||||
@@ -1381,6 +1382,11 @@ fn entries_from(
|
||||
if let Some(g) = guid {
|
||||
scope = format!("{scope} AND e.guid = {}", a.p(g));
|
||||
}
|
||||
match season {
|
||||
Season::Any => {}
|
||||
Season::Of(n) => scope = format!("{scope} AND e.season = {}", a.p(n)),
|
||||
Season::Unnumbered => scope = format!("{scope} AND e.season IS NULL"),
|
||||
}
|
||||
let search = match search.map(|q| q.trim().to_lowercase()).filter(|q| !q.is_empty()) {
|
||||
Some(q) => {
|
||||
// % and _ as typed, not as wildcards: "100%" matched anything starting 100 (#296).
|
||||
@@ -1495,6 +1501,23 @@ pub fn playlist_order(spec: &PlaylistSpec) -> String {
|
||||
format!("CASE WHEN e.feed_id IN ({ids}) THEN 0 ELSE 1 END, {by_date}")
|
||||
}
|
||||
|
||||
/// Which of a podcast's seasons a list is of (#482): every one, one by its number, or the episodes
|
||||
/// that name none.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Season {
|
||||
Any,
|
||||
Of(i64),
|
||||
Unnumbered,
|
||||
}
|
||||
|
||||
/// A season of a podcast, as its page offers it: None for the episodes that name none.
|
||||
#[derive(Debug, PartialEq, Eq, serde::Serialize)]
|
||||
pub struct SeasonCount {
|
||||
pub season: Option<i64>,
|
||||
pub episodes: i64,
|
||||
pub unread: i64,
|
||||
}
|
||||
|
||||
/// Which slice of a feed the UI is asking for.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Filter {
|
||||
@@ -1586,7 +1609,7 @@ impl Db {
|
||||
order: &str,
|
||||
) -> Result<Vec<EntryRow>> {
|
||||
let feeds = feed_id.as_ref().map(std::slice::from_ref);
|
||||
self.entries_where(user_id, feeds, filter, search, None, None, offset, limit, order).await
|
||||
self.entries_where(user_id, feeds, filter, search, None, None, Season::Any, offset, limit, order).await
|
||||
}
|
||||
|
||||
/// As `entries_in`, for several feeds together (an OPML's shows, #283), or every subscribed
|
||||
@@ -1602,7 +1625,63 @@ impl Db {
|
||||
limit: i64,
|
||||
order: &str,
|
||||
) -> Result<Vec<EntryRow>> {
|
||||
self.entries_where(user_id, feeds, filter, search, None, None, offset, limit, order).await
|
||||
self.entries_where(user_id, feeds, filter, search, None, None, Season::Any, offset, limit, order).await
|
||||
}
|
||||
|
||||
/// As `entries_of`, for one season of the feeds (#482).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn season_entries(
|
||||
&self,
|
||||
user_id: i64,
|
||||
feeds: &[&str],
|
||||
season: Season,
|
||||
filter: Filter,
|
||||
search: Option<&str>,
|
||||
offset: i64,
|
||||
limit: i64,
|
||||
order: &str,
|
||||
) -> Result<Vec<EntryRow>> {
|
||||
self.entries_where(user_id, Some(feeds), filter, search, None, None, season, offset, limit, order).await
|
||||
}
|
||||
|
||||
/// As `count_of`, for one season of the feeds (#482).
|
||||
pub async fn season_count(
|
||||
&self,
|
||||
user_id: i64,
|
||||
feeds: &[&str],
|
||||
season: Season,
|
||||
filter: Filter,
|
||||
search: Option<&str>,
|
||||
) -> Result<i64> {
|
||||
self.count_where(user_id, Some(feeds), season, filter, search).await
|
||||
}
|
||||
|
||||
/// The seasons of the feeds, newest first and the episodes naming none last, each with how
|
||||
/// many of its episodes the list holds and how many are unread: what the season picker offers
|
||||
/// (#482). The same FROM as the lists, so a count is what picking it shows.
|
||||
pub async fn seasons(&self, user_id: i64, feeds: &[&str]) -> Result<Vec<SeasonCount>> {
|
||||
let count = |filter| {
|
||||
let mut a = Args::default();
|
||||
let from = entries_from(&mut a, user_id, Some(feeds), filter, None, None, None, Season::Any, self.pg());
|
||||
(format!("SELECT e.season, count(*) AS n {from} GROUP BY e.season"), a.0)
|
||||
};
|
||||
let read = |rows: Vec<sea_orm::QueryResult>| -> Result<std::collections::HashMap<Option<i64>, i64>> {
|
||||
rows.iter().map(|r| Ok((r.try_get("", "season")?, r.try_get("", "n")?))).collect()
|
||||
};
|
||||
let (all, unread) = (count(Filter::All), count(Filter::Unread));
|
||||
let all = read(self.rows(&all.0, all.1).await?)?;
|
||||
let unread = read(self.rows(&unread.0, unread.1).await?)?;
|
||||
let mut out: Vec<SeasonCount> = all
|
||||
.into_iter()
|
||||
.map(|(season, episodes)| SeasonCount {
|
||||
season,
|
||||
episodes,
|
||||
unread: unread.get(&season).copied().unwrap_or(0),
|
||||
})
|
||||
.collect();
|
||||
// Newest season first; None, the episodes naming none, sorts below every number.
|
||||
out.sort_by_key(|s| std::cmp::Reverse(s.season));
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The shows of an OPML (or a Patreon creator) this person subscribes to (#283).
|
||||
@@ -1631,14 +1710,14 @@ impl Db {
|
||||
limit: i64,
|
||||
order: &str,
|
||||
) -> Result<Vec<EntryRow>> {
|
||||
self.entries_where(user_id, None, filter, search, None, Some(signal), offset, limit, order).await
|
||||
self.entries_where(user_id, None, filter, search, None, Some(signal), Season::Any, offset, limit, order).await
|
||||
}
|
||||
|
||||
pub async fn signal_count(&self, user_id: i64, signal: i64, filter: Filter, search: Option<&str>) -> Result<i64> {
|
||||
let mut a = Args::default();
|
||||
let sql = format!(
|
||||
"SELECT count(*) AS n {}",
|
||||
entries_from(&mut a, user_id, None, filter, search, None, Some(signal), self.pg())
|
||||
entries_from(&mut a, user_id, None, filter, search, None, Some(signal), Season::Any, self.pg())
|
||||
);
|
||||
let r = self.rows(&sql, a.0).await?;
|
||||
Ok(r.first().context("count(*) always returns a row")?.try_get("", "n")?)
|
||||
@@ -1649,7 +1728,7 @@ impl Db {
|
||||
pub async fn entry(&self, user_id: i64, feed_id: &str, guid: &str) -> Result<Option<EntryRow>> {
|
||||
let order = order_sql("published", "desc");
|
||||
Ok(self
|
||||
.entries_where(user_id, Some(&[feed_id]), Filter::All, None, Some(guid), None, 0, 1, &order)
|
||||
.entries_where(user_id, Some(&[feed_id]), Filter::All, None, Some(guid), None, Season::Any, 0, 1, &order)
|
||||
.await?
|
||||
.pop())
|
||||
}
|
||||
@@ -1663,12 +1742,13 @@ impl Db {
|
||||
search: Option<&str>,
|
||||
guid: Option<&str>,
|
||||
signal: Option<i64>,
|
||||
season: Season,
|
||||
offset: i64,
|
||||
limit: i64,
|
||||
order: &str,
|
||||
) -> Result<Vec<EntryRow>> {
|
||||
let mut a = Args::default();
|
||||
let from = entries_from(&mut a, user_id, feeds, filter, search, guid, signal, self.pg());
|
||||
let from = entries_from(&mut a, user_id, feeds, filter, search, guid, signal, season, self.pg());
|
||||
// The page's keys first, then its rows: the sort then needs only `entries_by_time`, not
|
||||
// every item's row, and the show notes are read for the page alone (#188).
|
||||
let (limit, offset) = (a.p(limit), a.p(offset));
|
||||
@@ -1752,9 +1832,21 @@ impl Db {
|
||||
feeds: Option<&[&str]>,
|
||||
filter: Filter,
|
||||
search: Option<&str>,
|
||||
) -> Result<i64> {
|
||||
self.count_where(user_id, feeds, Season::Any, filter, search).await
|
||||
}
|
||||
|
||||
async fn count_where(
|
||||
&self,
|
||||
user_id: i64,
|
||||
feeds: Option<&[&str]>,
|
||||
season: Season,
|
||||
filter: Filter,
|
||||
search: Option<&str>,
|
||||
) -> Result<i64> {
|
||||
let mut a = Args::default();
|
||||
let sql = if filter == Filter::Unread && search.is_none() {
|
||||
// The feed list's own count, feed by feed, knows nothing of seasons.
|
||||
let sql = if filter == Filter::Unread && search.is_none() && season == Season::Any {
|
||||
// Feed by feed, as the feed list counts (#352); the same feeds as `entries_from`.
|
||||
let user = a.p(user_id);
|
||||
let scope = match feeds {
|
||||
@@ -1771,7 +1863,7 @@ impl Db {
|
||||
} else {
|
||||
format!(
|
||||
"SELECT count(*) AS n {}",
|
||||
entries_from(&mut a, user_id, feeds, filter, search, None, None, self.pg())
|
||||
entries_from(&mut a, user_id, feeds, filter, search, None, None, season, self.pg())
|
||||
)
|
||||
};
|
||||
let r = self.rows(&sql, a.0).await?;
|
||||
@@ -4093,6 +4185,37 @@ mod tests {
|
||||
assert!(guids(1).await.is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_podcast_s_seasons_are_counted_and_listed_one_at_a_time() {
|
||||
let db = Db::memory().await.unwrap();
|
||||
db.exec_for_test(
|
||||
"INSERT INTO users (id, name, is_admin) VALUES (1,'ray',true);
|
||||
INSERT INTO entries (feed_id, guid, title, published, first_seen, season) VALUES
|
||||
('f','a','S1E1',100,100,1),('f','b','S1E2',200,200,1),('f','c','S2E1',300,300,2),
|
||||
('f','d','Trailer',50,50,NULL),('g','e','Elsewhere',400,400,2);",
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
db.subscribe(1, "f").await.unwrap();
|
||||
db.set_entry_flag(1, "f", "a", EntryFlag::Read, true).await.unwrap();
|
||||
|
||||
// Newest first, the unnumbered last, each with its unread; another feed's season 2 is not in it.
|
||||
let got = db.seasons(1, &["f"]).await.unwrap();
|
||||
let want = [(Some(2), 1, 1), (Some(1), 2, 1), (None, 1, 1)];
|
||||
assert_eq!(got.iter().map(|s| (s.season, s.episodes, s.unread)).collect::<Vec<_>>(), want);
|
||||
|
||||
let order = order_sql("published", "desc");
|
||||
let titles = async |season| {
|
||||
let rows = db.season_entries(1, &["f"], season, Filter::All, None, 0, 50, &order).await.unwrap();
|
||||
assert_eq!(db.season_count(1, &["f"], season, Filter::All, None).await.unwrap(), rows.len() as i64);
|
||||
rows.into_iter().map(|r| r.title.unwrap()).collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(titles(Season::Of(1)).await, ["S1E2", "S1E1"]);
|
||||
assert_eq!(titles(Season::Unnumbered).await, ["Trailer"]);
|
||||
assert_eq!(titles(Season::Any).await.len(), 4);
|
||||
assert_eq!(db.season_count(1, &["f"], Season::Of(1), Filter::Unread, None).await.unwrap(), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_playlist_puts_its_priority_podcasts_first_and_is_its_owners_alone() {
|
||||
let db = Db::memory().await.unwrap();
|
||||
|
||||
@@ -60,6 +60,7 @@ const WIRE: ipx_wire::Routes = &[
|
||||
("POST", "/api/feeds", "ipx.NewFeed", "ipx.AddedFeed"),
|
||||
("PATCH", "/api/feeds/{id}", "ipx.FeedPatch", ""),
|
||||
("GET", "/api/feeds/{id}/entries", "", "ipx.EntryPage"),
|
||||
("GET", "/api/feeds/{id}/seasons", "", "ipx.SeasonRows"),
|
||||
("GET", "/api/entries", "", "ipx.EntryPage"),
|
||||
("GET", "/api/queue", "", "ipx.EntryPage"),
|
||||
("PUT", "/api/queue", "ipx.QueueItems", "ipx.EntryPage"),
|
||||
@@ -108,6 +109,7 @@ pub fn router(state: WebState) -> Router {
|
||||
.route("/api/feeds", get(feeds).post(add_feed))
|
||||
.route("/api/feeds/{id}", patch(patch_feed).delete(remove_feed))
|
||||
.route("/api/feeds/{id}/entries", get(entries))
|
||||
.route("/api/feeds/{id}/seasons", get(seasons))
|
||||
.route("/api/entries", get(all_entries))
|
||||
.route("/api/queue", get(queue).put(set_queue))
|
||||
.route("/api/playlists", get(list_playlists).post(add_playlist))
|
||||
@@ -2042,6 +2044,9 @@ struct Page {
|
||||
sort: Option<String>,
|
||||
#[serde(default)]
|
||||
dir: Option<String>,
|
||||
/// One season of a podcast's (#482): its number, or `none` for the episodes naming none.
|
||||
#[serde(default)]
|
||||
season: Option<String>,
|
||||
}
|
||||
|
||||
fn fifty() -> i64 {
|
||||
@@ -2069,6 +2074,20 @@ async fn entries(
|
||||
entry_page(&state, user.id, Some(&ids[..]), None, &page).await
|
||||
}
|
||||
|
||||
/// A podcast's seasons, for its page to offer one at a time (#482). An OPML's are its shows'
|
||||
/// together, as its items are.
|
||||
async fn seasons(
|
||||
State(state): State<WebState>,
|
||||
Path(id): Path<String>,
|
||||
user: crate::db::User,
|
||||
) -> Result<Json<Vec<crate::db::SeasonCount>>, ApiError> {
|
||||
subscribed(&state, &user, &id).await?;
|
||||
let mut ids = state.ctx.db.group_members(user.id, &id).await?;
|
||||
ids.push(id);
|
||||
let ids: Vec<&str> = ids.iter().map(String::as_str).collect();
|
||||
Ok(Json(state.ctx.db.seasons(user.id, &ids).await?))
|
||||
}
|
||||
|
||||
/// A feed's items and files are for the people who subscribe to it (#129). Anyone signed in
|
||||
/// could read any feed's by its id, a paid one's included, with its enclosure addresses, which
|
||||
/// can carry the subscriber's key, and fetch, queue or delete its files by theirs. A feed in
|
||||
@@ -2104,6 +2123,11 @@ async fn entry_page(
|
||||
let order =
|
||||
crate::db::order_sql(page.sort.as_deref().unwrap_or("published"), page.dir.as_deref().unwrap_or("desc"));
|
||||
let limit = page.limit.clamp(1, 200);
|
||||
let season = match page.season.as_deref().map(str::trim) {
|
||||
None | Some("") => db::Season::Any,
|
||||
Some("none") => db::Season::Unnumbered,
|
||||
Some(n) => db::Season::Of(n.parse().map_err(|_| ApiError::bad_request(format!("no season {n:?}")))?),
|
||||
};
|
||||
// Which list, so a slow one's trace says what was asked of it (#287). The search's words stay
|
||||
// out: they are the reader's own.
|
||||
let in_list = tracing::info_span!(
|
||||
@@ -2115,19 +2139,32 @@ async fn entry_page(
|
||||
offset = page.offset,
|
||||
limit,
|
||||
search = search.is_some(),
|
||||
season = ?season,
|
||||
);
|
||||
// A season is of a podcast's own page; All Subscriptions and a Signal have none to pick.
|
||||
let in_season = feeds.filter(|_| season != db::Season::Any);
|
||||
let list = async {
|
||||
match signal {
|
||||
Some(id) => {
|
||||
match (signal, in_season) {
|
||||
(Some(id), _) => {
|
||||
db.signal_entries(user_id, id, filter, search, page.offset, limit, &order).instrument(in_list).await
|
||||
}
|
||||
None => db.entries_of(user_id, feeds, filter, search, page.offset, limit, &order).instrument(in_list).await,
|
||||
(None, Some(fs)) => {
|
||||
db.season_entries(user_id, fs, season, filter, search, page.offset, limit, &order)
|
||||
.instrument(in_list)
|
||||
.await
|
||||
}
|
||||
(None, None) => {
|
||||
db.entries_of(user_id, feeds, filter, search, page.offset, limit, &order).instrument(in_list).await
|
||||
}
|
||||
}
|
||||
};
|
||||
let count = async {
|
||||
match signal {
|
||||
Some(id) => db.signal_count(user_id, id, filter, search).instrument(db::step("count_in")).await,
|
||||
None => db.count_of(user_id, feeds, filter, search).instrument(db::step("count_in")).await,
|
||||
match (signal, in_season) {
|
||||
(Some(id), _) => db.signal_count(user_id, id, filter, search).instrument(db::step("count_in")).await,
|
||||
(None, Some(fs)) => {
|
||||
db.season_count(user_id, fs, season, filter, search).instrument(db::step("count_in")).await
|
||||
}
|
||||
(None, None) => db.count_of(user_id, feeds, filter, search).instrument(db::step("count_in")).await,
|
||||
}
|
||||
};
|
||||
// The count beside the list, not after it: each waited on the other, about 40 and 24 ms on the
|
||||
|
||||
@@ -275,6 +275,18 @@ message PlaylistRows {
|
||||
repeated PlaylistRow items = 1;
|
||||
}
|
||||
|
||||
// One season of a podcast in GET /api/feeds/{id}/seasons (#482): its number, unset for the
|
||||
// episodes that name none, how many episodes it has and how many are unread.
|
||||
message SeasonRow {
|
||||
optional int64 season = 1;
|
||||
int64 episodes = 2;
|
||||
int64 unread = 3;
|
||||
}
|
||||
|
||||
message SeasonRows {
|
||||
repeated SeasonRow items = 1;
|
||||
}
|
||||
|
||||
// POST /api/playlists, the answer.
|
||||
message PlaylistId {
|
||||
int64 id = 1;
|
||||
|
||||
@@ -37,6 +37,19 @@ test('names sort as a shelf files them, a leading The, A or An aside (#481)', ()
|
||||
'The Rest Is Science', 'science weekly', 'Theory of Everything']);
|
||||
});
|
||||
|
||||
test('a podcast gets its seasons only when most of it is in two or more (#482)', () => {
|
||||
const shown = (list: object) => run(`seasonsShown(${JSON.stringify(list)})`);
|
||||
const s = (season: number | null, episodes: number) => ({ season, episodes, unread: 0 });
|
||||
assert.equal(shown([s(6, 25), s(5, 40), s(1, 30)]), true, 'Oxide and Friends');
|
||||
assert.equal(shown([s(7, 40), s(1, 30), s(null, 3)]), true, 'a few trailers aside');
|
||||
assert.equal(shown([s(232, 1), s(225, 1), s(null, 364)]), false, 'two numbered of 366');
|
||||
assert.equal(shown([s(2023, 150), s(12026, 44), s(null, 573)]), false, 'years on a quarter of them');
|
||||
assert.equal(shown([s(1, 40)]), false, 'one season is no choice');
|
||||
assert.equal(shown([{ episodes: 3, unread: 0 }, s(2, 2), s(1, 2)]), true, 'none sent as absent, as protobuf does');
|
||||
assert.equal(run('seasonName(null)'), 'Other episodes');
|
||||
assert.equal(run('seasonName(3)'), 'Season 3');
|
||||
});
|
||||
|
||||
test('webUrl keeps only web addresses from a feed', () => {
|
||||
assert.equal(run(`webUrl('https://example.com/a')`), 'https://example.com/a');
|
||||
assert.equal(run(`webUrl('HTTP://example.com/')`), 'HTTP://example.com/');
|
||||
|
||||
@@ -56,9 +56,9 @@ test.beforeEach(async ({ page }) => {
|
||||
test('the page loads and lists the configured feeds', async ({ page }) => {
|
||||
// Regression: a ReferenceError in the script left the shell rendered and the sidebar
|
||||
// empty, with every handler below the error dead. Server-side checks all passed.
|
||||
// Four top-level feeds in the fixture config; the OPML's children are inside a closed folder.
|
||||
// The Signals folder is above them, and no feed.
|
||||
await expect(page.locator('.feed:not(.sigs):not(.plists)')).toHaveCount(5, { timeout: 15_000 });
|
||||
// Six top-level feeds in the fixture config, the season one's (#482) among them; the OPML's
|
||||
// children are inside a closed folder. The Signals folder is above them, and no feed.
|
||||
await expect(page.locator('.feed:not(.sigs):not(.plists)')).toHaveCount(6, { timeout: 15_000 });
|
||||
await expect(page.locator('.feed', { hasText: 'Test Show' })).toBeVisible();
|
||||
const errors: string[] = [];
|
||||
page.on('pageerror', e => errors.push(e.message));
|
||||
@@ -3217,3 +3217,23 @@ test('a reap over the quota says what it would delete and, dry, deletes nothing'
|
||||
expect(ipx(['reap'])).toContain('deleted 0 old file(s), 0.0 MB');
|
||||
expect(files()).toBe(before);
|
||||
});
|
||||
|
||||
test('a podcast told in seasons is listed one season at a time, or all with each season marked (#482)', async ({ page }) => {
|
||||
await page.locator('#feedlist .feed', { hasText: 'Seasoned Show' }).click({ timeout: 20_000 });
|
||||
await page.locator('#content .tabs button[data-f="all"]').click();
|
||||
const picker = page.locator('#content .seasons');
|
||||
await expect(picker.locator('button')).toHaveText(['All seasons', 'Season 2', 'Season 1', 'Other']);
|
||||
// Every season, newest first: where each starts is said above its first episode.
|
||||
await expect(page.locator('#eps .sdiv')).toHaveText(['Season 2', 'Other episodes', 'Season 1']);
|
||||
await picker.locator('button', { hasText: 'Season 1' }).click();
|
||||
await expect(page.locator('#eps .ep .t')).toHaveText(['The Pilot', 'Season One Close']);
|
||||
await expect(page.locator('#eps .sdiv')).toHaveCount(0);
|
||||
await expect(page.locator('#content .seasons button', { hasText: 'Season 1' })).toHaveAttribute('aria-pressed', 'true');
|
||||
await page.locator('#content .seasons button', { hasText: 'Other' }).click();
|
||||
await expect(page.locator('#eps .ep .t')).toHaveText(['A Bonus Between']);
|
||||
// A podcast with one season has no picker, and opening it starts from every season again.
|
||||
await page.locator('#feedlist .feed', { hasText: 'Test Show' }).first().click();
|
||||
await expect(page.locator('#content .seasons')).toHaveCount(0);
|
||||
await page.locator('#feedlist .feed', { hasText: 'Seasoned Show' }).click();
|
||||
await expect(page.locator('#content .seasons button.on')).toHaveText('All seasons');
|
||||
});
|
||||
|
||||
13
tests/ui/fixtures/seasons.xml
Normal file
13
tests/ui/fixtures/seasons.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
|
||||
<channel><title>Seasoned Show</title><link>http://127.0.0.1:8792/</link><description>A fixture podcast told in seasons (#482).</description>
|
||||
<item><title>Season Two Finale</title><guid>sn-4</guid><pubDate>Mon, 01 Jun 2026 10:00:00 +0000</pubDate>
|
||||
<itunes:season>2</itunes:season><itunes:episode>2</itunes:episode></item>
|
||||
<item><title>Season Two Opener</title><guid>sn-3</guid><pubDate>Mon, 25 May 2026 10:00:00 +0000</pubDate>
|
||||
<itunes:season>2</itunes:season><itunes:episode>1</itunes:episode></item>
|
||||
<item><title>A Bonus Between</title><guid>sn-b</guid><pubDate>Mon, 18 May 2026 10:00:00 +0000</pubDate></item>
|
||||
<item><title>The Pilot</title><guid>sn-1</guid><pubDate>Mon, 11 May 2026 10:00:00 +0000</pubDate>
|
||||
<itunes:season>1</itunes:season><itunes:episode>1</itunes:episode></item>
|
||||
<item><title>Season One Close</title><guid>sn-2</guid><pubDate>Mon, 04 May 2026 10:00:00 +0000</pubDate>
|
||||
<itunes:season>1</itunes:season><itunes:episode>2</itunes:episode></item>
|
||||
</channel></rss>
|
||||
@@ -63,6 +63,11 @@ metrics_bind = "127.0.0.1:8799"
|
||||
url = "http://127.0.0.1:8792/show.xml"
|
||||
auto_download = true
|
||||
|
||||
# Told in seasons, with a bonus naming none between them: the season picker (#482).
|
||||
[feeds.seasoned-show]
|
||||
url = "http://127.0.0.1:8792/seasons.xml"
|
||||
auto_download = false
|
||||
|
||||
# Downloads its image, so the UI has a file that is not playable to deal with.
|
||||
[feeds.picture-blog]
|
||||
url = "http://127.0.0.1:8792/pics.xml"
|
||||
|
||||
@@ -13,6 +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).
|
||||
- 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).
|
||||
|
||||
@@ -989,6 +989,13 @@ kbd{font:inherit;font-size:12px;color:var(--fg);background:var(--panel2);border:
|
||||
.tabs button.on{background:var(--raise);color:var(--fg);font-weight:500}
|
||||
.tabs a{padding:5px 12px;border-radius:7px;font-size:13px;color:var(--dim);text-decoration:none}
|
||||
.tabs a.on{background:var(--raise);color:var(--fg);font-weight:500}
|
||||
/* A podcast's seasons (#482): the tabs' track, scrolled sideways when there are more than fit. */
|
||||
.tabs.seasons{max-width:100%;overflow-x:auto;scrollbar-width:none}
|
||||
.tabs.seasons::-webkit-scrollbar{display:none}
|
||||
.tabs.seasons button{white-space:nowrap;flex:none}
|
||||
/* Where a season starts in the list of every season. */
|
||||
.sdiv{padding:14px 8px 5px;font-size:12px;font-weight:600;letter-spacing:.05em;text-transform:uppercase;color:var(--dim);border-bottom:1px solid var(--line)}
|
||||
.sdiv:first-child{padding-top:4px}
|
||||
|
||||
/* ---------- the admin page (admin.html) ---------- */
|
||||
/* One column that scrolls under the same header, rather than the app's fixed panes. */
|
||||
@@ -1539,6 +1546,8 @@ body:has(#player.on) #status{padding-bottom:3px}
|
||||
.tabs{flex:1 1 100%;border-radius:10px;padding:2px}
|
||||
.tabs button,.tabs a{flex:1;text-align:center;padding:7px 4px;border-radius:8px;font-size:14px}
|
||||
.tabs button.on,.tabs a.on{box-shadow:0 1px 3px rgba(0,0,0,.22)}
|
||||
/* Seasons keep their own widths, scrolling past the edge, rather than squeezing eight into 390px. */
|
||||
.tabs.seasons button{flex:none;padding:7px 12px}
|
||||
|
||||
/* Rows: taller, larger type, and a hairline between them that starts where the text does. */
|
||||
.ep{padding:10px 8px;border-radius:10px;min-height:44px}
|
||||
|
||||
@@ -29,7 +29,7 @@ const WEB_VERSION = JSON.parse(fs.readFileSync(path.join(here, '..', 'package.js
|
||||
// The files are one script, concatenated in this order, not modules: they share one top-level
|
||||
// scope, as the single inline script did, and code that runs at load needs what came before it.
|
||||
const PAGES: Record<string, { script: string, src: string[] }> = {
|
||||
'index.html': { script: 'app.js', src: ['util', 'wire', 'theme', 'feeds', 'feedpage', 'items', 'player', 'upnext', 'nowplaying', 'dialogs', 'signals', 'playlists', 'gestures', 'offline', 'events', 'native'] },
|
||||
'index.html': { script: 'app.js', src: ['util', 'wire', 'theme', 'feeds', 'feedpage', 'items', 'seasons', 'player', 'upnext', 'nowplaying', 'dialogs', 'signals', 'playlists', 'gestures', 'offline', 'events', 'native'] },
|
||||
'admin.html': { script: 'admin.js', src: ['util', 'wire', 'theme', 'admin'] },
|
||||
'login.html': { script: 'login.js', src: ['login'] },
|
||||
};
|
||||
|
||||
@@ -99,6 +99,8 @@ function renderFeed(){
|
||||
renderFeed(); loadEntries();
|
||||
});
|
||||
if(f) wireFailBanner(box,f);
|
||||
// An OPML's page is many podcasts' episodes together, their seasons each their own.
|
||||
if(f&&!kids.length) loadSeasons(f);
|
||||
}
|
||||
|
||||
/// The item table's headings, each a button that sorts by its column. The first click goes the
|
||||
|
||||
@@ -202,7 +202,7 @@ function renderFeeds(){
|
||||
done();
|
||||
}
|
||||
function selectFeed(id: string){
|
||||
S.feed=id; S.offset=0; S.sel=null; S.q=''; $<HTMLInputElement>('#epSearch').value='';
|
||||
S.feed=id; S.offset=0; S.sel=null; S.q=''; S.season=''; $<HTMLInputElement>('#epSearch').value='';
|
||||
try{ localStorage.setItem('ipx.feed',id); }catch{}
|
||||
renderFeeds(); renderFeed(); loadEntries();
|
||||
}
|
||||
|
||||
@@ -14,10 +14,13 @@ const lists=new Map<string,ListPage>();
|
||||
const LISTS_KEPT=40;
|
||||
/// Lists on their way, so a click on one already being fetched ahead waits for that answer.
|
||||
const fetching=new Map<string,Promise<ListPage>>();
|
||||
const listKey=(feed: string, filter=S.filter)=>[feed,filter,S.sort.col,S.sort.dir,S.q].join('\n');
|
||||
// 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');
|
||||
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});
|
||||
if(S.q) p.set('q',S.q);
|
||||
if(seasonFor(feed)) p.set('season',seasonFor(feed));
|
||||
const sg=signalId(feed);
|
||||
return feed===':all' ? `/api/entries?${p}`
|
||||
: sg!==null ? `/api/signals/${sg}/entries?${p}`
|
||||
@@ -155,7 +158,14 @@ function renderEntries(){
|
||||
else if(sg&&S.filter==='all') box.innerHTML='<p class="empty">Nothing has come through yet. New items are read as your feeds are checked.</p>';
|
||||
return;
|
||||
}
|
||||
for(const e of S.entries) box.appendChild(epEl(e));
|
||||
const breaks=seasonBreaks();
|
||||
let last: number|null|undefined;
|
||||
S.entries.forEach((e,i)=>{
|
||||
if(breaks&&(i===0||(e.season??null)!==(last??null)))
|
||||
box.insertAdjacentHTML('beforeend',`<div class="sdiv" role="heading" aria-level="3">${seasonName(e.season)}</div>`);
|
||||
last=e.season;
|
||||
box.appendChild(epEl(e));
|
||||
});
|
||||
syncPlayButtons();
|
||||
if(pane) pane.scrollTop=top;
|
||||
if(hasMore()){
|
||||
|
||||
50
web/src/seasons.ts
Normal file
50
web/src/seasons.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/* ---------------- seasons (#482) ---------------- */
|
||||
/// A podcast's seasons, by feed id, as its page last fetched them, so going back to it draws its
|
||||
/// picker at once while the counts are asked for again.
|
||||
const seasonsOf=new Map<string,SeasonCount[]>();
|
||||
/// Whether a podcast is told in seasons: two or more of them, holding most of its episodes. A few
|
||||
/// numbered among hundreds (The Vintage RPG Podcast's 2 of 366), or years given as seasons on a
|
||||
/// quarter of them (Ken and Robin's), are no seasons worth a picker.
|
||||
function seasonsShown(list: SeasonCount[]|undefined): boolean{
|
||||
if(!list) return false;
|
||||
const numbered=list.filter(s=>s.season!=null);
|
||||
const inOne=numbered.reduce((n,s)=>n+s.episodes,0), all=list.reduce((n,s)=>n+s.episodes,0);
|
||||
return numbered.length>=2 && inOne*2>=all;
|
||||
}
|
||||
/// What the picker sends for a season: its number, or `none` for the episodes that name none.
|
||||
const seasonKey=(s: SeasonCount)=>s.season==null?'none':String(s.season);
|
||||
const seasonName=(s: number|null|undefined)=>s==null?'Other episodes':`Season ${s}`;
|
||||
/// The picker, under the tabs: every season, one of them, or the episodes naming none.
|
||||
function seasonsHTML(list: SeasonCount[]): string{
|
||||
const chip=(key: string,label: string,title: string)=>
|
||||
`<button data-season="${key}" class="${S.season===key?'on':''}" aria-pressed="${S.season===key}" title="${title}">${label}</button>`;
|
||||
return `<div class="tabs seasons" role="group" aria-label="Seasons">${chip('','All seasons','Every season')}${
|
||||
list.map(s=>chip(seasonKey(s),s.season==null?'Other':`Season ${s.season}`,
|
||||
`${plural(s.episodes,'episode')}, ${s.unread} unread`)).join('')}</div>`;
|
||||
}
|
||||
function drawSeasons(f: Feed, list: SeasonCount[]|undefined){
|
||||
const bar=$('#content .toolbar'); if(!bar||S.feed!==f.id) return;
|
||||
bar.querySelector('.seasons')?.remove();
|
||||
if(!list||!seasonsShown(list)) return;
|
||||
bar.insertAdjacentHTML('beforeend',seasonsHTML(list));
|
||||
$$<HTMLButtonElement>('.seasons button',bar).forEach(b=>b.onclick=()=>{
|
||||
S.season=b.dataset.season!; S.offset=0;
|
||||
renderFeed(); loadEntries();
|
||||
});
|
||||
// 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.
|
||||
async function loadSeasons(f: Feed){
|
||||
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);
|
||||
}catch{}
|
||||
}
|
||||
/// 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 ?? ''));
|
||||
}
|
||||
@@ -141,6 +141,9 @@ interface State {
|
||||
/// Whether the server has more after the last page it sent, by that answer's own numbers.
|
||||
more: boolean;
|
||||
filter: string;
|
||||
/// One season of the open podcast (#482): its number, `none` for the episodes naming none, or
|
||||
/// empty for every season.
|
||||
season: string;
|
||||
q: string;
|
||||
/// The selected item's guid.
|
||||
sel: string | null;
|
||||
@@ -148,6 +151,14 @@ interface State {
|
||||
sort: {col: string, dir: 'asc' | 'desc'};
|
||||
}
|
||||
|
||||
/// One season of a podcast, `/api/feeds/{id}/seasons` (db.rs SeasonCount, #482). No season is
|
||||
/// the episodes that name none.
|
||||
interface SeasonCount {
|
||||
season?: number | null;
|
||||
episodes: number;
|
||||
unread: number;
|
||||
}
|
||||
|
||||
/// A smart playlist, `/api/playlists` (db.rs PlaylistRow, #476).
|
||||
interface Playlist {
|
||||
id: number;
|
||||
|
||||
@@ -345,7 +345,7 @@ const S: State = {
|
||||
feed:(()=>{ try{ return localStorage.getItem('ipx.feed'); }catch{ return null; } })(),
|
||||
entries:[], total:0, offset:0, more:false,
|
||||
filter:(()=>{ try{ return localStorage.getItem('ipx.filter'); }catch{ return null; } })()||'all',
|
||||
q:'', sel:null, me:null,
|
||||
season:'', q:'', sel:null, me:null,
|
||||
// The item table's order, kept across visits. The server sorts: a list arrives fifty at a time.
|
||||
sort:(()=>{ try{ return JSON.parse(localStorage.getItem('ipx.sort')??'null'); }catch{ return null; } })()
|
||||
||{col:'published',dir:'desc'},
|
||||
|
||||
Reference in New Issue
Block a user