An untitled item is named as it is stored, not by the page each time (#502)

The page named an item its feed gave no title (the first 120 characters of
its text, else its file's name) every time it drew one, so the iOS
widget, CarPlay, search and Signals never saw a name, and the list had to
carry each item's whole text to name the untitled ones (#501).

The feed parser now names them the same way as it reads a feed, for ipx
and the directory alike, and ipx names the untitled items already stored
once, in batches, before making search text, which the name goes into.
The reader and the directory's preview leave off a title that is only the
opening of the text below it, as they did for an untitled item.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RqkrVCCH8YcP2Y3i8VNYWA
This commit is contained in:
2026-11-28 10:49:32 -05:00
parent 467ac138e3
commit e2e8105880
12 changed files with 197 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- An episode its feed gives no title is named by the opening of its text or else its file's name, where it had none (#502).
- Its checks of YouTube channels go one at a time, two seconds apart, since YouTube refuses many asked together (#386).
- Its JSON log lines no longer carry their span, once on its own and again in a list, which said nothing the line's own fields did not (#363).

View File

@@ -14,6 +14,7 @@ chrono.workspace = true
http.workspace = true
hyper-util.workspace = true
opml.workspace = true
percent-encoding.workspace = true
pulldown-cmark.workspace = true
quick-xml.workspace = true
reqwest.workspace = true

View File

@@ -21,7 +21,7 @@ pub use failure::{Failure, explain_failure, failure_kind, is_temporary_lookup_fa
pub use fetch::{FEED_SILENCE, FEED_TIMEOUT, FETCHED_BYTES, FETCHES, Fetched, fetch, is_youtube_feed};
pub use jev::{JEV_URL, classify};
pub use outlines::{collect_outlines, is_opml, opml_title, parse_opml, read_opml};
pub use parse::{Enclosure, Entry, ParsedFeed, markdown_html, parse, same_file_key};
pub use parse::{Enclosure, Entry, ParsedFeed, markdown_html, parse, same_file_key, untitled_name};
pub use patreon::{is_patreon_creator, patreon_shows, same_feed};
pub use privacy::{redact, redact_text, url_looks_private};

View File

@@ -62,9 +62,53 @@ pub struct Enclosure {
pub length: Option<i64>,
}
/// RSS first, then Atom -- the same split the original made on `parsedFeed.version`.
/// RSS first, then Atom -- the same split the original made on `parsedFeed.version`. An item
/// without a title is named here, once, for everything that shows it (#502).
#[tracing::instrument(skip_all, fields(bytes = bytes.len()))]
pub fn parse(bytes: &[u8]) -> Result<ParsedFeed> {
let mut feed = parse_any(bytes)?;
for e in &mut feed.entries {
if e.title.is_none() {
e.title = untitled_name(e.description.as_deref(), e.enclosures.first().map(|x| x.url.as_str()));
}
}
Ok(feed)
}
/// A name for an item its feed gave no title: the first words of its text, cut at a word near
/// 120 characters, or else its file's name without the extension. What the page worked out each
/// time it drew one, until the iOS widget, CarPlay and search, which never saw it, needed it too.
pub fn untitled_name(description: Option<&str>, file: Option<&str>) -> Option<String> {
// Entities decoded, spaces made single; a tag is a space, so "2010)</p><p>Recorded" stays apart.
let words = description
.and_then(|d| title_text(Some(&text_of(d).split_whitespace().collect::<Vec<_>>().join(" "))))
.unwrap_or_default();
if !words.is_empty() {
let mut chars = words.chars();
let head: String = chars.by_ref().take(120).collect();
if chars.next().is_none() {
return Some(words);
}
// The word the cut fell in is dropped whole, as the page's /\s+\S*$/ did.
let cut = head.rfind(char::is_whitespace).map_or(head.as_str(), |at| head[..at].trim_end());
return Some(format!("{cut}\u{2026}"));
}
let path = file?.split(['?', '#']).next()?;
let last = path.rsplit('/').next().filter(|s| !s.is_empty())?;
let stem = match last.rsplit_once('.') {
Some((stem, ext))
if !stem.is_empty() && (1..=5).contains(&ext.len()) && ext.chars().all(|c| c.is_ascii_alphanumeric()) =>
{
stem
}
_ => last,
};
let name =
percent_encoding::percent_decode_str(stem).decode_utf8().map_or_else(|_| stem.to_owned(), |d| d.into_owned());
non_empty(Some(&name))
}
fn parse_any(bytes: &[u8]) -> Result<ParsedFeed> {
if bytes.trim_ascii_start().starts_with(b"[")
&& let Ok(posts) = serde_json::from_slice::<Vec<serde_json::Value>>(bytes)
{
@@ -613,6 +657,37 @@ mod tests {
use super::*;
use crate::failure;
#[test]
fn an_untitled_item_is_named_by_its_words_or_its_file() {
// Short text whole, decoded, the blocks kept apart.
assert_eq!(
untitled_name(Some("<p>Fish &amp; chips (2010)</p><p>Recorded</p>"), None).as_deref(),
Some("Fish & chips (2010) Recorded")
);
// Long text cut at the last whole word inside 120 characters.
let long = "word ".repeat(40);
let name = untitled_name(Some(&long), None).unwrap();
assert_eq!(name, format!("{}\u{2026}", "word ".repeat(24).trim_end()));
assert!(name.chars().count() <= 121);
// No text: the file's name, its query and extension gone, its escapes decoded.
assert_eq!(
untitled_name(Some("<img src=x>"), Some("https://x.example/a/Ep%2042.mp3?t=1")).as_deref(),
Some("Ep 42")
);
assert_eq!(untitled_name(None, Some("https://x.example/")), None);
assert_eq!(untitled_name(None, None), None);
// Through parse: the feed's own title is kept, and only a missing one is made.
let feed = parse(
br#"<rss version="2.0"><channel><title>t</title>
<item><guid>a</guid><description>Hello there</description></item>
<item><guid>b</guid><title>Kept</title><description>Not this</description></item>
</channel></rss>"#,
)
.unwrap();
let titles: Vec<_> = feed.entries.iter().map(|e| e.title.as_deref()).collect();
assert_eq!(titles, [Some("Hello there"), Some("Kept")]);
}
#[test]
fn parses_rss_with_itunes_extensions() {
let bytes = include_bytes!("../../../tests/data/rss2.xml");

View File

@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- An item its feed gives no title is named as it is stored, by the opening of its text or else its file's name, so search, Signals, the iOS widget and CarPlay show the same name the page does; the untitled items already stored are named once at start (#502).
- Torrents go to qBittorrent through its Web API, set in `[torrent]` (`qbittorrent_url`, `username`, `password`, `save_path`), which downloads and seeds them until the episode is deleted; ipx no longer runs a BitTorrent client of its own or listens on 6881, and `port_range` is gone. Without a qBittorrent set, torrents are held back as when they are turned off (#494, #495).
- The server's command is `ipxd`, not `ipx`: `ipxd daemon`, `ipxd status`, `ipxd user add` and the rest, in the container as `docker exec iPX ipxd ...`. `ipx` is now the reader in a terminal (#437).

View File

@@ -1147,6 +1147,48 @@ impl Db {
.collect()
}
/// Up to `limit` items stored without a title, after the item `after` in (feed, guid) order:
/// feed, guid, description and first file, for naming them (#502). In order, not by
/// `title IS NULL` alone, because one with neither text nor file stays untitled and would be
/// read again forever.
pub async fn untitled(
&self,
after: (&str, &str),
limit: i64,
) -> Result<Vec<(String, String, Option<String>, Option<String>)>> {
self.rows(
"SELECT e.feed_id, e.guid, e.description,
(SELECT x.url FROM enclosures x WHERE x.feed_id = e.feed_id AND x.guid = e.guid
ORDER BY x.id LIMIT 1) AS file
FROM entries e
WHERE e.title IS NULL AND (e.feed_id > $1 OR (e.feed_id = $1 AND e.guid > $2))
ORDER BY e.feed_id, e.guid LIMIT $3",
vec![after.0.into(), after.1.into(), limit.into()],
)
.await?
.iter()
.map(|r| {
Ok((
r.try_get("", "feed_id")?,
r.try_get("", "guid")?,
r.try_get("", "description")?,
r.try_get("", "file")?,
))
})
.collect()
}
/// Names an untitled item, unless a scan has titled it meanwhile, and leaves its search text to
/// be made again with the name in it.
pub async fn name_untitled(&self, feed_id: &str, guid: &str, title: &str) -> Result<()> {
self.exec(
"UPDATE entries SET title = $3, search_text = NULL WHERE feed_id = $1 AND guid = $2 AND title IS NULL",
vec![feed_id.into(), guid.into(), title.into()],
)
.await?;
Ok(())
}
pub async fn set_search_text(&self, feed_id: &str, guid: &str, text: &str) -> Result<()> {
self.exec(
"UPDATE entries SET search_text = $3 WHERE feed_id = $1 AND guid = $2",
@@ -3927,6 +3969,42 @@ mod tests {
assert!(!order_sql("x'; --", "asc").contains("x'"));
}
#[tokio::test]
async fn items_stored_untitled_are_named_once_from_their_words_or_file() {
let db = Db::memory().await.unwrap();
db.exec_for_test(
"INSERT INTO entries (feed_id, guid, title, description, first_seen, search_text) VALUES
('f','words',NULL,'<p>Hello there</p>',1,'x'), ('f','file',NULL,NULL,2,'x'),
('f','none',NULL,NULL,3,'x'), ('f','kept','Mine','Other words',4,'x');
INSERT INTO enclosures (id, feed_id, guid, url, state) VALUES (1,'f','file','http://x/Ep%201.mp3','skipped');",
)
.await
.unwrap();
crate::search::name_untitled(&db).await.unwrap();
let rows = db.rows("SELECT guid, title, search_text FROM entries ORDER BY first_seen", vec![]).await.unwrap();
let got: Vec<(String, Option<String>, Option<String>)> = rows
.iter()
.map(|r| {
(r.try_get("", "guid").unwrap(), r.try_get("", "title").unwrap(), r.try_get("", "search_text").unwrap())
})
.collect();
let named = |g: &str, t: Option<&str>, search: Option<&str>| {
(g.to_owned(), t.map(str::to_owned), search.map(str::to_owned))
};
assert_eq!(
got,
[
named("words", Some("Hello there"), None),
named("file", Some("Ep 1"), None),
// Nothing to name it by: left alone, search text and all, and not looked at forever.
named("none", None, Some("x")),
named("kept", Some("Mine"), Some("x")),
]
);
// A second pass finds nothing more to do.
crate::search::name_untitled(&db).await.unwrap();
}
#[tokio::test]
async fn the_feed_list_in_one_go_matches_asking_feed_by_feed() {
let db = Db::memory().await.unwrap();

View File

@@ -55,6 +55,7 @@ pub async fn run(ctx: Arc<Ctx>, mut stop: tokio::sync::watch::Receiver<bool>) {
/// Every item without search text, given one, a batch at a time: how many.
async fn fill(ctx: &Ctx) -> anyhow::Result<usize> {
name_untitled(&ctx.db).await?;
let mut made = 0;
loop {
let batch = ctx.db.unsearched(BATCH).await?;
@@ -68,6 +69,23 @@ async fn fill(ctx: &Ctx) -> anyhow::Result<usize> {
}
}
/// Names the items stored before a feed's untitled ones were named as they were read (#502),
/// once, in batches; then finds none and costs one query a pass. Before the search text, which
/// the name goes into.
pub(crate) async fn name_untitled(db: &crate::db::Db) -> anyhow::Result<()> {
let mut after = (String::new(), String::new());
loop {
let batch = db.untitled((&after.0, &after.1), BATCH).await?;
let Some(last) = batch.last() else { return Ok(()) };
after = (last.0.clone(), last.1.clone());
for (feed, guid, description, file) in &batch {
if let Some(name) = crate::feed::untitled_name(description.as_deref(), file.as_deref()) {
db.name_untitled(feed, guid, &name).await?;
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;