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

[Feature Request] Add queue manipulation endpoints in the API #509

Open
andrea3x opened this issue Dec 1, 2024 · 2 comments
Open

[Feature Request] Add queue manipulation endpoints in the API #509

andrea3x opened this issue Dec 1, 2024 · 2 comments
Labels
enhancement New feature or request Investigation required Needs to be investigated by the assignee

Comments

@andrea3x
Copy link

andrea3x commented Dec 1, 2024

Reading in the API reference, I couldn't find any endpoints to manipulate the queue.

The most basic one I'd like to see in the TIDAL Hi-Fi API is adding a song to the play queue.
Spotify implemented it in this way, we could do something similar, for example:
/player/queue: adds to play queue the specified content, identified by an URI (or a link!)

Other endpoints could, for example:

  • remove elements from the queue
  • change the order of the songs
  • etc

I tried to implement the first endpoint but I wasn't able to reverse engineer the Tidal JS code, I'm still inexperienced!
Do you think it is possible to add these endpoints?
Thanks a lot!

@andrea3x
Copy link
Author

andrea3x commented Dec 2, 2024

Using the debugger I found out that the function associated to the click of the button Add to queue in Suggested tracks tab (the following one:)
image
is:

onAddToPlayQueue: t => {
  t.stopPropagation(),
  e(
    y.m6({
      mediaItemIds: [
        i
      ],
      position: 'last',
      sourceContext: {
        id: n ||
        null,
        type: o ||
        'UNKNOWN'
      }
    })
  )
},

I tried to call y.m6() in the console but, besides the fact that they are minimized names and therefore everything could break with the next update, y is not defined globally and so I wouldn't know how to refer to it.

Is anyone able to investigate better?
Thanks

@Mar0xy
Copy link
Contributor

Mar0xy commented Dec 2, 2024

The way all current API endpoints work is by using the HTML elements and not any actual JS from Tidal itself.

See:

tidal-hifi/src/preload.ts

Lines 315 to 344 in f4d4b1a

function addIPCEventListeners() {
window.addEventListener("DOMContentLoaded", () => {
ipcRenderer.on("globalEvent", (_event, args) => {
switch (args) {
case globalEvents.playPause:
case globalEvents.play:
case globalEvents.pause:
playPause();
break;
case globalEvents.next:
elements.click("next");
break;
case globalEvents.previous:
elements.click("previous");
break;
case globalEvents.toggleFavorite:
elements.click("favorite");
break;
case globalEvents.toggleShuffle:
elements.click("shuffle");
break;
case globalEvents.toggleRepeat:
elements.click("repeat");
break;
default:
break;
}
});
});
}

tidal-hifi/src/preload.ts

Lines 201 to 209 in f4d4b1a

function playPause() {
const play = elements.get("play");
if (play) {
elements.click("play");
} else {
elements.click("pause");
}
}

const elements = {
play: '*[data-test="play"]',
pause: '*[data-test="pause"]',
next: '*[data-test="next"]',
previous: 'button[data-test="previous"]',
title: '*[data-test^="footer-track-title"]',
artists: '*[data-test^="grid-item-detail-text-title-artist"]',
home: '*[data-test="menu--home"]',
back: '[title^="Back"]',
forward: '[title^="Next"]',
search: '[class^="searchField"]',
shuffle: '*[data-test="shuffle"]',
repeat: '*[data-test="repeat"]',
account: '*[data-test^="profile-image-button"]',
settings: '*[data-test^="sidebar-menu-button"]',
openSettings: '*[data-test^="open-settings"]',
media: '*[data-test="current-media-imagery"]',
image: "img",
current: '*[data-test="current-time"]',
duration: '*[class^=playbackControlsContainer] *[data-test="duration"]',
bar: '*[data-test="progress-bar"]',
footer: "#footerPlayer",
mediaItem: "[data-type='mediaItem']",
album_header_title: '*[class^="playingFrom"] span:nth-child(2)',
playing_from: '*[class^="playingFrom"] span:nth-child(2)',
queue_album: "*[class^=playQueueItemsContainer] *[class^=groupTitle] span:nth-child(2)",
currentlyPlaying: "[class^='isPlayingIcon'], [data-test-is-playing='true']",
album_name_cell: '[class^="album"]',
tracklist_row: '[data-test="tracklist-row"]',
volume: '*[data-test="volume"]',
favorite: '*[data-test="footer-favorite-button"]',

If we were to go off trying to add it via using HTML elements it would essentially be impossible.

@Mastermindzh Mastermindzh added enhancement New feature or request Investigation required Needs to be investigated by the assignee labels Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Investigation required Needs to be investigated by the assignee
Projects
None yet
Development

No branches or pull requests

3 participants