Skip to content

Commit 7abf1b3

Browse files
authored
add support for synced lyrics (#635)
1 parent 68824ac commit 7abf1b3

File tree

23 files changed

+239
-232
lines changed

23 files changed

+239
-232
lines changed

.dir-locals.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
;;; For more information see (info "(emacs) Directory Variables")
33

44
((rustic-mode . ((eglot-workspace-configuration
5-
. (:rust-analyzer (:cargo (:features ["lyric-finder" "image" "notify"])
5+
. (:rust-analyzer (:cargo (:features ["image" "notify"])
66
:check (:command "clippy")))))))

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
env:
1010
CARGO_TERM_COLOR: always
1111
RUST_BACKTRACE: 1
12-
RUST_FEATURES: "rodio-backend,lyric-finder,media-control,image,notify"
12+
RUST_FEATURES: "rodio-backend,media-control,image,notify"
1313

1414
jobs:
1515
rust-ci:

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM rust as builder
22
WORKDIR app
33
COPY . .
4-
RUN cargo build --release --bin spotify_player --no-default-features --features lyric-finder
4+
RUN cargo build --release --bin spotify_player --no-default-features
55

66
FROM gcr.io/distroless/cc
77
# Create `./config` and `./cache` folders using WORKDIR commands.

README.md

Lines changed: 58 additions & 71 deletions
Large diffs are not rendered by default.

docs/config.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ To define application's component styles, the user can specify any of the below
231231
- `selection`
232232
- `secondary_row`
233233
- `like`
234+
- `lyrics_played`
234235

235236
A field in `component_style` is a struct with three **optional** fields: `fg` (foreground), `bg` (background) and `modifiers` (terminal effects):
236237

@@ -261,7 +262,9 @@ current_playing = { fg = "Green", modifiers = ["Bold"] }
261262
page_desc = { fg = "Cyan", modifiers = ["Bold"] }
262263
playlist_desc = { fg = "BrightBlack", modifiers = ["Dim"] }
263264
table_header = { fg = "Blue" }
264-
selection = { modifiers = ["Bold", "Reversed"] }
265+
secondary_row = {}
266+
like = {]
267+
lyrics_played = { modifiers = ["Dim"] }
265268
```
266269

267270
## Keymaps

examples/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
![Search page example](https://user-images.githubusercontent.com/40011582/140253653-5b156a8f-538b-4e68-9d52-0a379477574f.png)
2222

23-
## Lyric page
23+
## Lyrics page
2424

25-
![Lyric page example](https://user-images.githubusercontent.com/40011582/169437044-420cf0e2-5d75-4022-bd9f-34540f1fe230.png)
25+
![Lyrics page example](https://user-images.githubusercontent.com/40011582/169437044-420cf0e2-5d75-4022-bd9f-34540f1fe230.png)
2626

2727
## Command help popup
2828

spotify_player/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ librespot-connect = { version = "0.6.0", optional = true }
1919
librespot-core = "0.6.0"
2020
librespot-oauth = "0.6.0"
2121
librespot-playback = { version = "0.6.0", optional = true }
22+
librespot-metadata = "0.6.0"
2223
log = "0.4.22"
2324
chrono = "0.4.38"
2425
reqwest = { version = "0.12.9", features = ["json"] }
@@ -38,7 +39,6 @@ async-trait = "0.1.83"
3839
parking_lot = "0.12.3"
3940
tracing = "0.1.41"
4041
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
41-
lyric_finder = { version = "0.1.8", path = "../lyric_finder", optional = true }
4242
backtrace = "0.3.74"
4343
souvlaki = { version = "0.7.3", optional = true }
4444
viuer = { version = "0.9.1", optional = true }
@@ -85,7 +85,6 @@ rodiojack-backend = ["streaming", "librespot-playback/rodiojack-backend"]
8585
sdl-backend = ["streaming", "librespot-playback/sdl-backend"]
8686
gstreamer-backend = ["streaming", "librespot-playback/gstreamer-backend"]
8787
streaming = ["librespot-playback", "librespot-connect"]
88-
lyric-finder = ["lyric_finder"]
8988
media-control = ["souvlaki", "winit", "windows"]
9089
image = ["viuer", "dep:image"]
9190
sixel = ["image", "viuer/sixel"]

spotify_player/src/cli/handlers.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ fn get_id_or_name(args: &ArgMatches) -> IdOrName {
4646
}
4747
}
4848

49-
#[allow(clippy::unnecessary_wraps)] // we need this to match the other functions return type
50-
fn handle_get_subcommand(args: &ArgMatches) -> Result<Request> {
49+
fn handle_get_subcommand(args: &ArgMatches) -> Request {
5150
let (cmd, args) = args.subcommand().expect("playback subcommand is required");
5251

5352
let request = match cmd {
@@ -69,7 +68,7 @@ fn handle_get_subcommand(args: &ArgMatches) -> Result<Request> {
6968
_ => unreachable!(),
7069
};
7170

72-
Ok(request)
71+
request
7372
}
7473

7574
fn handle_playback_subcommand(args: &ArgMatches) -> Result<Request> {
@@ -202,7 +201,7 @@ pub fn handle_cli_subcommand(cmd: &str, args: &ArgMatches) -> Result<()> {
202201

203202
// construct a socket request based on the CLI command and its arguments
204203
let request = match cmd {
205-
"get" => handle_get_subcommand(args)?,
204+
"get" => handle_get_subcommand(args),
206205
"playback" => handle_playback_subcommand(args)?,
207206
"playlist" => handle_playlist_subcommand(args)?,
208207
"connect" => Request::Connect(get_id_or_name(args)),

spotify_player/src/client/handlers.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use anyhow::Context;
2+
use rspotify::model::Id;
23
use tracing::Instrument;
34

45
use crate::{
56
config,
67
state::{ContextId, ContextPageType, ContextPageUIState, PageState, PlayableId, SharedState},
78
};
89

9-
#[cfg(feature = "lyric-finder")]
1010
use crate::utils::map_join;
1111

1212
use super::ClientRequest;
@@ -167,25 +167,24 @@ fn handle_page_change_event(
167167
}
168168
}
169169

170-
#[cfg(feature = "lyric-finder")]
171-
PageState::Lyric {
170+
PageState::Lyrics {
171+
track_uri,
172172
track,
173173
artists,
174-
scroll_offset,
175174
} => {
176175
if let Some(rspotify::model::PlayableItem::Track(current_track)) =
177176
state.player.read().currently_playing()
178177
{
179178
if current_track.name != *track {
180-
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);
181-
track.clone_from(&current_track.name);
182-
*artists = map_join(&current_track.artists, |a| &a.name, ", ");
183-
*scroll_offset = 0;
184-
185-
client_pub.send(ClientRequest::GetLyric {
186-
track: track.clone(),
187-
artists: artists.clone(),
188-
})?;
179+
if let Some(id) = &current_track.id {
180+
tracing::info!("Currently playing track \"{}\" is different from the track \"{track}\" shown up in the lyrics page. Fetching new track's lyrics...", current_track.name);
181+
track.clone_from(&current_track.name);
182+
*artists = map_join(&current_track.artists, |a| &a.name, ", ");
183+
*track_uri = id.uri();
184+
client_pub.send(ClientRequest::GetLyrics {
185+
track_id: id.clone_static(),
186+
})?;
187+
}
189188
}
190189
}
191190
}

0 commit comments

Comments
 (0)