vc=82 — subscription-feed enrichment via lightweight stream_metadata
All checks were successful
build-apk / build-and-publish (push) Successful in 7m1s
gitleaks / scan (push) Successful in 43s

enrich_feed_item now calls the new strawcore stream_metadata() path (Android
/player + videoDetails read only) instead of the full stream_info. The full
path ran the JS sig/nsig deobf, an extra WEB /player metadata round-trip, the
iOS client, and stream/manifest/caption extraction — then kept only view_count
+ duration_seconds. Those two come from the same videoDetails the lightweight
path reads (populate_microformat never touches them), so the values are
identical; the feed just stops paying for the discarded work — ~one heavy
round-trip dropped per enriched item per refresh.

FFI surface (enrichFeedItem -> EnrichedFeedMetadata) unchanged. Needs
strawcore 30f24d2 (pushed first; CI clones strawcore main).
This commit is contained in:
Cobb 2026-06-21 06:56:06 -07:00
parent 1730ed3dc8
commit 2b3eb8bef4
3 changed files with 45 additions and 10 deletions

View file

@ -47,11 +47,13 @@ const YEAR_MAX: i32 = 2200;
///
/// built specifically so the subs feed can show 'N views ·
/// X duration' the way YT does, without paying the full channel_info
/// page-scrape cost on initial paint. The underlying stream_info IS
/// heavier than we'd like (~500ms each, runs JS deobf for play URLs
/// we'll discard) — future opt would be to parse the watch-page HTML
/// JSON state directly for just these two fields. ~100ms savings per
/// call but ~150 lines of HTML/JSON pluck logic. Punted until needed.
/// page-scrape cost on initial paint. Backed by the lightweight
/// `stream::stream_metadata` path (Android `/player` `videoDetails`
/// only) — it skips the JS sig/nsig deobf, the extra WEB `/player`
/// metadata round-trip, the iOS client, and stream/manifest/caption
/// extraction the full `stream_info` runs, all of which the feed would
/// discard. Same two values the full path would return, minus the
/// ~500ms JS/stream tail + the redundant WEB round-trip.
#[derive(Debug, Clone, uniffi::Record)]
pub struct EnrichedFeedMetadata {
pub view_count: i64,
@ -63,10 +65,10 @@ pub async fn enrich_feed_item(
video_url: String,
) -> Result<EnrichedFeedMetadata, StrawcoreError> {
crate::runtime::ensure_initialized();
let info = crate::stream::stream_info(video_url).await?;
let (view_count, duration_seconds) = crate::stream::stream_metadata(video_url).await?;
Ok(EnrichedFeedMetadata {
view_count: info.view_count,
duration_seconds: info.duration_seconds,
view_count,
duration_seconds,
})
}

View file

@ -7,6 +7,7 @@
use strawcore_core::youtube::linkhandler::stream::extract_video_id;
use strawcore_core::youtube::stream_extractor::stream_info as core_stream_info;
use strawcore_core::youtube::stream_extractor::stream_metadata as core_stream_metadata;
use crate::error::StrawcoreError;
use crate::search::SearchItem;
@ -69,6 +70,23 @@ pub async fn stream_info(input: String) -> Result<StreamInfo, StrawcoreError> {
Ok(map_stream_info(video_id, core))
}
/// Metadata-only fetch — returns `(view_count, duration_seconds)` from the
/// Android `videoDetails`, skipping the JS-deobf / streams / extra WEB
/// round-trip the full `stream_info` pays. Backs `enrich_feed_item`, which
/// only needs those two fields. Non-negative clamping mirrors
/// `map_stream_info` so the values are identical to the full path's.
pub async fn stream_metadata(input: String) -> Result<(i64, i64), StrawcoreError> {
log::info!("strawcore::stream_metadata input_len={}", input.len());
crate::runtime::ensure_initialized();
let video_id = resolve_video_id(&input)?;
let core = tokio::task::spawn_blocking(move || core_stream_metadata(&video_id))
.await
.map_err(|e| StrawcoreError::Extractor {
msg: format!("join: {e}"),
})??;
Ok((clamp_nonneg(core.view_count), core.duration_seconds.max(0)))
}
fn resolve_video_id(input: &str) -> Result<String, StrawcoreError> {
let trimmed = input.trim();
// Bare 11-char id?