Skip to content

Commit

Permalink
Add basic playbar support for podcasts (Rigellute#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
sputnick1124 authored Sep 20, 2020
1 parent 81e357e commit 1998c78
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 32 deletions.
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tab_spaces=2
edition = "2018"
70 changes: 43 additions & 27 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,15 @@ impl App {
.as_millis()
+ u128::from(*progress_ms);

match item {
PlayingItem::Track(track) => {
if elapsed < u128::from(track.duration_ms) {
self.song_progress_ms = elapsed;
} else {
self.song_progress_ms = track.duration_ms.into();
}
}
PlayingItem::Episode(_episode) => {}
let duration_ms = match item {
PlayingItem::Track(track) => track.duration_ms,
PlayingItem::Episode(episode) => episode.duration_ms,
};

if elapsed < u128::from(duration_ms) {
self.song_progress_ms = elapsed;
} else {
self.song_progress_ms = duration_ms.into();
}
}
}
Expand All @@ -444,22 +444,20 @@ impl App {
item: Some(item), ..
}) = &self.current_playback_context
{
match item {
PlayingItem::Track(track) => {
let event = if track.duration_ms - self.song_progress_ms as u32
> self.user_config.behavior.seek_milliseconds
{
IoEvent::Seek(
self.song_progress_ms as u32 + self.user_config.behavior.seek_milliseconds,
)
} else {
IoEvent::NextTrack
};

self.dispatch(event);
}
PlayingItem::Episode(_episode) => {}
let duration_ms = match item {
PlayingItem::Track(track) => track.duration_ms,
PlayingItem::Episode(episode) => episode.duration_ms,
};

let event = if duration_ms - self.song_progress_ms as u32
> self.user_config.behavior.seek_milliseconds
{
IoEvent::Seek(self.song_progress_ms as u32 + self.user_config.behavior.seek_milliseconds)
} else {
IoEvent::NextTrack
};

self.dispatch(event);
}
}

Expand Down Expand Up @@ -606,7 +604,14 @@ impl App {
self.handle_error(anyhow!("failed to set clipboard content: {}", e));
}
}
PlayingItem::Episode(_episode) => {}
PlayingItem::Episode(episode) => {
if let Err(e) = clipboard.set_contents(format!(
"https://open.spotify.com/episode/{}",
episode.id.to_owned()
)) {
self.handle_error(anyhow!("failed to set clipboard content: {}", e));
}
}
}
}
}
Expand All @@ -630,7 +635,14 @@ impl App {
self.handle_error(anyhow!("failed to set clipboard content: {}", e));
}
}
PlayingItem::Episode(_episode) => {}
PlayingItem::Episode(episode) => {
if let Err(e) = clipboard.set_contents(format!(
"https://open.spotify.com/show/{}",
episode.show.id.to_owned()
)) {
self.handle_error(anyhow!("failed to set clipboard content: {}", e));
}
}
}
}
}
Expand Down Expand Up @@ -895,7 +907,11 @@ impl App {
self.dispatch(IoEvent::GetAudioAnalysis(uri));
self.push_navigation_stack(RouteId::Analysis, ActiveBlock::Analysis);
}
PlayingItem::Episode(_epidose) => {}
PlayingItem::Episode(_episode) => {
// No audio analysis available for podcast uris, so just default to the empty analysis
// view to avoid a 400 error code
self.push_navigation_stack(RouteId::Analysis, ActiveBlock::Analysis);
}
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rspotify::{
PlayingItem,
},
oauth2::{SpotifyClientCredentials, SpotifyOAuth, TokenInfo},
senum::{Country, RepeatState, SearchType},
senum::{AdditionalType, Country, RepeatState, SearchType},
util::get_token,
};
use serde_json::{map::Map, Value};
Expand Down Expand Up @@ -295,7 +295,13 @@ impl<'a> Network<'a> {
}

async fn get_current_playback(&mut self) {
let context = self.spotify.current_playback(None, None).await;
let context = self
.spotify
.current_playback(
None,
Some(vec![AdditionalType::Episode, AdditionalType::Track]),
)
.await;

if let Ok(Some(c)) = context {
let mut app = self.app.lock().await;
Expand All @@ -309,7 +315,7 @@ impl<'a> Network<'a> {
app.dispatch(IoEvent::CurrentUserSavedTracksContains(vec![track_id]));
};
}
PlayingItem::Episode(_episode) => {}
PlayingItem::Episode(_episode) => { /*should map this to following the podcast show*/ }
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub fn get_help_docs() -> Vec<Vec<&'static str>> {
vec!["Seek backwards 5 seconds", "<", "General"],
vec!["Seek forwards 5 seconds", ">", "General"],
vec!["Toggle shuffle", "<Ctrl+s>", "General"],
vec!["Copy url to currently playing song", "c", "General"],
vec!["Copy url to currently playing album", "C", "General"],
vec!["Copy url to currently playing song/episode", "c", "General"],
vec!["Copy url to currently playing album/show", "C", "General"],
vec!["Cycle repeat mode", "<Ctrl+r>", "General"],
vec![
"Move selection left",
Expand Down

0 comments on commit 1998c78

Please sign in to comment.