mpris fix

This commit is contained in:
Core 2022-03-11 00:26:42 +00:00
parent 6da8c3c2b6
commit 44ed769ed6
No known key found for this signature in database
GPG key ID: FE9BF1B547F8F3C6
6 changed files with 127 additions and 133 deletions

View file

@ -1212,9 +1212,9 @@
tslib "^1.9.3"
"@sentry/electron@^3.0.2":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@sentry/electron/-/electron-3.0.3.tgz#cfb8ba582753a9b34beb4f775cc48fd0a82096df"
integrity sha512-uDSFfl3eL29Dq8jYIJmWFWRHMQCSNk6pjL6gUmJiPhEhpu72hokZyezUJsJrSyipraqLgmSimY71u0ayARYqwg==
version "3.0.4"
resolved "https://registry.yarnpkg.com/@sentry/electron/-/electron-3.0.4.tgz#ce69bab9b2f6a7b92183e9fff138a0f79c5c76e3"
integrity sha512-IsvhxtHeBLNoRMMfsOHrWghNoJZodJ2lC95Qm22Nsk/qm3W11YMxa38u/l1aKU2f3gmu3Gbti4sT+3eNXD/bKg==
dependencies:
"@sentry/browser" "6.17.2"
"@sentry/core" "6.17.2"
@ -1234,12 +1234,12 @@
tslib "^1.9.3"
"@sentry/integrations@^6.18.1":
version "6.18.1"
resolved "https://registry.yarnpkg.com/@sentry/integrations/-/integrations-6.18.1.tgz#c815eb9d104739805401b69d5559adec14876e33"
integrity sha512-Xzg9C0qPpauZGab2OLKnJjCwn/Lx7WsZK87Q53KaYcscdvXNV0LriNzNKcBIRH+Q+GEsaF3mjyGDLmuDABB59A==
version "6.18.2"
resolved "https://registry.yarnpkg.com/@sentry/integrations/-/integrations-6.18.2.tgz#caed0092e8a6c9fb0b8b7efd2deef946ca76e626"
integrity sha512-jzEH15m1dewzma2Fp0ENNRUDEOI3gGPfC/+lsLAuj9AMoNZ6qykQP8cB8OPTlzIZc0oyWGAE/1LoTrndPAvoPA==
dependencies:
"@sentry/types" "6.18.1"
"@sentry/utils" "6.18.1"
"@sentry/types" "6.18.2"
"@sentry/utils" "6.18.2"
localforage "^1.8.1"
tslib "^1.9.3"
@ -1283,10 +1283,10 @@
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.17.2.tgz#4dde3423db5953e798b19ed29618c28fc7bf2e30"
integrity sha512-UrFLRDz5mn253O8k/XftLxoldF+NyZdkqKLGIQmST5HEVr7ub9nQJ4Y5ZFA3zJYWpraaW8faIbuw+pgetC8hmQ==
"@sentry/types@6.18.1":
version "6.18.1"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.18.1.tgz#e2de38dd0da8096a5d22f8effc6756c919266ede"
integrity sha512-wp741NoBKnXE/4T9L723sWJ8EcNMxeTIT1smgNJOfbPwrsDICoYmGEt6JFa05XHpWBGI66WuNvnDjoHVeh6zhA==
"@sentry/types@6.18.2":
version "6.18.2"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-6.18.2.tgz#f528fec8b75c19d5a6976004e71703184c6cf7be"
integrity sha512-WzpJf/Q5aORTzrSwer/As1NlO90dBAQpaHV2ikDDKqOyMWEgjKb5/4gh59p9gH8JMMnLetP1AvQel0fOj5UnUw==
"@sentry/utils@6.17.2":
version "6.17.2"
@ -1296,12 +1296,12 @@
"@sentry/types" "6.17.2"
tslib "^1.9.3"
"@sentry/utils@6.18.1":
version "6.18.1"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.18.1.tgz#1aa819502b042540612f4db7bcb86c7b176f5a6b"
integrity sha512-IFZmuvA+c5lDGlZEri13JSyUP0BHelzY0S4dcKxAzskPW+BtBdQDgYGV90iED1y+IRMLawWb34GF7HyJSouN1Q==
"@sentry/utils@6.18.2":
version "6.18.2"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-6.18.2.tgz#c572a3ff49113e7dc4c97db1a18d117f199b9fff"
integrity sha512-EC619jesknyu4xpwud5WC/5odYLz6JUy7OSFy5405PpdGeh/m8XUvuJAx4zDx0Iz/Mlk0S1Md+ZcQwqkv39dkw==
dependencies:
"@sentry/types" "6.18.1"
"@sentry/types" "6.18.2"
tslib "^1.9.3"
"@sindresorhus/is@^0.14.0":
@ -1610,9 +1610,9 @@
"@types/node" "*"
"@types/yargs-parser@*":
version "20.2.1"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-20.2.1.tgz#3b9ce2489919d9e4fea439b76916abc34b2df129"
integrity sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==
version "21.0.0"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.0.tgz#0c60e537fa790f5f9472ed2776c2b71ec117351b"
integrity sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==
"@types/yargs@^16.0.0":
version "16.0.4"
@ -1622,9 +1622,9 @@
"@types/yargs-parser" "*"
"@types/yargs@^17.0.1":
version "17.0.8"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.8.tgz#d23a3476fd3da8a0ea44b5494ca7fa677b9dad4c"
integrity sha512-wDeUwiUmem9FzsyysEwRukaEdDNcwbROvQ9QGRKaLI6t+IltNzbn4/i4asmB10auvZGQCzSQ6t0GSczEThlUXw==
version "17.0.9"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.9.tgz#f1f931a4e5ae2c0134dea10f501088636a50b46a"
integrity sha512-Ci8+4/DOtkHRylcisKmVMtmVO5g7weUVCKcsu1sJvF1bn0wExTmbHmhFKj7AnEm0de800iovGhdSKzYnzbaHpg==
dependencies:
"@types/yargs-parser" "*"
@ -2317,12 +2317,12 @@ braces@^3.0.1, braces@~3.0.2:
fill-range "^7.0.1"
browserslist@^4.14.5, browserslist@^4.17.5, browserslist@^4.19.1:
version "4.19.3"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.19.3.tgz#29b7caad327ecf2859485f696f9604214bedd383"
integrity sha512-XK3X4xtKJ+Txj8G5c30B4gsm71s69lqXlkYui4s6EkKxuv49qjYlY6oVd+IFJ73d4YymtM3+djvvt/R/iJwwDg==
version "4.20.0"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.20.0.tgz#35951e3541078c125d36df76056e94738a52ebe9"
integrity sha512-bnpOoa+DownbciXj0jVGENf8VYQnE2LNWomhYuCsMmmx9Jd9lwq0WXODuwpSsp8AVdKM2/HorrzxAfbKvWTByQ==
dependencies:
caniuse-lite "^1.0.30001312"
electron-to-chromium "^1.4.71"
caniuse-lite "^1.0.30001313"
electron-to-chromium "^1.4.76"
escalade "^3.1.1"
node-releases "^2.0.2"
picocolors "^1.0.0"
@ -2534,10 +2534,10 @@ camelcase@^6.2.0:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a"
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==
caniuse-lite@^1.0.30001312:
version "1.0.30001312"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001312.tgz#e11eba4b87e24d22697dae05455d5aea28550d5f"
integrity sha512-Wiz1Psk2MEK0pX3rUzWaunLTZzqS2JYZFzNKqAiJGiuxIjRPLgV6+VDPOg6lQOUxmDwhTlh198JsTTi8Hzw6aQ==
caniuse-lite@^1.0.30001313:
version "1.0.30001314"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001314.tgz#65c7f9fb7e4594fca0a333bec1d8939662377596"
integrity sha512-0zaSO+TnCHtHJIbpLroX7nsD+vYuOVjl3uzFbJO1wMVbuveJA0RK2WcQA9ZUIOiO0/ArMiMgHJLxfEZhQiC0kw==
castv2-client@^1.2.0:
version "1.2.0"
@ -3505,10 +3505,10 @@ electron-store@^8.0.1:
conf "^10.0.3"
type-fest "^1.0.2"
electron-to-chromium@^1.4.71:
version "1.4.75"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.75.tgz#d1ad9bb46f2f1bf432118c2be21d27ffeae82fdd"
integrity sha512-LxgUNeu3BVU7sXaKjUDD9xivocQLxFtq6wgERrutdY/yIOps3ODOZExK1jg8DTEg4U8TUCb5MLGeWFOYuxjF3Q==
electron-to-chromium@^1.4.76:
version "1.4.80"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.80.tgz#299a1ea3e32810934b4e3c2e4d4cb53136fdab3f"
integrity sha512-COsbJCGVYCc/aAY4cd94x1Js3q0r406YKGbdL8LXHg0O9dEjuFEFU/vZneRxBxKo/f1lLHi0YyAR7sbFM+i8Bg==
electron-updater@^4.6.5:
version "4.6.5"
@ -3635,9 +3635,9 @@ enhanced-resolve@^4.1.1:
tapable "^1.0.0"
enhanced-resolve@^5.8.3:
version "5.9.1"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.9.1.tgz#e898cea44d9199fd92137496cff5691b910fb43e"
integrity sha512-jdyZMwCQ5Oj4c5+BTnkxPgDZO/BJzh/ADDmKebayyzNwjVX1AFCeGkOfxNx0mHi2+8BKC5VxUYiw3TIvoT7vhw==
version "5.9.2"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.9.2.tgz#0224dcd6a43389ebfb2d55efee517e5466772dd9"
integrity sha512-GIm3fQfwLJ8YZx2smuHpBKkXC1yOk+OBEmKckVyL0i/ea8mqDEykK3ld5dgH1QYPNyT/lIllxV2LULnxCHaHkA==
dependencies:
graceful-fs "^4.2.4"
tapable "^2.2.0"
@ -4217,11 +4217,10 @@ function-bind@^1.1.1:
integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==
gauge@^4.0.0:
version "4.0.2"
resolved "https://registry.yarnpkg.com/gauge/-/gauge-4.0.2.tgz#c3777652f542b6ef62797246e8c7caddecb32cc7"
integrity sha512-aSPRm2CvA9R8QyU5eXMFPd+cYkyxLsXHd2l5/FOH2V/eml//M04G6KZOmTap07O1PvEwNcl2NndyLfK8g3QrKA==
version "4.0.3"
resolved "https://registry.yarnpkg.com/gauge/-/gauge-4.0.3.tgz#286cf105c1962c659f0963058fb05116c1b82d3f"
integrity sha512-ICw1DhAwMtb22rYFwEHgJcx1JCwJGv3x6G0OQUq56Nge+H4Q8JEwr8iveS0XFlsUNSI67F5ffMGK25bK4Pmskw==
dependencies:
ansi-regex "^5.0.1"
aproba "^1.0.3 || ^2.0.0"
color-support "^1.1.3"
console-control-strings "^1.1.0"
@ -4655,9 +4654,9 @@ http-errors@~1.6.2:
statuses ">= 1.4.0 < 2"
http-parser-js@>=0.5.1:
version "0.5.5"
resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.5.5.tgz#d7c30d5d3c90d865b4a2e870181f9d6f22ac7ac5"
integrity sha512-x+JVEkO2PoM8qqpbPbOL3cqHPwerep7OwzK7Ay+sMQjKzaKCqWvjoXm5tqMP9tXWWTnTzAjIhXg+J99XYuPhPA==
version "0.5.6"
resolved "https://registry.yarnpkg.com/http-parser-js/-/http-parser-js-0.5.6.tgz#2e02406ab2df8af8a7abfba62e0da01c62b95afd"
integrity sha512-vDlkRPDJn93swjcjqMSaGSPABbIarsr1TLAui/gLDXzV5VsJNdXNzMYDyNBLQkjWQCJ1uizu8T2oDMhmGt0PRA==
http-proxy-agent@^4.0.1:
version "4.0.1"

