()
| 486 | } |
| 487 | |
| 488 | async fetchInfo() { |
| 489 | const meta = Spicetify.Player.data.item.metadata; |
| 490 | |
| 491 | // prepare title |
| 492 | let rawTitle = meta.title; |
| 493 | if (CONFIG.trimTitle) { |
| 494 | rawTitle = rawTitle |
| 495 | .replace(/\(.+?\)/g, "") |
| 496 | .replace(/\[.+?\]/g, "") |
| 497 | .replace(/\s-\s.+?$/, "") |
| 498 | .replace(/,.+?$/, "") |
| 499 | .trim(); |
| 500 | } |
| 501 | |
| 502 | // prepare artist |
| 503 | let artistName; |
| 504 | if (CONFIG.showAllArtists) { |
| 505 | artistName = Object.keys(meta) |
| 506 | .filter((key) => key.startsWith("artist_name")) |
| 507 | .sort() |
| 508 | .map((key) => meta[key]) |
| 509 | .join(", "); |
| 510 | } else { |
| 511 | artistName = meta.artist_name; |
| 512 | } |
| 513 | |
| 514 | // prepare release date |
| 515 | let releaseDate; |
| 516 | if (CONFIG.showReleaseDate) { |
| 517 | const albumURI = meta.album_uri; |
| 518 | if (albumURI?.startsWith("spotify:album:")) { |
| 519 | releaseDate = await this.getAlbumDate(albumURI); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | // prepare album |
| 524 | const albumText = meta.album_title || ""; |
| 525 | |
| 526 | if (meta.image_xlarge_url === this.currTrackImg.src) { |
| 527 | this.setState({ |
| 528 | title: rawTitle || "", |
| 529 | artist: artistName || "", |
| 530 | album: albumText || "", |
| 531 | releaseDate: releaseDate || "", |
| 532 | heart: Spicetify.Player.getHeart(), |
| 533 | }); |
| 534 | return; |
| 535 | } |
| 536 | |
| 537 | // TODO: Pre-load next track |
| 538 | // Wait until next track image is downloaded then update UI text and images |
| 539 | const previousImg = this.currTrackImg.cloneNode(); |
| 540 | this.currTrackImg.src = meta.image_xlarge_url; |
| 541 | this.currTrackImg.onload = () => { |
| 542 | const bgImage = `url("${this.currTrackImg.src}")`; |
| 543 | |
| 544 | this.animateCanvas(previousImg, this.currTrackImg); |
| 545 | this.setState({ |
no test coverage detected