Key queue items by source and keep episodes out of music-only paths
Podcast episodes share the sentinel id -1, so the queue key now checks
the episode id first (ep:...) and falls back to TrackItem::key instead of
local:{id}. Likes, playlists, metadata edits, music history, content-id
lookups, share links, similarity and artist/release jumps skip episodes;
Shift-J and the info popup open the podcast instead. Sync protocol 3
cannot carry episodes, so peers and Jam guests get the private-item
placeholder, handoff of a queue with episodes is refused and remote
SetState commands do not replace such a queue.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7583afaeba
commit
3567f5f395
10 files changed
+462
-12
No files matched your search
+59
-4
@@ -769,6 +769,22 @@ fn apply_playback_state_to_ui(
|
||||
.min(state.player.queue.len().saturating_sub(1));
|
||||
}
|
||||
|
||||
/// Shown when a queue with podcast episodes would be handed to a device.
|
||||
const PODCAST_HANDOFF_UNSUPPORTED: &str = "device handoff: the queue has podcast episodes, which \
|
||||
other devices cannot receive with this build yet (needs sync protocol v4)";
|
||||
/// Shown when another device tries to change a queue that has episodes.
|
||||
const PODCAST_REMOTE_CONTROL_UNSUPPORTED: &str = "remote control ignored: the queue has podcast \
|
||||
episodes, which other devices cannot see with this build yet";
|
||||
|
||||
fn queue_has_podcast_episodes(state: &AppState) -> bool {
|
||||
state.player.queue.iter().any(|track| track.is_podcast())
|
||||
|| state
|
||||
.player
|
||||
.current
|
||||
.as_ref()
|
||||
.is_some_and(|track| track.is_podcast())
|
||||
}
|
||||
|
||||
fn publish_playback_snapshot(state: &mut AppState, runtime: &Runtime) {
|
||||
if !state.device_playback.is_audio_owner() {
|
||||
return;
|
||||
@@ -947,6 +963,13 @@ pub(crate) fn transfer_active_to_remote_device(
|
||||
transfer_active_to_this_device(state, runtime);
|
||||
return;
|
||||
}
|
||||
if queue_has_podcast_episodes(state) {
|
||||
// Protocol 3 cannot carry episodes (they travel as private
|
||||
// placeholders), so the other device could neither play nor keep
|
||||
// them: refuse before ownership changes.
|
||||
state.status_message = Some(PODCAST_HANDOFF_UNSUPPORTED.into());
|
||||
return;
|
||||
}
|
||||
if let Err(error) = runtime.devices.claim_playback(&target_device_id) {
|
||||
state.status_message = Some(format!("device handoff: {error}"));
|
||||
return;
|
||||
@@ -2434,6 +2457,11 @@ fn report_history(
|
||||
listened_ms: i64,
|
||||
ended_reason: music_dht::device_sync::ListenEndReason,
|
||||
) {
|
||||
// Podcast episodes are not music history (no content id); their
|
||||
// listening sessions go to the podcast store (`podcast_runtime`).
|
||||
if track.is_podcast() {
|
||||
return;
|
||||
}
|
||||
let Some(listen_id) = listen_id else {
|
||||
return;
|
||||
};
|
||||
@@ -3068,6 +3096,12 @@ fn reset_artist_pagination(state: &mut AppState) {
|
||||
global.reloading = false;
|
||||
}
|
||||
|
||||
/// A row of the local music library (not a podcast episode, not a pending
|
||||
/// federated placeholder).
|
||||
fn is_library_row(track: &crate::library::models::TrackItem) -> bool {
|
||||
!track.is_podcast() && track.id >= 0
|
||||
}
|
||||
|
||||
/// Preserve the queue position while refreshing library-backed entries.
|
||||
///
|
||||
/// A playback key identifies a track, not a queue occurrence: the same track
|
||||
@@ -3081,7 +3115,7 @@ fn queue_position_after_refresh(
|
||||
let removed_before_current = queue
|
||||
.iter()
|
||||
.take(queue_pos)
|
||||
.filter(|track| track.id >= 0 && !refreshed_ids.contains(&track.id))
|
||||
.filter(|track| is_library_row(track) && !refreshed_ids.contains(&track.id))
|
||||
.count();
|
||||
queue_pos.saturating_sub(removed_before_current)
|
||||
}
|
||||
@@ -3103,9 +3137,22 @@ fn apply_queue_refresh(
|
||||
.cloned()
|
||||
.map(|track| (track_playback_key(&track), track))
|
||||
.collect();
|
||||
let current_id = state.player.current.as_ref().map(|track| track.id);
|
||||
// A current podcast episode (sentinel id) is never a deleted library
|
||||
// row; it takes the "not a library row" branch below.
|
||||
let current_id = state.player.current.as_ref().map(|track| {
|
||||
if track.is_podcast() {
|
||||
crate::library::models::TrackItem::NOT_A_LIBRARY_ROW
|
||||
} else {
|
||||
track.id
|
||||
}
|
||||
});
|
||||
let current_key = state.player.current.as_ref().map(track_playback_key);
|
||||
for track in &mut state.player.queue {
|
||||
// Podcast episodes are not library rows: their sentinel id matches
|
||||
// nothing and they are never refreshed from the library.
|
||||
if track.is_podcast() {
|
||||
continue;
|
||||
}
|
||||
if let Some(fresh) = by_id.get(&track.id) {
|
||||
*track = fresh.clone();
|
||||
} else if let Some(fresh) = by_key.get(&track_playback_key(track)) {
|
||||
@@ -3116,12 +3163,12 @@ fn apply_queue_refresh(
|
||||
.player
|
||||
.queue
|
||||
.iter()
|
||||
.any(|track| track.id >= 0 && !by_id.contains_key(&track.id));
|
||||
.any(|track| is_library_row(track) && !by_id.contains_key(&track.id));
|
||||
if had_missing {
|
||||
state
|
||||
.player
|
||||
.queue
|
||||
.retain(|track| track.id < 0 || by_id.contains_key(&track.id));
|
||||
.retain(|track| !is_library_row(track) || by_id.contains_key(&track.id));
|
||||
state.player.prefetched_pos = None;
|
||||
}
|
||||
if state.player.queue.is_empty() {
|
||||
@@ -3254,6 +3301,14 @@ fn handle_playback_command(
|
||||
) {
|
||||
match command {
|
||||
crate::devices::PlaybackCommand::SetState { state: wire, seek } => {
|
||||
if queue_has_podcast_episodes(state) {
|
||||
// The sender saw our episodes as private placeholders;
|
||||
// applying its queue would replace them. Keep ours.
|
||||
tracing::info!("ignored a remote playback command: the queue has podcast episodes");
|
||||
state.status_message = Some(PODCAST_REMOTE_CONTROL_UNSUPPORTED.into());
|
||||
publish_playback_snapshot(state, runtime);
|
||||
return;
|
||||
}
|
||||
let old_current_key = state.player.current.as_ref().map(track_playback_key);
|
||||
let old_playing = state.player.playing;
|
||||
let old_paused = state.player.paused;
|
||||
|
||||
@@ -126,3 +126,13 @@ pub fn seasons() -> Vec<SeasonSummary> {
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
/// Queue item for episode `n` of the fixture podcast ("Show").
|
||||
pub fn episode_track(n: u32) -> crate::library::models::TrackItem {
|
||||
let meta = row("Show", 0, 0, 0).summary.meta;
|
||||
crate::library::models::TrackItem::podcast_episode(
|
||||
episode(n, &format!("Episode {n}"), None)
|
||||
.episode
|
||||
.to_ref(&meta),
|
||||
)
|
||||
}
|
||||
+20
-1
@@ -1065,6 +1065,21 @@ fn handle_track_info(
|
||||
let len = tracks.len();
|
||||
match key.code {
|
||||
KeyCode::Esc | KeyCode::Enter | KeyCode::Char('q') => {}
|
||||
// An episode's "artist" is its podcast title: never look it up as a
|
||||
// federated artist (that would send a private title to the
|
||||
// network); open the podcast instead.
|
||||
KeyCode::Char('a')
|
||||
if tracks
|
||||
.get(cursor.min(len.saturating_sub(1)))
|
||||
.is_some_and(TrackItem::is_podcast) =>
|
||||
{
|
||||
let track = tracks[cursor.min(len.saturating_sub(1))].clone();
|
||||
if let Some(effect) =
|
||||
crate::app::update::podcasts::reveal_episode_podcast(state, &track)
|
||||
{
|
||||
super::perform_effect(state, runtime, effect);
|
||||
}
|
||||
}
|
||||
KeyCode::Char('a') => {
|
||||
let artists = tracks
|
||||
.get(cursor.min(len.saturating_sub(1)))
|
||||
@@ -1126,6 +1141,10 @@ fn handle_track_info(
|
||||
KeyCode::Char('c') => {
|
||||
if let Some(track) = tracks.get(cursor.min(len.saturating_sub(1))) {
|
||||
match crate::share::track_share_link(track) {
|
||||
None if track.is_podcast() => {
|
||||
state.status_message =
|
||||
Some("podcast episodes have no track share link".into())
|
||||
}
|
||||
Some(link) => {
|
||||
state.popup = Some(Popup::FedCopyText {
|
||||
title: "Track share link".into(),
|
||||
@@ -1155,7 +1174,7 @@ fn handle_track_info(
|
||||
cursor,
|
||||
scroll,
|
||||
});
|
||||
} else if track.id < 0 || track.file_path.is_empty() {
|
||||
} else if track.is_podcast() || track.id < 0 || track.file_path.is_empty() {
|
||||
state.status_message = Some("similarity search starts from a local track".into());
|
||||
state.popup = Some(Popup::TrackInfo {
|
||||
tracks,
|
||||
|
||||
+20
-2
@@ -1400,7 +1400,7 @@ impl SimilaritySearchHit {
|
||||
Self::Local { track, .. } => track
|
||||
.content_id
|
||||
.clone()
|
||||
.unwrap_or_else(|| format!("local:{}", track.id)),
|
||||
.unwrap_or_else(|| track.key().to_string()),
|
||||
Self::Federated { track, .. } => track
|
||||
.content_id
|
||||
.clone()
|
||||
@@ -2382,7 +2382,13 @@ fn fed_release_slot_availability(
|
||||
}
|
||||
}
|
||||
|
||||
/// Audio content id of a music track (library or federated). Podcast
|
||||
/// episodes have none: they are never content-addressed, resolved by hash
|
||||
/// or fetched from peers.
|
||||
pub fn track_content_id(track: &TrackItem) -> Option<String> {
|
||||
if track.is_podcast() {
|
||||
return None;
|
||||
}
|
||||
track
|
||||
.content_id
|
||||
.as_deref()
|
||||
@@ -2396,12 +2402,24 @@ pub fn track_content_id(track: &TrackItem) -> Option<String> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Identity of a queue item for matching it across queue edits, shuffle,
|
||||
/// resolution and playback state.
|
||||
///
|
||||
/// Podcast episodes are keyed by their episode id only (`ep:…`, from
|
||||
/// `TrackItem::key`): all of them share the sentinel numeric id, which must
|
||||
/// never identify anything. Music is keyed content-first (a pending
|
||||
/// federated item and its library copy are the same track), then by its
|
||||
/// federated source, then by `TrackItem::key` (`lib:<row id>` for library
|
||||
/// rows, `tmp:<id>` for process-local placeholders).
|
||||
pub fn track_key(track: &TrackItem) -> String {
|
||||
if track.is_podcast() {
|
||||
return track.key().to_string();
|
||||
}
|
||||
if let Some(content_id) = track_content_id(track) {
|
||||
return format!("content:{content_id}");
|
||||
}
|
||||
if let Some(fed) = &track.fed {
|
||||
return format!("fed:{}:{}", fed.owner, fed.item_id);
|
||||
}
|
||||
format!("local:{}", track.id)
|
||||
track.key().to_string()
|
||||
}
|
||||
+60
-4
@@ -386,7 +386,14 @@ pub fn update(state: &mut AppState, action: Action) -> Option<Effect> {
|
||||
let mut local_tracks: Vec<TrackItem> = Vec::new();
|
||||
let mut fed_tracks: Vec<crate::federation::FedTrack> = Vec::new();
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
let mut episodes = 0usize;
|
||||
for track in tracks {
|
||||
// Likes are music library state; episodes have their own
|
||||
// "played" progress instead.
|
||||
if track.is_podcast() {
|
||||
episodes += 1;
|
||||
continue;
|
||||
}
|
||||
if !seen.insert(track_key(&track)) {
|
||||
continue;
|
||||
}
|
||||
@@ -399,7 +406,11 @@ pub fn update(state: &mut AppState, action: Action) -> Option<Effect> {
|
||||
}
|
||||
}
|
||||
if local_tracks.is_empty() && fed_tracks.is_empty() {
|
||||
state.status_message = Some("no track selected".into());
|
||||
state.status_message = Some(if episodes > 0 {
|
||||
PODCAST_NOT_MUSIC.into()
|
||||
} else {
|
||||
"no track selected".into()
|
||||
});
|
||||
None
|
||||
} else {
|
||||
let should_like = local_tracks.iter().any(|track| !state.track_liked(track))
|
||||
@@ -445,6 +456,9 @@ pub fn update(state: &mut AppState, action: Action) -> Option<Effect> {
|
||||
Action::GoToRelease => {
|
||||
let track = selected_track(state).or_else(|| state.player.current.clone());
|
||||
match track {
|
||||
Some(track) if track.is_podcast() => {
|
||||
return podcasts::reveal_episode_podcast(state, &track);
|
||||
}
|
||||
Some(track) => open_release_for_track(state, &track),
|
||||
None => state.status_message = Some("no track selected".into()),
|
||||
}
|
||||
@@ -452,12 +466,17 @@ pub fn update(state: &mut AppState, action: Action) -> Option<Effect> {
|
||||
}
|
||||
Action::AddToPlaylist => {
|
||||
let target = selected_playlist_target(state, true);
|
||||
let target = without_podcast_episodes(state, target);
|
||||
match target {
|
||||
Some(target) => {
|
||||
state.popup = Some(super::state::Popup::AddToPlaylist { target, cursor: 0 });
|
||||
state.track_selection.clear();
|
||||
}
|
||||
None => state.status_message = Some("no track selected".into()),
|
||||
None => {
|
||||
state
|
||||
.status_message
|
||||
.get_or_insert_with(|| "no track selected".into());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -476,7 +495,8 @@ pub fn update(state: &mut AppState, action: Action) -> Option<Effect> {
|
||||
}
|
||||
}
|
||||
Action::NewPlaylist => {
|
||||
let for_target = selected_playlist_target(state, false);
|
||||
let for_target =
|
||||
without_podcast_episodes(state, selected_playlist_target(state, false));
|
||||
state.popup = Some(super::state::Popup::NewPlaylist {
|
||||
for_target,
|
||||
input: crate::app::input::LineEdit::default(),
|
||||
@@ -537,7 +557,9 @@ fn current_track_for_info(state: &AppState) -> Option<TrackItem> {
|
||||
queued_at_position
|
||||
.filter(|queued| {
|
||||
super::state::track_key(queued) == current_key
|
||||
|| queued.id == current.id
|
||||
// Podcast episodes share the sentinel id; only their key
|
||||
// identifies them.
|
||||
|| (!current.is_podcast() && !queued.is_podcast() && queued.id == current.id)
|
||||
|| current.is_fed_pending()
|
||||
})
|
||||
.or_else(|| {
|
||||
@@ -590,6 +612,36 @@ fn open_track_info(
|
||||
}
|
||||
}
|
||||
|
||||
/// Status text when a music-only action meets a podcast episode.
|
||||
pub const PODCAST_NOT_MUSIC: &str =
|
||||
"podcast episodes are not music: likes, playlists and library actions do not apply";
|
||||
|
||||
/// Playlists hold music only: drops podcast episodes from a local target
|
||||
/// (and says so when nothing is left).
|
||||
fn without_podcast_episodes(
|
||||
state: &mut AppState,
|
||||
target: Option<super::state::PlaylistAddTarget>,
|
||||
) -> Option<super::state::PlaylistAddTarget> {
|
||||
use super::state::PlaylistAddTarget;
|
||||
match target {
|
||||
Some(PlaylistAddTarget::Local(tracks)) => {
|
||||
let total = tracks.len();
|
||||
let music: Vec<TrackItem> = tracks
|
||||
.into_iter()
|
||||
.filter(|track| !track.is_podcast())
|
||||
.collect();
|
||||
if music.is_empty() {
|
||||
if total > 0 {
|
||||
state.status_message = Some(PODCAST_NOT_MUSIC.into());
|
||||
}
|
||||
return None;
|
||||
}
|
||||
Some(PlaylistAddTarget::Local(music))
|
||||
}
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
fn selected_playlist_target(
|
||||
state: &AppState,
|
||||
include_current: bool,
|
||||
@@ -677,6 +729,10 @@ fn open_edit_popup(state: &mut AppState) {
|
||||
return;
|
||||
}
|
||||
if let Some(track) = selected_track(state).or_else(|| state.player.current.clone()) {
|
||||
if track.is_podcast() {
|
||||
state.status_message = Some("podcast details come from the RSS feed".into());
|
||||
return;
|
||||
}
|
||||
state.popup = Some(track_edit_popup(&track));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::app::action::Action;
|
||||
use crate::app::input::LineEdit;
|
||||
use crate::app::state::{
|
||||
AppState, EpisodeList, FedInputField, Loadable, OpenedPodcast, PODCAST_ACTION_ROWS,
|
||||
PODCAST_EPISODE_PAGE, PodcastListRow, PodcastRow, PodcastStoreStatus, Popup, SeasonRow,
|
||||
PODCAST_EPISODE_PAGE, PodcastListRow, PodcastRow, PodcastStoreStatus, Popup, SeasonRow, Tab,
|
||||
};
|
||||
use crate::podcasts::refresh::{RefreshReport, SubscribeReport};
|
||||
|
||||
@@ -184,6 +184,51 @@ fn open_podcast(state: &mut AppState, index: usize) -> Option<Effect> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Shift-J (or the info popup's artist jump) on a podcast episode: opens its
|
||||
/// podcast on the Podcasts tab instead of a music release or artist.
|
||||
pub fn reveal_episode_podcast(
|
||||
state: &mut AppState,
|
||||
track: &crate::library::models::TrackItem,
|
||||
) -> Option<Effect> {
|
||||
let episode = track.podcast_episode_ref()?;
|
||||
let podcast_id = episode.podcast_id.clone();
|
||||
let title = episode.podcast_title.clone();
|
||||
state.active_tab = Tab::Podcasts;
|
||||
state.help_visible = false;
|
||||
state.track_selection.clear();
|
||||
state.jump_origin = None;
|
||||
if !store_ready(state) {
|
||||
return None;
|
||||
}
|
||||
if state
|
||||
.podcasts
|
||||
.opened
|
||||
.as_ref()
|
||||
.is_some_and(|opened| opened.podcast_id == podcast_id)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
close(state);
|
||||
match state
|
||||
.podcasts
|
||||
.podcasts()
|
||||
.iter()
|
||||
.position(|row| *row.id() == podcast_id)
|
||||
{
|
||||
Some(index) => {
|
||||
state.podcasts.selected = index + PODCAST_ACTION_ROWS;
|
||||
open_podcast(state, index)
|
||||
}
|
||||
None => {
|
||||
state.status_message = Some(format!(
|
||||
"podcasts: {} is not subscribed on this device",
|
||||
display_title(&title)
|
||||
));
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Esc: episodes -> seasons (when the podcast has them) -> podcast list.
|
||||
fn back(state: &mut AppState) {
|
||||
let tab = &mut state.podcasts;
|
||||
|
||||
@@ -1835,3 +1835,186 @@ mod podcast_tab {
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Podcast episodes in the shared queue: identity by episode id (never the
|
||||
/// shared sentinel id) and music-only actions that must skip them.
|
||||
mod podcast_queue {
|
||||
use super::*;
|
||||
use crate::app::podcast_fixtures::{self as fx, episode_track};
|
||||
use crate::app::state::{PODCAST_ACTION_ROWS, Popup, RepeatMode, track_content_id};
|
||||
use crate::app::update::PODCAST_NOT_MUSIC;
|
||||
|
||||
fn keys(queue: &[TrackItem]) -> Vec<String> {
|
||||
queue.iter().map(track_key).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn episodes_are_keyed_by_episode_id_not_by_the_sentinel_id() {
|
||||
let (one, two) = (episode_track(1), episode_track(2));
|
||||
assert_eq!(one.id, TrackItem::NOT_A_LIBRARY_ROW);
|
||||
assert_eq!(one.id, two.id);
|
||||
assert!(track_key(&one).starts_with("ep:ep1"), "{}", track_key(&one));
|
||||
assert_ne!(track_key(&one), track_key(&two));
|
||||
assert_eq!(track_key(&one), track_key(&episode_track(1)));
|
||||
// Music keeps its content-first key; a library row without a
|
||||
// content id is keyed by its row, never as `local:` / an episode.
|
||||
assert!(track_key(&test_track(5)).starts_with("content:"));
|
||||
let mut bare = test_track(5);
|
||||
bare.content_id = None;
|
||||
assert_eq!(track_key(&bare), "lib:5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_an_episode_keeps_the_other_episode_current() {
|
||||
let mut state = AppState::default();
|
||||
state.player.queue = vec![episode_track(1), test_track(7), episode_track(2)];
|
||||
state.player.queue_pos = 2;
|
||||
state.player.current = Some(episode_track(2));
|
||||
state.player.playing = true;
|
||||
state.active_tab = Tab::Queue;
|
||||
state.queue_tab.cursor = 0;
|
||||
let effect = update(&mut state, Action::RemoveFromQueue);
|
||||
assert_eq!(
|
||||
effect,
|
||||
Some(Effect::RemoveQueueIndices {
|
||||
indices: vec![0],
|
||||
restart_paused: None,
|
||||
stop: false,
|
||||
})
|
||||
);
|
||||
assert_eq!(state.player.queue_pos, 1);
|
||||
assert_eq!(
|
||||
state.player.current.as_ref().map(track_key),
|
||||
Some(track_key(&episode_track(2)))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_the_playing_episode_moves_to_the_next_item_not_another_episode() {
|
||||
let mut state = AppState::default();
|
||||
state.player.queue = vec![episode_track(1), episode_track(2), test_track(7)];
|
||||
state.player.queue_pos = 0;
|
||||
state.player.current = Some(episode_track(1));
|
||||
state.player.playing = true;
|
||||
state.active_tab = Tab::Queue;
|
||||
state.queue_tab.cursor = 0;
|
||||
let effect = update(&mut state, Action::RemoveFromQueue);
|
||||
assert!(matches!(
|
||||
effect,
|
||||
Some(Effect::RemoveQueueIndices {
|
||||
restart_paused: Some(false),
|
||||
..
|
||||
})
|
||||
));
|
||||
assert_eq!(
|
||||
state.player.current.as_ref().map(track_key),
|
||||
Some(track_key(&episode_track(2)))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shuffle_and_repeat_keep_a_mixed_queue_intact() {
|
||||
let mut state = AppState::default();
|
||||
let queue = vec![
|
||||
test_track(1),
|
||||
episode_track(1),
|
||||
episode_track(2),
|
||||
test_track(2),
|
||||
episode_track(3),
|
||||
test_track(3),
|
||||
];
|
||||
let original = keys(&queue);
|
||||
state.player.queue = queue;
|
||||
state.player.current = Some(test_track(1));
|
||||
state.player.playing = true;
|
||||
for _ in 0..8 {
|
||||
update(&mut state, Action::ToggleShuffle);
|
||||
let mut shuffled = keys(&state.player.queue);
|
||||
shuffled.sort();
|
||||
let mut expected = original.clone();
|
||||
expected.sort();
|
||||
assert_eq!(shuffled, expected, "no item lost or duplicated");
|
||||
update(&mut state, Action::ToggleShuffle);
|
||||
assert_eq!(keys(&state.player.queue), original);
|
||||
}
|
||||
// Next/previous step through episodes like any other item, and
|
||||
// repeat-all wraps around.
|
||||
state.player.repeat = RepeatMode::All;
|
||||
state.player.queue_pos = 4;
|
||||
state.player.current = Some(episode_track(3));
|
||||
assert_eq!(
|
||||
update(&mut state, Action::NextTrack),
|
||||
Some(Effect::PlayCurrent)
|
||||
);
|
||||
assert_eq!(state.player.queue_pos, 5);
|
||||
assert_eq!(
|
||||
update(&mut state, Action::NextTrack),
|
||||
Some(Effect::PlayCurrent)
|
||||
);
|
||||
assert_eq!(state.player.queue_pos, 0);
|
||||
assert_eq!(
|
||||
update(&mut state, Action::PrevTrack),
|
||||
Some(Effect::PlayCurrent)
|
||||
);
|
||||
assert_eq!(state.player.queue_pos, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn current_track_info_finds_the_playing_episode_among_episodes() {
|
||||
let mut state = AppState::default();
|
||||
state.player.queue = vec![episode_track(1), episode_track(2)];
|
||||
// The queue position points at another episode (same sentinel id).
|
||||
state.player.queue_pos = 0;
|
||||
state.player.current = Some(episode_track(2));
|
||||
state.player.playing = true;
|
||||
update(&mut state, Action::OpenCurrentTrackInfo);
|
||||
let Some(Popup::TrackInfo { tracks, .. }) = &state.popup else {
|
||||
panic!("track info expected");
|
||||
};
|
||||
assert_eq!(track_key(&tracks[0]), track_key(&episode_track(2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn music_only_actions_skip_episodes() {
|
||||
let mut state = fx::ready_state(vec![fx::row("Show", 1, 2, 0)]);
|
||||
state.active_tab = Tab::Queue;
|
||||
state.player.queue = vec![episode_track(1)];
|
||||
state.player.current = Some(episode_track(1));
|
||||
state.player.playing = true;
|
||||
|
||||
assert_eq!(update(&mut state, Action::ToggleLike), None);
|
||||
assert_eq!(state.status_message.as_deref(), Some(PODCAST_NOT_MUSIC));
|
||||
assert_eq!(update(&mut state, Action::AddToPlaylist), None);
|
||||
assert!(state.popup.is_none());
|
||||
assert_eq!(state.status_message.as_deref(), Some(PODCAST_NOT_MUSIC));
|
||||
update(&mut state, Action::NewPlaylist);
|
||||
assert!(matches!(
|
||||
state.popup.take(),
|
||||
Some(Popup::NewPlaylist {
|
||||
for_target: None,
|
||||
..
|
||||
})
|
||||
));
|
||||
update(&mut state, Action::EditSelected);
|
||||
assert!(state.popup.is_none(), "episode metadata is not editable");
|
||||
assert_eq!(update(&mut state, Action::DownloadSelected), None);
|
||||
|
||||
// No content id, no share link, no music history, private on the
|
||||
// v3 wire.
|
||||
let episode = episode_track(1);
|
||||
assert_eq!(track_content_id(&episode), None);
|
||||
assert_eq!(crate::share::track_content_id(&episode), None);
|
||||
assert_eq!(crate::share::track_share_link(&episode), None);
|
||||
let wire = crate::devices::PlaybackTrack::from_track(&episode);
|
||||
assert_eq!(wire.title, music_dht::device_sync::PRIVATE_ITEM_TITLE);
|
||||
assert!(wire.artist_names.is_empty() && wire.release_title.is_empty());
|
||||
assert_eq!((wire.id, wire.content_id, wire.fed), (0, None, None));
|
||||
|
||||
// Shift-J opens the podcast instead of a music release.
|
||||
let effect = update(&mut state, Action::GoToRelease);
|
||||
assert_eq!(state.active_tab, Tab::Podcasts);
|
||||
assert_eq!(state.podcasts.selected, PODCAST_ACTION_ROWS);
|
||||
assert!(state.podcasts.opened.is_some());
|
||||
assert!(matches!(effect, Some(Effect::PodcastLoadEpisodes { .. })));
|
||||
}
|
||||
}
|
||||
@@ -167,6 +167,9 @@ impl PlaybackTrack {
|
||||
}
|
||||
|
||||
pub fn from_track(track: &TrackItem) -> Self {
|
||||
if track.is_podcast() {
|
||||
return Self::private_placeholder();
|
||||
}
|
||||
Self {
|
||||
id: track.id,
|
||||
title: track.title.clone(),
|
||||
@@ -201,6 +204,38 @@ impl PlaybackTrack {
|
||||
}
|
||||
}
|
||||
|
||||
/// What peers see in place of a podcast episode.
|
||||
///
|
||||
/// This wire version (protocol 3) has no typed item source, so an
|
||||
/// episode cannot be described without passing it off as music or
|
||||
/// leaking its private title and URL (to Jam guests in particular). It
|
||||
/// is sent as the shared "private item" placeholder instead: not
|
||||
/// playable, no identity. Typed podcast items for peers that support
|
||||
/// them come with sync protocol v4.
|
||||
pub fn private_placeholder() -> Self {
|
||||
Self {
|
||||
id: 0,
|
||||
title: music_dht::device_sync::PRIVATE_ITEM_TITLE.to_string(),
|
||||
track_number: None,
|
||||
disc_number: None,
|
||||
duration_seconds: 0.0,
|
||||
artist_names: Vec::new(),
|
||||
featured_artist_names: Vec::new(),
|
||||
release_id: 0,
|
||||
release_title: String::new(),
|
||||
release_year: None,
|
||||
file_path: String::new(),
|
||||
content_id: None,
|
||||
audio_format: None,
|
||||
audio_bitrate: None,
|
||||
audio_sample_rate: None,
|
||||
audio_bit_depth: None,
|
||||
file_size_bytes: None,
|
||||
play_count: 0,
|
||||
fed: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_track_item(&self) -> TrackItem {
|
||||
let refs = |names: &[String]| -> Vec<ArtistRef> {
|
||||
names
|
||||
@@ -1203,6 +1238,11 @@ impl DeviceSync {
|
||||
listened_ms: i64,
|
||||
ended_reason: music_dht::device_sync::ListenEndReason,
|
||||
) -> Option<ListenEvent> {
|
||||
// Music listening history only: episodes record podcast listening
|
||||
// sessions in the podcast store instead.
|
||||
if track.is_podcast() {
|
||||
return None;
|
||||
}
|
||||
let content_id = track
|
||||
.content_id
|
||||
.as_deref()
|
||||
|
||||
@@ -1070,3 +1070,19 @@ fn failed_podcast_actions_append_nothing() {
|
||||
assert!(result.is_err());
|
||||
assert!(logged_ops(&sync).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn podcast_episodes_never_enter_music_listening_history() {
|
||||
let sync = test_sync();
|
||||
let episode = crate::app::podcast_fixtures::episode_track(1);
|
||||
assert!(
|
||||
sync.listen_event_for_track(
|
||||
"listen-1".into(),
|
||||
&episode,
|
||||
1_000,
|
||||
120_000,
|
||||
music_dht::device_sync::ListenEndReason::Finished,
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
use crate::library::models::TrackItem;
|
||||
|
||||
/// Content id of a music track. Podcast episodes have none: they are not
|
||||
/// content-addressed and never shared as `frid://` track links.
|
||||
pub fn track_content_id(track: &TrackItem) -> Option<String> {
|
||||
if track.is_podcast() {
|
||||
return None;
|
||||
}
|
||||
track
|
||||
.fed
|
||||
.as_ref()
|
||||
@@ -14,6 +19,9 @@ pub fn track_can_share(track: &TrackItem) -> bool {
|
||||
}
|
||||
|
||||
pub fn track_share_link(track: &TrackItem) -> Option<String> {
|
||||
if track.is_podcast() {
|
||||
return None;
|
||||
}
|
||||
let content_id = track_content_id(track).or_else(|| {
|
||||
(!track.file_path.trim().is_empty())
|
||||
.then(|| crate::library::audio_content_id(&track.file_path))
|
||||
|
||||
Reference in new issue
Block a user