fixed artists retrieval, removed arch build steps

This commit is contained in:
2021-05-30 15:40:27 +02:00
parent d34ddfeb75
commit d6f63ac560
8 changed files with 36 additions and 118 deletions

View File

@@ -23,7 +23,7 @@ const elements = {
next: '*[data-test="next"]',
previous: 'button[data-test="previous"]',
title: '*[data-test^="footer-track-title"]',
artists: '*[class^="elemental__text elemental__text css-oxcos"]',
artists: '*[data-test^="grid-item-detail-text-title-artist"]',
home: '*[data-test="menu--home"]',
back: '[class^="backwardButton"]',
forward: '[class^="forwardButton"]',
@@ -38,6 +38,7 @@ const elements = {
current: '*[data-test="current-time"]',
duration: '*[data-test="duration-time"]',
bar: '*[data-test="progress-bar"]',
footer: "#footerPlayer",
/**
* Get an element from the dom
@@ -63,6 +64,19 @@ const elements = {
return "";
},
getArtists: function () {
const footer = this.get("footer");
if (footer) {
const artists = footer.querySelector(this["artists"]);
if (artists) {
return artists.innerText;
}
}
return "unknown artist(s)";
},
/**
* Shorthand function to get the text of a dom element
* @param {*} key key in elements object to fetch
@@ -266,7 +280,7 @@ function updateURL() {
*/
setInterval(function () {
const title = elements.getText("title");
const artists = elements.getText("artists");
const artists = elements.getArtists();
const current = elements.getText("current");
const duration = elements.getText("duration");
const progressBarcurrentTime = elements.get("bar").getAttribute("aria-valuenow");
@@ -293,21 +307,21 @@ setInterval(function () {
currentPlayStatus = currentStatus;
// check progress bar value and make sure current stays up to date after switch
if(progressBarTime != progressBarcurrentTime && !titleOrArtistChanged) {
if (progressBarTime != progressBarcurrentTime && !titleOrArtistChanged) {
progressBarTime = progressBarcurrentTime;
currentTime = options.current;
options.duration = duration;
currentTimeChanged = true;
}
if(currentTimeChanged) {
if(options.current == currentTime && currentStatus != "paused") return;
if (currentTimeChanged) {
if (options.current == currentTime && currentStatus != "paused") return;
currentTime = options.current;
currentTimeChanged = false;
}
// make sure current is set to 0 if title changes
if(titleOrArtistChanged) {
if (titleOrArtistChanged) {
options.current = "0:00";
currentTime = options.current;
progressBarTime = progressBarcurrentTime;

View File

@@ -6,8 +6,8 @@ const mediaInfoModule = require("./mediaInfo");
const discordModule = [];
function timeToSeconds(timeArray) {
let minutes = (timeArray[0] * 1);
let seconds = (minutes * 60) + (timeArray[1] * 1);
let minutes = timeArray[0] * 1;
let seconds = minutes * 60 + timeArray[1] * 1;
return seconds;
}
@@ -19,14 +19,16 @@ const observer = (event, arg) => {
const currentSeconds = timeToSeconds(mediaInfoModule.mediaInfo.current.split(":"));
const durationSeconds = timeToSeconds(mediaInfoModule.mediaInfo.duration.split(":"));
const date = new Date();
const now = date.getTime() / 1000 | 0;
const now = (date.getTime() / 1000) | 0;
const remaining = date.setSeconds(date.getSeconds() + (durationSeconds - currentSeconds));
if (mediaInfoModule.mediaInfo.url) {
rpc.setActivity({
...idleStatus,
...{
details: `Listening to ${mediaInfoModule.mediaInfo.title}`,
state: mediaInfoModule.mediaInfo.artist,
state: mediaInfoModule.mediaInfo.artist
? mediaInfoModule.mediaInfo.artist
: "unknown artist(s)",
startTimestamp: parseInt(now),
endTimestamp: parseInt(remaining),
buttons: [{ label: "Play on Tidal", url: mediaInfoModule.mediaInfo.url }],