47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import { appleMusicFetch } from "../3p/appleMusicClient";
|
|
import { spotifyFetch } from "../3p/spotifyClient";
|
|
|
|
const APM_ID = "1552965331";
|
|
const SPT_ID = "0kDiUhIznBbi6Y3slWiOBS";
|
|
|
|
const appleResult = await appleMusicFetch("/catalog/us/albums/" + APM_ID);
|
|
const spotiResult = await spotifyFetch("/albums/" + SPT_ID + "?market=US");
|
|
|
|
const appleAlbum = appleResult.data[0];
|
|
const appleUpc = appleAlbum.attributes.upc;
|
|
|
|
const spotifyUpc = spotiResult.external_ids.upc;
|
|
|
|
if (appleUpc !== spotifyUpc) {
|
|
throw "UPC mismatch :/";
|
|
}
|
|
|
|
const appleISRCs = appleAlbum.relationships.tracks.data.map(a => a.attributes.isrc);
|
|
const spotifyISRCs = spotiResult.tracks.items.map(a => a.external_ids ? a.external_ids.isrc : null);
|
|
|
|
if (appleISRCs.length !== spotifyISRCs.length) {
|
|
throw "ISRC or something mismatch :/";
|
|
}
|
|
|
|
const a = new URLSearchParams();
|
|
|
|
for (let i = 0; i < appleISRCs.length; i++) {
|
|
const cands = new Set([appleISRCs[i], spotifyISRCs[i]].filter(a => !!a));
|
|
if (cands.size !== 1) throw "skill issue";
|
|
const c = Array.from(cands);
|
|
|
|
a.append(`isrc${i + 1}`, c[0]);
|
|
}
|
|
|
|
a.append("edit-note", `Data obtained via authenticated APIs from:
|
|
- Apple Music: https://api.music.apple.com/v1/catalog/us/albums/${APM_ID}
|
|
- Spotify: https://api.spotify.com/v1/albums/${SPT_ID}?market=US`);
|
|
|
|
|
|
console.log("UPC: " + appleUpc);
|
|
console.log(`https://magicisrc.kepstin.ca/?${a.toString()}`);
|
|
|
|
console.log("\n\n");
|
|
console.log(`Data obtained via authenticated APIs from:
|
|
- Apple Music: https://api.music.apple.com/v1/catalog/us/albums/${APM_ID}
|
|
- Spotify: https://api.spotify.com/v1/albums/${SPT_ID}?market=US`) |