View file

@ -138,9 +138,7 @@
],
"linux": {
"target": [
"AppImage",
"deb",
"snap"
"AppImage"
],
"synopsis": "A new look into listening and enjoying music in style and performance. ",
"category": "AudioVideo",

View file

@ -12,9 +12,9 @@ import fetch from 'electron-fetch'
import {wsapi} from "./wsapi";
import {utils} from './utils';
import {Plugins} from "./plugins";
const fileWatcher = require('chokidar');
const AdmZip = require("adm-zip");
import {watch} from "chokidar";
// @ts-ignore
import * as AdmZip from "adm-zip";
/**
* @file Creates the BrowserWindow
@ -244,9 +244,7 @@ export class BrowserWindow {
};
StartWatcher(path: string) {
var chokidar = require("chokidar");
var watcher = chokidar.watch(path, {
const watcher = watch(path, {
ignored: /[\/\\]\./,
persistent: true
});
@ -1049,11 +1047,7 @@ export class BrowserWindow {
ipcMain.on('disable-update', (event) => {
// Check if using app store builds so people don't get pissy wen button go bonk
if (app.isPackaged && !process.mas || !process.windowsStore) {
event.returnValue = false
} else {
event.returnValue = true
}
event.returnValue = !(app.isPackaged && !process.mas || !process.windowsStore);
})
@ -1190,7 +1184,7 @@ export class BrowserWindow {
private async broadcastRemote() {
const myString = `http://${BrowserWindow.getIP()}:${this.remotePort}`;
const mdns = require('mdns-js');
const encoded = new Buffer(myString).toString('base64');
const encoded = Buffer.from(myString).toString('base64');
const x = mdns.tcp('cider-remote');
const txt_record = {
"Ver": "131077",

View file

@ -54,6 +54,7 @@ app.on('ready', () => {
win.on("ready-to-show", () => {
Cider.bwCreated();
console.debug('[Cider] Window is Ready.')
CiderPlug.callPlugins('onReady', win);
});
});

View file

@ -1,12 +1,10 @@
// @ts-ignore
import * as Player from 'mpris-service';
export default class MPRIS {
export default class mpris {
/**
* Private variables for interaction in plugins
*/
private _win: any;
private _app: any;
private static utils: any;
/**
@ -20,8 +18,8 @@ export default class MPRIS {
/**
* MPRIS Service
*/
private mpris: any;
private mprisEvents: Object = {
private static player: Player.Player;
private static mprisEvents: Object = {
"playpause": "playPause",
"play": "play",
"pause": "pause",
@ -35,11 +33,12 @@ export default class MPRIS {
/**
* Runs a media event
* @param type - pausePlay, nextTrack, PreviousTrack
* @param type - pausePlay, next, previous
* @private
*/
private static runMediaEvent(type: string) {
MPRIS.utils.getWindow().webContents.executeJavaScript(`MusicKitInterop.${type}()`).catch(console.error)
console.debug(`[Plugin][${this.name}] ${type}.`);
mpris.utils.getWindow().webContents.executeJavaScript(`MusicKitInterop.${type}()`).catch(console.error)
}
/**
@ -59,90 +58,89 @@ export default class MPRIS {
/**
* Connects to MPRIS Service
*/
@MPRIS.linuxOnly
private connect() {
this.mpris = Player({
name: 'Cider',
@mpris.linuxOnly
private static connect() {
const player = Player({
name: 'cider',
identity: 'Cider',
supportedUriSchemes: [],
supportedMimeTypes: [],
supportedInterfaces: ['player']
});
this.mpris = Object.assign(this.mpris, {
canQuit: true,
canControl: true,
canPause: true,
canPlay: true,
canGoNext: true,
active: true
})
console.debug(`[Plugin][${mpris.name}] Successfully connected.`);
const pos_atr = {durationInMillis: 0};
this.mpris.getPosition = function () {
player.getPosition = function () {
const durationInMicro = pos_atr.durationInMillis * 1000;
const percentage = parseFloat("0") || 0;
return durationInMicro * percentage;
}
for (const [key, value] of Object.entries(this.mprisEvents)) {
this.mpris.on(key, () => {
MPRIS.runMediaEvent(value)
for (const [key, value] of Object.entries(mpris.mprisEvents)) {
player.on(key, function () {
mpris.runMediaEvent(value)
});
}
player.on('quit', function () {
process.exit();
});
mpris.player = player;
}
/**
* Update MPRIS Player Attributes
* Update M.P.R.I.S Player Attributes
*/
@MPRIS.linuxOnly
private updatePlayer(attributes: any) {
@mpris.linuxOnly
private static updatePlayer(attributes: any) {
const MetaData = {
'mpris:trackid': this.mpris.objectPath(`track/${attributes.playParams.id.replace(/[.]+/g, "")}`),
'mpris:trackid': mpris.player.objectPath(`track/${attributes.playParams.id.replace(/[.]+/g, "")}`),
'mpris:length': attributes.durationInMillis * 1000, // In microseconds
'mpris:artUrl': (attributes.artwork.url.replace('/{w}x{h}bb', '/512x512bb')).replace('/2000x2000bb', '/35x35bb'),
'xesam:title': `${attributes.name}`,
'xesam:album': `${attributes.albumName}`,
'xesam:artist': [`${attributes.artistName}`,],
'xesam:artist': [`${attributes.artistName}`],
'xesam:genre': attributes.genreNames
}
if (this.mpris.metadata["mpris:trackid"] === MetaData["mpris:trackid"]) {
if (mpris.player.metadata["mpris:trackid"] === MetaData["mpris:trackid"]) {
return
}
this.mpris.metadata = MetaData;
mpris.player.metadata = MetaData;
}
/**
* Update MPRIS Player State
* Update M.P.R.I.S Player State
* @private
* @param attributes
*/
@MPRIS.linuxOnly
private updatePlayerState(attributes: any) {
let status = 'Stopped';
if (attributes.status) {
status = 'Playing';
} else if (attributes.status === false) {
status = 'Paused';
@mpris.linuxOnly
private static updatePlayerState(attributes: any) {
switch (attributes.status) {
case true: // Playing
mpris.player.playbackStatus = Player.PLAYBACK_STATUS_PLAYING;
break;
case false: // Paused
mpris.player.playbackStatus = Player.PLAYBACK_STATUS_PAUSED;
break;
default:
mpris.player.playbackStatus = Player.PLAYBACK_STATUS_STOPPED;
break
}
if (this.mpris.playbackStatus === status) {
return
}
this.mpris.playbackStatus = status;
}
/**
* Clear state
* @private
*/
private clearState() {
this.mpris.metadata = {'mpris:trackid': '/org/mpris/MediaPlayer2/TrackList/NoTrack'}
this.mpris.playbackStatus = 'Stopped';
private static clearState() {
mpris.player.metadata = {'mpris:trackid': '/org/mpris/MediaPlayer2/TrackList/NoTrack'}
mpris.player.playbackStatus = Player.PLAYBACK_STATUS_STOPPED;
}
@ -153,31 +151,32 @@ export default class MPRIS {
/**
* Runs on plugin load (Currently run on application start)
*/
constructor(utils: { getApp: () => any; }) {
MPRIS.utils = utils
this._app = utils.getApp();
console.debug(`[Plugin][${this.name}] Loading Complete.`);
constructor(utils: any) {
mpris.utils = utils
console.debug(`[Plugin][${mpris.name}] Loading Complete.`);
}
/**
* Runs on app ready
*/
onReady(win: any): void {
this._win = win;
console.debug(`[Plugin][${this.name}] Ready.`);
this.connect()
onReady(_: any): void {
console.debug(`[Plugin][${mpris.name}] Ready.`);
}
/**
* Renderer ready
*/
onRendererReady(): void {
mpris.connect()
}
/**
* Runs on app stop
*/
onBeforeQuit(): void {
console.debug(`[Plugin][${this.name}] Stopped.`);
try {
this.clearState()
} catch (e) {
console.error(e)
}
console.debug(`[Plugin][${mpris.name}] Stopped.`);
mpris.clearState()
}
/**
@ -185,7 +184,8 @@ export default class MPRIS {
* @param attributes Music Attributes (attributes.status = current state)
*/
onPlaybackStateDidChange(attributes: object): void {
this.updatePlayerState(attributes)
console.debug(`[Plugin][${mpris.name}] onPlaybackStateDidChange.`);
mpris.updatePlayerState(attributes)
}
/**
@ -193,7 +193,8 @@ export default class MPRIS {
* @param attributes Music Attributes
*/
onNowPlayingItemDidChange(attributes: object): void {
this.updatePlayer(attributes);
console.debug(`[Plugin][${mpris.name}] onMetadataDidChange.`);
mpris.updatePlayer(attributes);
}
}

View file

@ -10,7 +10,7 @@ const MusicKitInterop = {
const attributes = MusicKitInterop.getAttributes()
if (MusicKitInterop.filterTrack(attributes, true, false)) {
global.ipcRenderer.send('playbackStateDidChange', attributes)
ipcRenderer.send('wsapi-updatePlaybackState', attributes);
global.ipcRenderer.send('wsapi-updatePlaybackState', attributes);
// if (typeof _plugins != "undefined") {
// _plugins.execute("OnPlaybackStateChanged", {Attributes: MusicKitInterop.getAttributes()})
// }
@ -24,6 +24,7 @@ const MusicKitInterop = {
/** wsapi */
MusicKit.getInstance().addEventListener(MusicKit.Events.nowPlayingItemDidChange, async () => {
console.log('nowPlayingItemDidChange')
const attributes = MusicKitInterop.getAttributes()
const trackFilter = MusicKitInterop.filterTrack(attributes, false, true)
@ -47,7 +48,7 @@ const MusicKitInterop = {
})
},
async modifyNamesOnLocale() {
if (app.mklang == '' || app.mklang == null) {
if (app.mklang === '' || app.mklang == null) {
return;
}
const mk = MusicKit.getInstance()
@ -56,17 +57,17 @@ const MusicKitInterop = {
return;
}
const id = nowPlayingItem?._songId ?? (nowPlayingItem?.songId ?? nowPlayingItem?.id)
if (id != null && id != -1) {
if (id != null && id !== -1) {
try{
const query = await mk.api.v3.music(`/v1${(((nowPlayingItem?._songId ?? nowPlayingItem?.songId) != null) && ((nowPlayingItem?._songId ?? nowPlayingItem?.songId) != -1)) ? `/catalog/${mk.storefrontId}/` : `/me/library/`}songs/${id}?l=${app.mklang}`);
const query = await mk.api.v3.music(`/v1${(((nowPlayingItem?._songId ?? nowPlayingItem?.songId) != null) && ((nowPlayingItem?._songId ?? nowPlayingItem?.songId) !== -1)) ? `/catalog/${mk.storefrontId}/` : `/me/library/`}songs/${id}?l=${app.mklang}`);
if (query?.data?.data[0]){
let attrs = query?.data?.data[0]?.attributes;
if (attrs?.name) { nowPlayingItem.attributes.name = attrs?.name ?? ''}
if (attrs?.albumName) { nowPlayingItem.attributes.albumName = attrs?.albumName ?? ''}
if (attrs?.artistName) { nowPlayingItem.attributes.artistName = attrs?.artistName ?? ''}
}} catch (e) { return;}
} else {return;}
}} catch (e) { }
} else {}
},
getAttributes: function () {
const mk = MusicKit.getInstance()
@ -75,7 +76,7 @@ const MusicKitInterop = {
const remainingTimeExport = mk.currentPlaybackTimeRemaining;
const attributes = (nowPlayingItem != null ? nowPlayingItem.attributes : {});
attributes.status = isPlayingExport ?? false;
attributes.status = isPlayingExport ?? null;
attributes.name = attributes?.name ?? 'no-title-found';
attributes.artwork = attributes?.artwork ?? {url: ''};
attributes.artwork.url = (attributes?.artwork?.url ?? '').replace(`{f}`, "png");
@ -120,7 +121,7 @@ const MusicKitInterop = {
},
play: () => {
MusicKit.getInstance().play().then(r => console.log(`[MusicKitInterop.play] ${r}`));
MusicKit.getInstance().play().catch(console.error);
},
pause: () => {
@ -131,7 +132,7 @@ const MusicKitInterop = {
if (MusicKit.getInstance().isPlaying) {
MusicKit.getInstance().pause();
} else if (MusicKit.getInstance().nowPlayingItem != null) {
MusicKit.getInstance().play().then(r => console.log(`[MusicKitInterop.playPause] Playing ${r}`));
MusicKit.getInstance().play().catch(console.error);
}
},