Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement podcast functionality #552

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ List of available actions:
- `DeleteFromPlaylist`
- `ShowActionsOnAlbum`
- `ShowActionsOnArtist`
- `ShowActionsOnShow`
- `ToggleLiked`
- `CopyLink`
- `Follow`
Expand Down
3 changes: 1 addition & 2 deletions spotify_player/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ log = "0.4.22"
chrono = "0.4.38"
reqwest = { version = "0.12.5", features = ["json"] }
rpassword = "7.3.1"
rspotify = "0.13.2"
rspotify = "0.13.3"
serde = { version = "1.0.204", features = ["derive"] }
tokio = { version = "1.38.0", features = ["rt", "rt-multi-thread", "macros", "time"] }
toml = "0.8.14"
Expand Down Expand Up @@ -89,4 +89,3 @@ default = ["rodio-backend", "media-control"]

[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/v{ version }/{ name }_{ target }{ archive-suffix }"

8 changes: 4 additions & 4 deletions spotify_player/src/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,27 +339,27 @@ async fn handle_playback_request(
let tracks = client.radio_tracks(sid.uri()).await?;

PlayerRequest::StartPlayback(
Playback::URIs(tracks.into_iter().map(|t| t.id).collect(), None),
Playback::URIs(tracks.into_iter().map(|t| t.id.into()).collect(), None),
None,
)
}
Command::StartLikedTracks { limit, random } => {
// get a list of liked tracks' ids
let mut ids: Vec<_> = if let Some(ref state) = state {
let mut ids: Vec<PlayableId> = if let Some(ref state) = state {
state
.data
.read()
.user_data
.saved_tracks
.values()
.map(|t| t.id.to_owned())
.map(|t| t.id.to_owned().into())
.collect()
} else {
client
.current_user_saved_tracks()
.await?
.into_iter()
.map(|t| t.id)
.map(|t| t.id.into())
.collect()
};

Expand Down
39 changes: 29 additions & 10 deletions spotify_player/src/client/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,41 @@ fn handle_playback_change_event(
handler_state: &mut PlayerEventHandlerState,
) -> anyhow::Result<()> {
let player = state.player.read();
let (playback, track) = match (
let (playback, id, name, duration) = match (
player.buffered_playback.as_ref(),
player.current_playing_track(),
player.currently_playing(),
) {
(Some(playback), Some(track)) => (playback, track),
(Some(playback), Some(PlayableItem::Track(track))) => (
playback,
PlayableId::Track(track.id.clone().expect("all non-local tracks have ids")),
track.name.clone(),
track.duration,
),
(Some(playback), Some(PlayableItem::Episode(episode))) => (
playback,
PlayableId::Episode(episode.id.clone()),
episode.name.clone(),
episode.duration,
),
_ => return Ok(()),
};

if let Some(progress) = player.playback_progress() {
// update the playback when the current track ends
if progress >= track.duration && playback.is_playing {
if progress >= duration && playback.is_playing {
client_pub.send(ClientRequest::GetCurrentPlayback)?;
}
}

if let Some(queue) = player.queue.as_ref() {
// queue needs to be updated if its playing track is different from actual playback's playing track
if let Some(PlayableItem::Track(queue_track)) = queue.currently_playing.as_ref() {
if queue_track.id != track.id {
if let Some(queue_track) = queue.currently_playing.as_ref() {
if queue_track
.id()
.expect("all non-local tracks have ids")
.uri()
!= id.uri()
{
client_pub.send(ClientRequest::GetCurrentUserQueue)?;
}
}
Expand All @@ -77,16 +93,16 @@ fn handle_playback_change_event(
if let Some(progress) = player.playback_progress() {
// re-queue the current track if it's about to end while
// ensuring that only one `AddTrackToQueue` request is made
if progress + chrono::TimeDelta::seconds(5) >= track.duration
if progress + chrono::TimeDelta::seconds(5) >= duration
&& playback.is_playing
&& handler_state.add_track_to_queue_req_timer.elapsed()
> std::time::Duration::from_secs(10)
{
tracing::info!(
"fake track repeat mode is enabled, add the current track ({}) to queue",
track.name
name
);
client_pub.send(ClientRequest::AddTrackToQueue(track.id.clone().unwrap()))?;
client_pub.send(ClientRequest::AddPlayableToQueue(id))?;
handler_state.add_track_to_queue_req_timer = std::time::Instant::now();
}
}
Expand Down Expand Up @@ -124,6 +140,7 @@ fn handle_page_change_event(
ContextId::Artist(_) => ContextPageUIState::new_artist(),
ContextId::Playlist(_) => ContextPageUIState::new_playlist(),
ContextId::Tracks(_) => ContextPageUIState::new_tracks(),
ContextId::Show(_) => ContextPageUIState::new_show(),
});
}
None => {
Expand All @@ -148,7 +165,9 @@ fn handle_page_change_event(
artists,
scroll_offset,
} => {
if let Some(current_track) = state.player.read().current_playing_track() {
if let Some(rspotify_model::PlayableItem::Track(current_track)) =
state.player.read().currently_playing()
{
if current_track.name != *track {
tracing::info!("Current playing track \"{}\" is different from the track \"{track}\" shown up in the lyric page. Updating the track and fetching its lyric...", current_track.name);
track.clone_from(&current_track.name);
Expand Down
Loading
Loading