mirror of
https://notabug.org/SuperSaltyGamer/ame
synced 2026-01-15 19:12:56 -03:00
[applemusic] Various fixes, publish 1.4.2
This commit is contained in:
68
dist/applemusic.user.js
vendored
68
dist/applemusic.user.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @namespace ame-applemusic
|
||||
// @name Ame (Apple Music)
|
||||
// @version 1.4.1
|
||||
// @version 1.4.2
|
||||
// @author SuperSaltyGamer
|
||||
// @run-at document-start
|
||||
// @match https://music.apple.com/*
|
||||
|
||||
@@ -15,7 +15,7 @@ onAlbumRoute(async () => {
|
||||
const album = await getAlbum(albumId);
|
||||
if (!album) return;
|
||||
|
||||
const refEl = await waitFor('.headings__metadata', '.description');
|
||||
const refEl = await waitFor('.headings__metadata-bottom', '.description');
|
||||
if (!refEl) return;
|
||||
|
||||
const audioTraits = album.attributes.audioTraits;
|
||||
|
||||
@@ -78,7 +78,7 @@ async function checkCountries(refEl: HTMLElement) {
|
||||
<span data-storefront="${storefront.id}" title="Totally unavailable">${storefront.attributes.name}, </span>
|
||||
`));
|
||||
|
||||
await sleep(100);
|
||||
await sleep(222);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ async function checkCountries(refEl: HTMLElement) {
|
||||
`));
|
||||
}
|
||||
|
||||
await sleep(100);
|
||||
await sleep(222);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -115,6 +115,6 @@ async function checkCountries(refEl: HTMLElement) {
|
||||
<span data-storefront="${storefront.id}"><a target="_blank" href="https://music.apple.com/${storefront.id}/album/${albumId}" title="Fully available">${storefront.attributes.name}</a>, </span>
|
||||
`));
|
||||
|
||||
await sleep(100);
|
||||
await sleep(222);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,10 +62,13 @@ checkQualitiesButtonEl.addEventListener('click', async () => {
|
||||
|
||||
if (!data) throw new Error('Could not find data from track manifest.');
|
||||
|
||||
const realInfo = await fetchRealAlacQuality(track.attributes.extendedAssetUrls.enhancedHls, Object.values(data));
|
||||
if (realInfo) data['__REAL__'] = realInfo;
|
||||
const qualities = Object.values(data);
|
||||
qualities.sort(sortQuality);
|
||||
|
||||
const qualities = Object.values(data).sort(sortQuality);
|
||||
const realInfo = await fetchRealAlacQuality(track.attributes.extendedAssetUrls.enhancedHls, qualities);
|
||||
if (realInfo) qualities.push(realInfo);
|
||||
|
||||
qualities.sort(sortQuality);
|
||||
const displayQuality = qualities.find(quality => parseInt(quality['CHANNEL-COUNT']) <= 2)!;
|
||||
|
||||
trackEl.append(fromHTML(`<span class="ame-track-quality ame-color-tertiary" title="${qualities.map(formatQuality).join('\n')}">${formatQuality(displayQuality)}</span>`));
|
||||
@@ -108,10 +111,10 @@ function formatQuality(quality: Quality): string {
|
||||
|
||||
async function fetchRealAlacQuality(manifestUrl: string, qualities: Quality[]): Promise<Quality | null> {
|
||||
const baseUrl = manifestUrl.split('/').slice(0, -1).join('/');
|
||||
const segmentUrl = qualities.filter(quality => quality['AUDIO-FORMAT-ID'] === 'alac' && parseInt(quality['CHANNEL-COUNT']) <= 2).at(-1)?.['FIRST-SEGMENT-URI'];
|
||||
if (!segmentUrl) return null;
|
||||
const firstSegmentUrl = qualities.filter(quality => quality['AUDIO-FORMAT-ID'] === 'alac' && parseInt(quality['CHANNEL-COUNT']) <= 2).at(-1)?.['FIRST-SEGMENT-URI'];
|
||||
if (!firstSegmentUrl) return null;
|
||||
|
||||
const res = await (await fetchCors(`${baseUrl}/${segmentUrl}`, {
|
||||
const res = await (await fetchCors(`${baseUrl}/${firstSegmentUrl}`, {
|
||||
headers: {
|
||||
'Range': 'bytes=0-16384'
|
||||
}
|
||||
@@ -145,7 +148,7 @@ async function fetchRealAlacQuality(manifestUrl: string, qualities: Quality[]):
|
||||
pos += 8 + 28; // Move inside atom.
|
||||
case 0x61_6C_61_63: // alac
|
||||
return {
|
||||
'FIRST-SEGMENT-URI': segmentUrl,
|
||||
'FIRST-SEGMENT-URI': firstSegmentUrl,
|
||||
'AUDIO-FORMAT-ID': 'alac',
|
||||
'CHANNEL-COUNT': view.getUint8(pos + 8 + 13).toString(),
|
||||
'BIT-DEPTH': view.getUint8(pos + 8 + 9),
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
/* Hide Open in Music button in the sidebar. */
|
||||
|
||||
.navigation__scrollable-container + .navigation__native-cta {
|
||||
@@ -100,8 +99,8 @@ nav {
|
||||
|
||||
/* Fix artwork breaking when overflown metadata exceeds its height. */
|
||||
|
||||
.artwork {
|
||||
aspect-ratio: 1;
|
||||
div[slot="artwork"] {
|
||||
height: fit-content;
|
||||
}
|
||||
|
||||
/* Add styles for album quality badges. */
|
||||
|
||||
@@ -38,8 +38,10 @@ export function waitFor<T extends HTMLElement>(selector: string, waitSelector?:
|
||||
let el = refEl.querySelector<T>(waitSelector ?? selector);
|
||||
if (!el) return;
|
||||
|
||||
if (waitSelector) el = refEl.querySelector<T>(selector);
|
||||
if (!el) return;
|
||||
if (waitSelector) {
|
||||
el = refEl.querySelector<T>(selector);
|
||||
if (!el) return;
|
||||
}
|
||||
|
||||
resolve(el);
|
||||
clearTimeout(disposeTimeout);
|
||||
|
||||
Reference in New Issue
Block a user