diff --git a/Cargo.lock b/Cargo.lock
index fe24c1d..9c9ccc9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -389,6 +389,12 @@ version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
+[[package]]
+name = "core_detect"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48"
+
[[package]]
name = "cpufeatures"
version = "0.2.17"
@@ -790,6 +796,20 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
+[[package]]
+name = "encoding_rs"
+version = "0.8.44"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "89253175e704ab869b04f9db224d38630e0211a53841a79181deae0889e169f5"
+dependencies = [
+ "cfg-if",
+ "core_detect",
+ "multiversion_no_op",
+ "rustversion",
+ "scopeguard",
+ "simdutf8",
+]
+
[[package]]
name = "enum-assoc"
version = "1.3.0"
@@ -2071,6 +2091,12 @@ dependencies = [
"uuid",
]
+[[package]]
+name = "multiversion_no_op"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d"
+
[[package]]
name = "music-dht"
version = "0.5.0"
@@ -2079,10 +2105,12 @@ dependencies = [
"async-trait",
"blake3",
"data-encoding",
+ "encoding_rs",
"federation-net",
"futures",
"iroh",
"postcard",
+ "quick-xml",
"rand 0.9.5",
"rusqlite",
"serde",
@@ -2092,6 +2120,7 @@ dependencies = [
"tokio",
"tracing",
"unicode-normalization",
+ "url",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 568c7b7..86aa1c5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -38,3 +38,6 @@ lofty = "0.22"
data-encoding = "2"
rand = "0.9"
tempfile = "3"
+quick-xml = "0.41"
+encoding_rs = "0.8.35"
+url = "2.5"
diff --git a/crates/music-dht/Cargo.toml b/crates/music-dht/Cargo.toml
index a376ffd..cec4116 100644
--- a/crates/music-dht/Cargo.toml
+++ b/crates/music-dht/Cargo.toml
@@ -26,6 +26,13 @@ thiserror = { workspace = true }
tracing = { workspace = true }
rand = { workspace = true }
data-encoding = { workspace = true }
+quick-xml = { workspace = true, optional = true }
+encoding_rs = { workspace = true, optional = true }
+url = { workspace = true, optional = true }
+
+[features]
+# RSS 2.0 / RSS 1.0 / Atom podcast feed parser (`music_dht::podcast::feed`).
+podcast-feed = ["dep:quick-xml", "dep:encoding_rs", "dep:url"]
[dev-dependencies]
anyhow = { workspace = true }
diff --git a/crates/music-dht/src/podcast/feed.rs b/crates/music-dht/src/podcast/feed.rs
new file mode 100644
index 0000000..8da47b8
--- /dev/null
+++ b/crates/music-dht/src/podcast/feed.rs
@@ -0,0 +1,1775 @@
+//! Shared tolerant RSS 2.0 / RSS 1.0 / Atom parser for podcast feeds.
+//!
+//! Available with the `podcast-feed` cargo feature. Every Furumi client uses
+//! this parser because episode identity depends on what it extracts.
+//!
+//! Real-world feeds are frequently sloppy: undeclared namespace prefixes,
+//! HTML entities that XML does not define, mismatched closing tags, legacy
+//! single-byte encodings and creative date formats. The parser is a single
+//! iterative pass over `quick-xml` events (no recursion), keeps only the
+//! fields Furumi needs, bounds every captured value and never panics on
+//! malformed input. It performs no I/O: fetching, redirects, conditional
+//! requests and scheduling belong to the client runtime.
+//!
+//! ```
+//! use music_dht::podcast::feed::parse_feed_with_base;
+//! use music_dht::podcast::{FeedUrl, PodcastId};
+//!
+//! let xml = br#"Show
+//! - Pilotep-1
+//!
+//! "#;
+//! let url = FeedUrl::parse("https://example.test/feed.xml").unwrap();
+//! let feed = parse_feed_with_base(xml, Some(url.as_str())).unwrap();
+//! let podcast = PodcastId::from_feed_url(&url);
+//! let ids = feed.resolve_episode_ids(&podcast, &[]);
+//! let episode = feed.episodes[0].to_meta(&podcast, ids[0].clone().unwrap());
+//! assert_eq!(episode.audio_url, "https://example.test/audio/1.mp3");
+//! ```
+
+use std::borrow::Cow;
+use std::collections::HashSet;
+
+use quick_xml::events::{BytesStart, Event};
+use quick_xml::reader::Reader;
+use url::Url;
+
+use super::{
+ EpisodeId, EpisodeIdentityHints, EpisodeMeta, EpisodeType, FeedUrl, KnownEpisode,
+ MAX_DESCRIPTION_CHARS, MAX_GUID_BYTES, MAX_TITLE_CHARS, PodcastError, PodcastId, PodcastMeta,
+ PodcastResult, is_http_url, resolve_episode_ids,
+};
+
+/// Upper bound on episodes taken from a single feed document.
+pub const MAX_EPISODES: usize = 20_000;
+/// Raw text captured for one element is capped to keep memory bounded on
+/// hostile or broken documents.
+const MAX_CAPTURE_BYTES: usize = 512 * 1024;
+/// Elements nested deeper than this are skipped (their events are ignored).
+const MAX_DEPTH: usize = 256;
+/// Durations longer than this (about 115 days) are treated as garbage.
+const MAX_DURATION_SECONDS: f64 = 10_000_000.0;
+const UNTITLED_EPISODE: &str = "Untitled episode";
+const UNTITLED_PODCAST: &str = "Untitled podcast";
+
+/// Channel-level result of [`parse_feed`].
+#[derive(Debug, Clone, PartialEq)]
+pub struct ParsedFeed {
+ /// Podcast title (never empty).
+ pub title: String,
+ /// Author (`itunes:author`, Atom author, `dc:creator`, `managingEditor`).
+ pub author: Option,
+ /// Plain-text description, at most [`MAX_DESCRIPTION_CHARS`].
+ pub description: Option,
+ /// Publisher web page.
+ pub link: Option,
+ /// Absolute http(s) artwork URL.
+ pub image_url: Option,
+ /// `itunes:new-feed-url`, verbatim. Clients canonicalize it with
+ /// [`FeedUrl::parse`] and record it as a feed alias.
+ pub new_feed_url: Option,
+ /// Playable items in document order, duplicates removed.
+ pub episodes: Vec,
+}
+
+/// One playable feed item.
+#[derive(Debug, Clone, PartialEq)]
+pub struct ParsedEpisode {
+ /// RSS `` / Atom ``, trimmed; `None` when absent, blank or
+ /// longer than [`MAX_GUID_BYTES`].
+ pub guid: Option,
+ /// RSS `guid isPermaLink` (default `true` per RSS 2.0); `None` without
+ /// an RSS GUID. Informational: identity uses the GUID text either way.
+ pub guid_is_permalink: Option,
+ /// Title (never empty).
+ pub title: String,
+ /// Plain-text description, at most [`MAX_DESCRIPTION_CHARS`].
+ pub description: Option,
+ /// Publication time in unix milliseconds.
+ pub published_at_ms: Option,
+ /// Announced duration in milliseconds.
+ pub duration_ms: Option,
+ /// `itunes:season`.
+ pub season: Option,
+ /// `itunes:episode`.
+ pub episode_number: Option,
+ /// `itunes:episodeType`.
+ pub episode_type: EpisodeType,
+ /// Absolute http(s) audio URL (never a local file).
+ pub audio_url: String,
+ /// Enclosure MIME type, lowercased, without parameters.
+ pub mime_type: Option,
+ /// Enclosure length in bytes.
+ pub byte_len: Option,
+ /// Item web page.
+ pub link: Option,
+ /// Absolute http(s) artwork URL.
+ pub image_url: Option,
+}
+
+impl ParsedEpisode {
+ /// Identity hints for [`resolve_episode_ids`].
+ pub fn identity_hints(&self) -> EpisodeIdentityHints {
+ EpisodeIdentityHints {
+ guid: self.guid.clone(),
+ enclosure_url: Some(self.audio_url.clone()),
+ link: self.link.clone(),
+ published_at_ms: self.published_at_ms,
+ title: Some(self.title.clone()),
+ }
+ }
+
+ /// Contract metadata for this item under a resolved id.
+ pub fn to_meta(&self, podcast_id: &PodcastId, episode_id: EpisodeId) -> EpisodeMeta {
+ EpisodeMeta {
+ episode_id,
+ podcast_id: podcast_id.clone(),
+ guid: self.guid.clone(),
+ title: self.title.clone(),
+ description: self.description.clone(),
+ season: self.season,
+ episode_number: self.episode_number,
+ episode_type: self.episode_type,
+ published_at_ms: self.published_at_ms,
+ duration_ms: self.duration_ms,
+ audio_url: self.audio_url.clone(),
+ mime: self.mime_type.clone(),
+ byte_len: self.byte_len,
+ image_url: self.image_url.clone(),
+ link: self
+ .link
+ .clone()
+ .filter(|link| link.len() <= super::MAX_URL_BYTES),
+ }
+ }
+}
+
+impl ParsedFeed {
+ /// Identity hints of every episode, in order.
+ pub fn identity_hints(&self) -> Vec {
+ self.episodes
+ .iter()
+ .map(ParsedEpisode::identity_hints)
+ .collect()
+ }
+
+ /// Resolves stable ids for every episode (see [`resolve_episode_ids`]).
+ pub fn resolve_episode_ids(
+ &self,
+ podcast_id: &PodcastId,
+ known: &[KnownEpisode],
+ ) -> Vec