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

Get album name #88

Merged
merged 3 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const elements = {
duration: '*[data-test="duration-time"]',
bar: '*[data-test="progress-bar"]',
footer: "#footerPlayer",
album_header_title: '.header-details [data-test="title"]',
playing_title: 'span[data-test="table-cell-title"].css-geqnfr',
album_name_cell: '[data-test="table-cell-album"]',
tracklist_row: '[data-test="tracklist-row"]',

/**
* Get an element from the dom
Expand Down Expand Up @@ -77,6 +81,26 @@ const elements = {
return "unknown artist(s)";
},

getAlbumName: function () {
//If listening to an album, get its name from the header title
if(window.location.href.includes('/album/')) {
const albumName = window.document.querySelector(this.album_header_title);
if(albumName) {
Copy link
Owner

Choose a reason for hiding this comment

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

I take it that the url either includes album or playlist? Never both?
If so, please wrap the second if in an "elseif"

return albumName.textContent;
}
//If listening to a playlist or a mix, get album name from the list
} else if(window.location.href.includes('/playlist/') || window.location.href.includes('/mix/')) {
if(currentPlayStatus === statuses.playing) {
const row = window.document.querySelector(this.playing_title).closest(this.tracklist_row);
if(row) {
return row.querySelector(this.album_name_cell).textContent;
}
}
}

return "";
},

/**
* Shorthand function to get the text of a dom element
* @param {*} key key in elements object to fetch
Expand Down Expand Up @@ -258,6 +282,7 @@ function updateMediaInfo(options, notify) {
...{
"xesam:title": options.title,
"xesam:artist": [options.message],
"xesam:album": options.album,
"mpris:artUrl": options.image,
"mpris:length": convertDuration(options.duration) * 1000 * 1000,
},
Expand Down Expand Up @@ -290,6 +315,7 @@ function updateURL() {
setInterval(function () {
const title = elements.getText("title");
const artists = elements.getArtists();
const album = elements.getAlbumName();
const current = elements.getText("current");
const duration = elements.getText("duration");
const appName = "Tidal Hifi";
Expand All @@ -299,6 +325,7 @@ setInterval(function () {
const options = {
title,
message: artists,
album: album,
status: currentStatus,
url: currentURL,
current: current,
Expand Down
1 change: 1 addition & 0 deletions src/scripts/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const observer = (event, arg) => {
startTimestamp: parseInt(now),
endTimestamp: parseInt(remaining),
largeImageKey: mediaInfoModule.mediaInfo.image,
largeImageText: (mediaInfoModule.mediaInfo.album) ? mediaInfoModule.mediaInfo.album : `${idleStatus.largeImageText}`,
buttons: [{ label: "Play on Tidal", url: mediaInfoModule.mediaInfo.url }],
},
});
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/mediaInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const statuses = require("./../constants/statuses");
const mediaInfo = {
title: "",
artist: "",
album: "",
icon: "",
status: statuses.paused,
url: "",
Expand All @@ -20,6 +21,7 @@ const mediaInfoModule = {
mediaInfoModule.update = function (arg) {
mediaInfo.title = propOrDefault(arg.title);
mediaInfo.artist = propOrDefault(arg.message);
mediaInfo.album = propOrDefault(arg.album);
mediaInfo.icon = propOrDefault(arg.icon);
mediaInfo.url = propOrDefault(arg.url);
mediaInfo.status = propOrDefault(arg.status);
Expand Down