diff --git a/crates/qbz-qt/src/local_album_actions.rs b/crates/qbz-qt/src/local_album_actions.rs index 148436a70..4da2d79c7 100644 --- a/crates/qbz-qt/src/local_album_actions.rs +++ b/crates/qbz-qt/src/local_album_actions.rs @@ -471,26 +471,6 @@ fn publish_doc(doc: Option) { }); } -/// Route ONE queue track to its audible step. -/// -/// This WAS a hand-copy of `local_playback::play_audible`, rating-key ladder -/// and all, kept in sync by comment. It is now the same single call, so there -/// is nothing left to keep in sync: `SourceRegistry::playback` claims the row -/// and `audible_qt` performs the ticket. The PROTECTED audio path is entered, -/// never modified. -async fn play_audible(runtime: &Runtime, track: &QueueTrack) -> bool { - match crate::audible_qt::play_queue_track(runtime, track).await { - Ok(played) => played, - Err(e) => { - log::error!( - "[qbz-qt] local album play: track {} not playable: {e}", - track.id - ); - false - } - } -} - /// A track SUBSET becomes the queue and starts at its first row /// (`local_playback::play_rows` over an explicit list — that one is private and /// only reachable by album/folder id, which a per-disc menu cannot express). @@ -501,7 +481,12 @@ async fn play_rows(runtime: &Runtime, tracks: Vec) { }; runtime.core().set_queue(queue, Some(0)).await; crate::playback_qt::publish_queue(runtime).await; - play_audible(runtime, &first).await; + // THE shared audible step, not a second copy of it. The last hand-copy of + // this function lived here and was kept in sync by comment; it drifted + // anyway — it never learned that an OFFLINE row belongs to the offline + // tier, so a per-disc play of a downloaded album went silent exactly like + // the album funnel did. + crate::local_playback::play_audible(runtime, &first).await; crate::playback_qt::refresh_now_playing(runtime).await; } diff --git a/crates/qbz-qt/src/local_playback.rs b/crates/qbz-qt/src/local_playback.rs index 04e904365..139f9c984 100644 --- a/crates/qbz-qt/src/local_playback.rs +++ b/crates/qbz-qt/src/local_playback.rs @@ -256,6 +256,17 @@ pub fn local_queue_track(t: &LocalTrack) -> QueueTrack { // Audible steps // --------------------------------------------------------------------------- +/// Does this queue row belong to `qbz-core`'s OFFLINE tier rather than to the +/// local audible step? +/// +/// A pure test on the row, deliberately: the alternative is asking the +/// filesystem whether `file_path` is a directory, and that stats a path which +/// may live on an unreachable share — the exact block the audible step's +/// bounded probe exists to survive. +fn belongs_to_the_offline_tier(track: &QueueTrack) -> bool { + qbz_source::RawRef::from_queue_track(track).badge == qbz_source::SourceBadge::Offline +} + /// Route ONE queue track to its audible step — through `qbz-source`. /// /// This used to `match track.source.as_deref()`, with a `Some("plex")` arm @@ -276,7 +287,37 @@ pub fn local_queue_track(t: &LocalTrack) -> QueueTrack { /// /// `SourceRegistry::playback` claims the row ONCE and answers with a ticket; /// `audible_qt` performs it. No source is branched on by hand here any more. -async fn play_audible(runtime: &Runtime, track: &QueueTrack) -> bool { +/// +/// The ONE routing decision left is not a source branch, it is a TIER one: an +/// OFFLINE row is a file the local step cannot read. `library.db` stores a +/// CMAF download's `file_path` as the BUNDLE DIRECTORY +/// (`…/audio/tracks-cmaf//`, holding `init.mp4` + an encrypted +/// `segments.bin`), so `LocalSource::playback` hands back a +/// `PlaybackTicket::File` naming a directory and the read fails as +/// +/// audible: file not available at …/audio/tracks-cmaf/266725026 (drive unmounted?) +/// +/// — a message about a drive, for a bundle that is right there on disk. Only +/// `qbz-core`'s offline tier can decrypt it, and the row carries the real +/// Qobuz catalog id precisely so that tier can be asked. Two of the three +/// funnels into the audible step already excluded these rows +/// (`play_current_if_local`, `playback_qt::play_resolved_offline_aware`); the +/// LocalLibrary PLAY funnel did not, so every offline album played from that +/// view went silent. This is now the only copy of the test, and both local +/// play paths (here and `local_album_actions`) go through it. +pub(crate) async fn play_audible(runtime: &Runtime, track: &QueueTrack) -> bool { + if belongs_to_the_offline_tier(track) { + return match crate::playback_qt::play_resolved_offline_aware(runtime, track.id, 0).await { + Ok(()) => true, + Err(e) => { + log::error!( + "[qbz-qt] local play: offline track {} not playable: {e}", + track.id + ); + false + } + }; + } match crate::audible_qt::play_queue_track(runtime, track).await { Ok(played) => played, Err(e) => { @@ -664,6 +705,53 @@ mod tests { assert!(order_by_visible(&rows, &[], 1).is_none()); } + /// A DOWNLOADED row played from Local Library must be recognised as the + /// offline tier's, not the local audible step's. The regression this + /// guards was silent: `LocalSource` answered with a `File` ticket naming + /// the CMAF bundle DIRECTORY, the read failed as "drive unmounted?", and + /// the bar still adopted the track — the album looked like it was playing + /// and no audio came out. + /// + /// The test runs the row through the REAL `local_queue_track`, because the + /// two halves that have to agree are its source word and the badge the + /// router reads. Asserting the badge alone would keep passing if either + /// side were renamed. + #[test] + fn a_downloaded_row_is_the_offline_tiers_not_the_local_steps() { + let offline = LocalTrack { + id: 4938, + qobuz_track_id: Some(266_725_026), + source: Some("qobuz_download".into()), + file_path: "/c/qbz/audio/tracks-cmaf/266725026".into(), + ..Default::default() + }; + let row = super::local_queue_track(&offline); + assert!(super::belongs_to_the_offline_tier(&row)); + // And it is asked for by the QOBUZ id — the offline tier is keyed on + // it, and the library row id rides in the hint. + assert_eq!(row.id, 266_725_026); + assert_eq!(row.source_item_id_hint.as_deref(), Some("4938")); + } + + /// The other side of the same fork: a user file, a Plex item and a media + /// server row all stay with the local audible step. A predicate that said + /// "yes" here would send a file on disk down the Qobuz tier walk. + #[test] + fn every_other_local_source_stays_with_the_audible_step() { + for word in ["user", "plex", "jellyfin", "subsonic", "navidrome"] { + let t = LocalTrack { + id: 12, + source: Some(word.into()), + file_path: "/m/a.flac".into(), + ..Default::default() + }; + let row = super::local_queue_track(&t); + assert!( + !super::belongs_to_the_offline_tier(&row), + "{word} must not be routed to the offline tier" + ); + } + } } // --------------------------------------------------------------------------- diff --git a/crates/qbz-source/src/sources/local.rs b/crates/qbz-source/src/sources/local.rs index 0cc82222f..c541c1341 100644 --- a/crates/qbz-source/src/sources/local.rs +++ b/crates/qbz-source/src/sources/local.rs @@ -722,6 +722,33 @@ impl Source for LocalSource { why: "a normalised local track id is always numeric", })?; let row = self.track_row(row_id).ok_or_else(|| self.not_found(item))?; + + // An OFFLINE row is recognised here and REFUSED here, which is the + // discipline `BadIdShape` exists for: say no at the moment of the + // mistake instead of forwarding a shape that fails two layers down. + // + // A CMAF download's `local_tracks.file_path` is the BUNDLE DIRECTORY + // (`…/audio/tracks-cmaf//`, holding `init.mp4` and an + // AES-encrypted `segments.bin`), not a playable container. Returned as + // a `File` ticket it reached `std::fs::read`, which reported it as + // + // audible: file not available at …/tracks-cmaf/266725026 (drive unmounted?) + // + // — a message about a drive, for a bundle sitting on the local disk. + // Only `qbz-core`'s offline tier can decrypt it, and it is asked for by + // the QOBUZ catalog id the row carries in `QueueTrack.id`, not by this + // row id. NO fs call is made to decide this: a `is_dir()` here would + // block for the mount timeout on exactly the unreachable share the + // audible step's bounded probe exists to survive. + if SourceBadge::from_word(row.source.as_deref()) == SourceBadge::Offline { + return Err(SourceError::BadIdShape { + by: SourceId::LOCAL, + id: item.id().to_string(), + why: "an offline (qobuz_download) row is a CMAF bundle only qbz-core's offline \ + tier can read — play it by its Qobuz catalog id, not as a local file", + }); + } + let path = PathBuf::from(&row.file_path); // The player keys on the QUEUE's id, which is what every caller passes