diff --git a/websites/Y/Yandex Music/metadata.json b/websites/Y/Yandex Music/metadata.json index a11c696d9b77..3540eaa1626c 100644 --- a/websites/Y/Yandex Music/metadata.json +++ b/websites/Y/Yandex Music/metadata.json @@ -5,6 +5,12 @@ "name": "D3rise", "id": "253913831896645632" }, + "contributors": [ + { + "name": "slowlife.", + "id": "374905512661221377" + } + ], "service": "Yandex Music", "description": { "en": "Yandex streaming service that allows you to listen to music tracks, albums, and collections of music tracks and get personal recommendations.", @@ -12,8 +18,11 @@ "ga_IE": "Seirbhís sruthú Yandex a ligeann duit éisteacht le rianta ceoil, albam, agus bailiúcháin rianta ceoil agus moltaí pearsanta a fháil.", "nl": "Yandex-streamingdienst waarmee u naar muziektracks, albums en verzamelingen muziektracks kunt luisteren en persoonlijke aanbevelingen kunt krijgen." }, - "url": "music.yandex.ru", - "version": "1.1.4", + "url": [ + "music.yandex.ru", + "music.yandex.com" + ], + "version": "2.0.0", "logo": "https://cdn.rcd.gg/PreMiD/websites/Y/Yandex%20Music/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/Y/Yandex%20Music/assets/thumbnail.png", "color": "#FDCD01", diff --git a/websites/Y/Yandex Music/presence.ts b/websites/Y/Yandex Music/presence.ts index 75bfe80486ee..c3c8a7b61581 100644 --- a/websites/Y/Yandex Music/presence.ts +++ b/websites/Y/Yandex Music/presence.ts @@ -1,77 +1,38 @@ const presence = new Presence({ - clientId: "745261937092198532", - }), - strings = presence.getStrings({ - playing: "general.playing", - pause: "general.paused", - }); - -let presenceData: PresenceData; - -function getMillisecondsFromString(timeString: string): number { - const parsedText = timeString.split(":"); - return (Number(parsedText[0]) * 60 + Number(parsedText[1])) * 1000; -} - -function isPodcast(): boolean { - return !!document.querySelectorAll(".track__podcast")[0]; -} - -setInterval(async () => { - const startedAt = - Date.now() - - getMillisecondsFromString( - document.querySelectorAll(".progress__left")[0].textContent - ), - playing = - document.querySelectorAll(".player-controls__btn_pause").length === 2; - - let artists; - if (isPodcast()) { - artists = - document.querySelectorAll(".track__podcast")[0].textContent; - } else { - artists = - document.querySelectorAll(".track__artists")[0].textContent; - } - - const coverImageSizes = document - .querySelector(".track") - .querySelector(".entity-cover__image") - .srcset // get all images of all sizes - .split(", "), - coverImage = coverImageSizes - .at(-1) // get the last one (the best one) - .split(" ") - .at(0), - largeImageKey = coverImage - ? `https:${coverImage}` - : "https://cdn.rcd.gg/PreMiD/websites/Y/Yandex%20Music/assets/logo.png"; - - presenceData = { - largeImageKey, - smallImageKey: playing ? Assets.Play : Assets.Pause, - smallImageText: playing ? (await strings).playing : (await strings).pause, - details: - document.querySelectorAll(".track__title")[0].textContent, - state: artists, - startTimestamp: startedAt, - endTimestamp: - startedAt + - getMillisecondsFromString( - document.querySelectorAll(".progress__right")[0] - .textContent - ), - }; - - if (!playing) { - delete presenceData.startTimestamp; - delete presenceData.endTimestamp; - } -}, 1000); + clientId: "745261937092198532", +}); -presence.on("UpdateData", () => { - if (document.querySelectorAll(".track__title").length !== 0) - presence.setActivity(presenceData); - else presence.setActivity(); +presence.on("UpdateData", async () => { + if ( + document.querySelectorAll(".player-controls__btn_pause").length !== 2 || + !navigator.mediaSession.metadata + ) + return presence.clearActivity(); + + const largeImageKey = navigator.mediaSession.metadata.artwork + ? navigator.mediaSession.metadata.artwork.at(-1).src + : "https://cdn.rcd.gg/PreMiD/websites/Y/Yandex%20Music/assets/logo.png", + timePassed = document.querySelector(".progress__left").textContent, + [currentTime, duration] = [ + presence.timestampFromFormat(timePassed), + presence.timestampFromFormat( + document.querySelector(".progress__right").textContent + ) + presence.timestampFromFormat(timePassed), + ], + [startTimestamp, endTimestamp] = presence.getTimestamps( + currentTime, + duration + ), + presenceData = { + type: ActivityType.Listening, + largeImageKey, + details: navigator.mediaSession.metadata.title, + state: + navigator.mediaSession.metadata.artist || + navigator.mediaSession.metadata.album, + startTimestamp, + endTimestamp, + }; + + presence.setActivity(presenceData); });