tidal-hifi icon indicating copy to clipboard operation
tidal-hifi copied to clipboard

`favorite/toggle` endoint doesn't update internal state

Open dionorgua opened this issue 9 months ago • 5 comments

Hi,

When using /favorite/toggle endpoint first time (on not liked song) it makes it 'liked' (in UI). But /current API call still shows it as: "favorite": false

So next call to /favorite/toggle do nothing.

Note: that pause/play fixes it

dionorgua avatar Mar 21 '25 14:03 dionorgua

I am unable to reproduce this using the player/favorite/toggle event, it updates in both the UI and all media info sources.

Mastermindzh avatar Apr 22 '25 07:04 Mastermindzh

Hmm. Still happens for me on latest flatpak build (5.18.2)

curl http://localhost:47836/current | jq            
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   528  100   528    0     0   225k      0 --:--:-- --:--:-- --:--:--  257k
{
  "title": "Mr. Brownstone",
  "artists": "Guns N' Roses",
  "album": "",
  "icon": "/home/dion/.var/app/com.mastermindzh.tidal-hifi/config/tidal-hifi/notification.jpg",
  "playingFrom": "Bon Jovi",
  "status": "playing",
  "url": "https://tidal.com/browse/track/91059739?u",
  "current": "1:42",
  "currentInSeconds": 102,
  "duration": "3:49",
  "durationInSeconds": 229,
  "image": "https://resources.tidal.com/images/f301b83f/9dff/40a8/bcfd/4059a3459d1f/640x640.jpg",
  "favorite": false,
  "player": {
    "status": "playing",
    "shuffle": false,
    "repeat": "off"
  },
  "artist": "Guns N' Roses"
}

Now make it favorite:

% curl -X POST http://localhost:47836/favorite/toggle
OK%                                                                                                                                                                                                                                                                                 

UI shows it as favorite now.

But here it's still false:

% curl http://localhost:47836/current | jq           
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   528  100   528    0     0   346k      0 --:--:-- --:--:-- --:--:--  515k
{
  "title": "Mr. Brownstone",
  "artists": "Guns N' Roses",
  "album": "",
  "icon": "/home/dion/.var/app/com.mastermindzh.tidal-hifi/config/tidal-hifi/notification.jpg",
  "playingFrom": "Bon Jovi",
  "status": "playing",
  "url": "https://tidal.com/browse/track/91059739?u",
  "current": "2:00",
  "currentInSeconds": 120,
  "duration": "3:49",
  "durationInSeconds": 229,
  "image": "https://resources.tidal.com/images/f301b83f/9dff/40a8/bcfd/4059a3459d1f/640x640.jpg",
  "favorite": false,
  "player": {
    "status": "playing",
    "shuffle": false,
    "repeat": "off"
  },
  "artist": "Guns N' Roses"
}

dionorgua avatar Apr 22 '25 10:04 dionorgua

Can you try player/favorite/toggle?

Mastermindzh avatar Apr 22 '25 10:04 Mastermindzh

It doesn't work. I've found another thing. it looks like it's not favorite/toggle issue. It's not updated in current even if I change favorite flag using UI. So

  1. Song is not 'favorite'
  2. curl http://localhost:47836/current | jq shows "favorite": false
  3. I click on 'heart' icon in UI. So song is now 'favorite'
  4. curl http://localhost:47836/current | jq still shows "favorite": false
  5. I click pause/play. Now current is updated and "favorite": true

Same thing happens when I decide to remove 'favorite' flag from song

dionorgua avatar Apr 22 '25 10:04 dionorgua

Ah, I reproduced it now. Idk what I was doing earlier when it worked.. probably one of the newer branches....

Updating straight from the UI is expected to not update immediately. The update function has the following logic:

const hasStateChanged = playStateChanged || shuffleStateChanged || repeatStateChanged;

It uses that to determine whether to update EVERYTHING or not. I'll have ot update it to include other values too.

Mastermindzh avatar Apr 22 '25 11:04 Mastermindzh

Thanks for all the posts here. i was able to make a script and bind it to keyboard shortcut to like/favorite a track. Sucks to have to pause/play to update the status a bit, but at the same time at least it tells (the brief pause and play) me that i actually liked without having to use notifications in my script (echo parts are just for seeing on terminal if i need a sanity check)

#!/bin/bash
# by xpander

API="http://127.0.0.1:47836"

# get current favorite status
fav=$(curl -s "$API/current" | jq .favorite)

# like the track only if not already liked
if [ "$fav" = "false" ]; then
    curl -s -X POST "$API/player/favorite/toggle" >/dev/null
    echo "Liked the current track!"
# trigger a quick pause/play to update /current
curl -s -X POST "$API/player/pause" >/dev/null
sleep 0.4
curl -s -X POST "$API/player/play" >/dev/null
else
    echo "Already liked"
fi

xpander69 avatar Nov 08 '25 11:11 xpander69