Taiko2k / Tauon

The music player of today! :city_sunrise:
https://tauonmusicbox.rocks
GNU General Public License v3.0
1.75k stars 66 forks source link

[Question] Integrate with eww-bar? #683

Closed thyeun closed 2 years ago

thyeun commented 2 years ago

Sorry for asking a question here, it is doable Tauon Music Box on eww-bar?

Based on the suggestion code by adi1090x, that done for mpc as below

#!/bin/bash
# scripts by adi1090x

## Get data
STATUS="$(mpc status)"
COVER="/tmp/.music_cover.png"
MUSIC_DIR="$HOME/Music"

## Get status
get_status() {
    if [[ $STATUS == *"[playing]"* ]]; then
        echo ""
    else
        echo "奈"
    fi
}

## Get song
get_song() {
    song=`mpc -f %title% current`
    if [[ -z "$song" ]]; then
        echo "Offline"
    else
        echo "$song"
    fi  
}

## Get artist
get_artist() {
    artist=`mpc -f %artist% current`
    if [[ -z "$artist" ]]; then
        echo ""
    else
        echo "$artist"
    fi  
}

## Get time
get_time() {
    time=`mpc status | grep "%)" | awk '{print $4}' | tr -d '(%)'`
    if [[ -z "$time" ]]; then
        echo "0"
    else
        echo "$time"
    fi  
}
get_ctime() {
    ctime=`mpc status | grep "#" | awk '{print $3}' | sed 's|/.*||g'`
    if [[ -z "$ctime" ]]; then
        echo "0:00"
    else
        echo "$ctime"
    fi  
}
get_ttime() {
    ttime=`mpc -f %time% current`
    if [[ -z "$ttime" ]]; then
        echo "0:00"
    else
        echo "$ttime"
    fi  
}

## Get cover
get_cover() {
    ffmpeg -i "${MUSIC_DIR}/$(mpc current -f %file%)" "${COVER}" -y &> /dev/null
    STATUS=$?

    # Check if the file has a embbeded album art
    if [ "$STATUS" -eq 0 ];then
        echo "$COVER"
    else
        echo "images/music.png"
    fi
}

## Execute accordingly
if [[ "$1" == "--song" ]]; then
    get_song
elif [[ "$1" == "--artist" ]]; then
    get_artist
elif [[ "$1" == "--status" ]]; then
    get_status
elif [[ "$1" == "--time" ]]; then
    get_time
elif [[ "$1" == "--ctime" ]]; then
    get_ctime
elif [[ "$1" == "--ttime" ]]; then
    get_ttime
elif [[ "$1" == "--cover" ]]; then
    get_cover
elif [[ "$1" == "--toggle" ]]; then
    mpc -q toggle
elif [[ "$1" == "--next" ]]; then
    { mpc -q next; get_cover; }
elif [[ "$1" == "--prev" ]]; then
    { mpc -q prev; get_cover; }
fi
zkrising commented 2 years ago

Tauon supports MPRIS (https://wiki.archlinux.org/title/MPRIS).

You can use a tool like playerctl to get easily get information about tauon, the easiest thing to do (imo) is to replace the mpd calls with playerctl equivalents.

thyeun commented 2 years ago

@zkldi ok, thanks!!! will try it out

Taiko2k commented 2 years ago

Yep. playerctl will be the way.

You'll just have to edit that script to use that instead. For the cover art is a bit easier than what's there, just use playerctl metadata mpris:artUrl, you'll just need to convert the URI to a path if that app doesn't support URI's.

thyeun commented 2 years ago

Done successfully, but can i ask, possible run Tauon at the background, as like i play the first song than only Tauon appear on screen?

Taiko2k commented 2 years ago

Done successfully, but can i ask, possible run Tauon at the background, as like i play the first song than only Tauon appear on screen?

Can you rephrase that?

thyeun commented 2 years ago

As you can see my eww-bar, the music icon are inactive, and no song are playing

Screenshot_2022-02-15-02-25-26_1366x768

As what i want is, let Tauon always running at the background on the system, but when i press play something (mean i start playing a song), it will open up Tauon Music Box

A bit hard to said in words here :(

Taiko2k commented 2 years ago

Okay I think I see what you mean, you want it to show the window on demand? I don't think playerctl supports this, but you can use dbus directly using:

dbus-send --session --type=method_call --dest=org.mpris.MediaPlayer2.tauon /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Raise

Though, there is a bug in Tauon currently causing this to not work properly. I've committed a fix but its not in a release version yet.

Note that some desktop environments like GNOME don't allow apps to self raise themselves regardless. You could work around that by enabling "show in system tray" and "close to tray" in Tauon (Menu > Settings > Function > Page 3)

thyeun commented 2 years ago

@Taiko2k the dbus way is same like polybar using the MPRIS python file?

if yes, i think i can try it out, been try it on polybar before i change to eww-bar.

Taiko2k commented 2 years ago

the dbus way is same like polybar using the MPRIS python file?

dbus-send is just a program you can use in place of playerctl.

thyeun commented 2 years ago

Cant make it work, not well understand how dbus-send done things

Taiko2k commented 2 years ago

Basically you would run that command first to raise the window, then the playerctl command. If you have dbus-send then it should work, try it in a terminal:

dbus-send --session --print-reply --type=method_call --dest=org.mpris.MediaPlayer2.tauon /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Raise

thyeun commented 2 years ago

Yes, i trying using the command from yours, but getting below error

Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.mpris.MediaPlayer2.tauon was not provided by any .service files

Will try it later on

Taiko2k commented 2 years ago

Tauon will need to be running for that to work

thyeun commented 2 years ago

i understand what you want to guide me on, but that not the way i prefer, hahahaha

Very hard to explain how i prefer.

Do you using Microsoft Teams (linux), when you close the team, the process of Teams still running at the background, once there are someone contact/chat with you, you will get an alert notice, and once you click on that notice, Teams will appear again.

So, when i close Tauon, Tauon still will running at the background (mean you wont see Taoun in my workspace), but it will appear back when i click play on the eww-bar and play the song immediately.

Taiko2k commented 2 years ago

So, when i close Tauon, Tauon still will running at the background

You can enable the "tray" option with min to tray enabled as mentioned before for that kind of behavior.

appear back when i click play on the eww-bar and play the song immediately.

You'd have to do it the way I mentioned, use that dbus command to reveal the window (working in tauon master, not release version yet), then use playerctl to play.

thyeun commented 2 years ago

@Taiko2k i know why i fail, the close to tray once i login and logout, it will back to original, and because of that, once i raise back using the dbus-send, Tauon wont appear because no service, if the Tauon service detected, i will get the below message from terminal

method return time=1644922170.413366 sender=:1.30 -> destination=:1.316 serial=279 reply_serial=2

You can try reproduce the system tray with login and logout error, see you face the same error or not. Tauon version : 7.1.0 Original: Screenshot_2022-02-15-06-47-25_1366x768

Taiko2k commented 2 years ago

Well its not an error, tauon wont start on login by itself. But you could add it to your startup applications manually yourself. You can have it start in the background by running tauon --tray.

thyeun commented 2 years ago

Ok, than everything perfect now, thank you so much.

And waiting your latest release also :)