mirror of
https://github.com/Rigellute/spotify-tui.git
synced 2026-04-26 16:15:55 +03:00
[PR #921] [CLOSED] Added feature to fetch song lyrics #1091
Labels
No labels
bug
enhancement
good first issue
help wanted
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotify-tui#1091
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Rigellute/spotify-tui/pull/921
Author: @giorgioskij
Created: 12/2/2021
Status: ❌ Closed
Base:
master← Head:lyrics📝 Commits (7)
e7de1cfadd basic lyrics implementation8ba01f8first working implementatione47f526refactor and clean code7a2448fremove unnecessary stuff - mostly comments02f377bbugfix4b0c088removed every comment marking new featuresde9516aadded help entry for the new shortcut📊 Changes
11 files changed (+743 additions, -460 deletions)
View changed files
📝
Cargo.lock(+497 -460)📝
Cargo.toml(+1 -0)📝
src/app.rs(+4 -0)📝
src/handlers/common_key_events.rs(+3 -0)📝
src/handlers/empty.rs(+2 -0)➕
src/handlers/lyrics.rs(+96 -0)📝
src/handlers/mod.rs(+25 -0)📝
src/network.rs(+48 -0)📝
src/ui/help.rs(+5 -0)📝
src/ui/mod.rs(+58 -0)📝
src/user_config.rs(+4 -0)📄 Description
Support for fetching song lyrics
I've been using this great tool for a while, and I was curious whether it would be possible to add a section that displays the lyrics of the song that's currently playing, so I decided to implement it: even if it's not one of the most important missing features listed on the readme, I thought that it would have been a pretty nice addition to improve the overall experience for many users like me.
Approach to the implementation
My main concerns and goals about the implementation of this feature were:
Something to consider, and its solution.
Any API to fetch the lyrics is obviously not guaranteed to be available forever, and may interrupt its service at any time, just as Spotify could. Therefore, unless Spotify provides their personal API to fetch lyrics, this separation is unavoidable. What we can do to be prepared for any circumstance is to have an implementation that is easy to adapt and extend. Anything that is related or specific to the API we are currently using is contained in a single small function: to replace the api provider or just disable the lyrics service, it is only needed to modify that function.
How it works
The way to implement this that I found to be most cohesive and unobtrusive was to add a block just like the welcome, album or artist view, that integrates in the
navigation_stack. In this way, the shorcut (I opted for<ctrl+l>) brings up the new lyrics window, that can be scrolled with the usual keys. Just like a playlist, album, or artist section, it stays in view until a new window is opened, or untilqis pressed to go back in the stack.Final result
Lyrics found
Lyrics not found (in this case, it is an instrumental song)
Summary of the new code
In line with the principles defined previously, I did not change anything of the previously existing code. I am not an experienced Rust developer, but thanks to a perfectly robust and scalable implementation (for real, the quality of the code was amazing and very easy to understand and integrate!), I was able to add the new window by following the same exact patterns used for the other windows and sections, so basically I didn't write any new logic, I only extended what was already present.
What I added to project structure
send_lyrics_requestinsidenetwork.rs. Here, I send the http request, parse the received json, and return anOption<String>with the fetched lyrics. This could have been done in a separate module kept in a separate file, but I thought that in this case, since it is only a single function, it is probably better to avoid introducing unnecessary complications.ureq, which was obviously needed to perform the http request.lyrics.rscontaining the handler for the lyrics component.I hope you find this contribution useful, once again thanks a lot for bringing to life this great project. I sure had a lot of fun putting my hands on it! As i said, I am not very experienced with Rust, so I am definitely willing to put some time in to adjust the implementation in any way you think might be needed.
Giorgio
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.