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

Spotify segment (linux) #4732

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

luisegarduno
Copy link

Prerequisites

  • I have read and understood the contributing guide.
  • The commit message follows the conventional commits guidelines.
  • Tests for the changes have been added (for bug fixes / features).
  • Docs have been added/updated (for bug fixes / features).

Description

The goal of this PR is to create a working segment that displays the song & artist currently playing on the Spotify application via Linux.

mytheme

I created a solution to fetch information from the Spotify application on Linux (Ubuntu) by using a bash segment to run a command. Having said this, the command is written directly in the theme file (see gist).

About 2 years ago, I forked oh-my-posh with the intention of converting the command into a proper segment, but never got around to getting it to work. Given my limited experience with go, I figured I should ask for help.

Regarding the solution itself, here is the command that retrieves the Spotify information:

$ dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata

The command shown above has been tested on several Ubuntu machines and has show to work consistently well. However, I am uncertain on the compatibility across other Linux distributions.

@JanDeDobbeleer
Copy link
Owner

Cool! This isn't a bad start. Allow me to review that somewhere this week.

Copy link
Owner

@JanDeDobbeleer JanDeDobbeleer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to also update the docs, and eventually probably add a source property too specifying dbus or something else (but that's not relevant now)

src/segments/spotify_linux.go Outdated Show resolved Hide resolved
@luisegarduno
Copy link
Author

I'm able to get the tests to pass locally, however when testing the binary, the spotify segment is not showing.

@JanDeDobbeleer
Copy link
Owner

I'm able to get the tests to pass locally, however when testing the binary, the spotify segment is not showing.

You can use oh-my-posh debug to show what’s going on.

@JanDeDobbeleer
Copy link
Owner

@luisegarduno any update?

@luisegarduno
Copy link
Author

Thanks for tip, oh-my-posh debug has been very helpful.

I've made some progress in my latest commit, having {{.Artist}} - {{.Track}} now work.

The workflow will not get far though, as I deleted spotify_wsl & spotify_wsl_test (locally) so that I could get spotify_linux to build - matching boolean function names "Enabled". I assume this may be an easy fix, as I just need to figure out a way to separate the builds for wsl & linux since //go:build wsl isn't a thing yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants