fix(qt): play a downloaded album from Local Library through the offline tier

A CMAF download's `local_tracks.file_path` is the BUNDLE DIRECTORY
(`tracks-cmaf/<qobuz_id>/`, holding `init.mp4` and an encrypted
`segments.bin`), not a playable container. `LocalSource::playback` handed
it back as a `PlaybackTicket::File`, the read failed with EISDIR, and the
audible step 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. The bar
adopted the track anyway, so the album looked like it was playing and no
audio came out.

Three funnels reach the audible step and only two excluded an offline row:
`play_current_if_local` (auto-advance) and
`playback_qt::play_resolved_offline_aware`. The Local Library PLAY funnel
did not, nor did its hand-copy in `local_album_actions`. Only qbz-core's
offline tier can decrypt the bundle, and the row carries the real Qobuz
catalog id precisely so that tier can be asked for it.

- `local_playback::play_audible` is now the ONLY copy of the audible step
  and routes an offline row to the offline tier; `local_album_actions`
  drops its copy and calls it.
- `LocalSource::playback` refuses an offline row with `BadIdShape` instead
  of emitting a ticket that lies. The test is on the row data, never
  `is_dir()`: a stat there would block for the mount timeout on the
  unreachable share the audible step's bounded probe exists to survive.
- Tests run the row through the real `local_queue_track`, because the two
  halves that must agree are its source word and the badge the router reads.

Verified by driving the window: album play, track-row play and skip-next all
log `[Core] track ... served from OFFLINE cache` and decode at 44.1 kHz /
24-bit; a plain user-file album still plays through the local audible step at
96 kHz / 24-bit. qbz-qt 431/431, qbz-source 91/91.

cc
This commit is contained in:
vicrodh committed 2026-08-20 18:16:33 -06:00
1 parent 900517db57
commit 8c3514b899
3 files changed
+122 -22

No files matched your search

+6 -21
View File
@@ -471,26 +471,6 @@ fn publish_doc(doc: Option<AlbumDetailDoc>) {
}); });
} }
/// 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 /// 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 /// (`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). /// 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<LocalTrack>) {
}; };
runtime.core().set_queue(queue, Some(0)).await; runtime.core().set_queue(queue, Some(0)).await;
crate::playback_qt::publish_queue(runtime).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; crate::playback_qt::refresh_now_playing(runtime).await;
} }
+89 -1
View File
@@ -256,6 +256,17 @@ pub fn local_queue_track(t: &LocalTrack) -> QueueTrack {
// Audible steps // 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`. /// Route ONE queue track to its audible step — through `qbz-source`.
/// ///
/// This used to `match track.source.as_deref()`, with a `Some("plex")` arm /// 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; /// `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. /// `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/<qobuz_id>/`, 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 { match crate::audible_qt::play_queue_track(runtime, track).await {
Ok(played) => played, Ok(played) => played,
Err(e) => { Err(e) => {
@@ -664,6 +705,53 @@ mod tests {
assert!(order_by_visible(&rows, &[], 1).is_none()); 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"
);
}
}
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
+27
View File
@@ -722,6 +722,33 @@ impl Source for LocalSource {
why: "a normalised local track id is always numeric", why: "a normalised local track id is always numeric",
})?; })?;
let row = self.track_row(row_id).ok_or_else(|| self.not_found(item))?; 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/<qobuz_id>/`, 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); let path = PathBuf::from(&row.file_path);
// The player keys on the QUEUE's id, which is what every caller passes // The player keys on the QUEUE's id, which is what every caller passes