Release v0.7.2 - Redesigned interface and persistent account settings
Validate and generate manual release / package (push) Canceled after 0s
Validate and generate manual release / package (push) Canceled after 0s
This commit is contained in:
1 parent
1d894f59fb
commit
398749210a
35 files changed
+2807
-256
No files matched your search
@@ -2,8 +2,8 @@ import {randomKey,hmac,base64url} from './webcrypto.mjs';
|
||||
import { MusicError } from '../../core/controller.mjs';
|
||||
// Shared trusted-GM/optional-companion transport. Never construct with MA credentials on a player client.
|
||||
export class MAReadClient {
|
||||
#base; #token; #target; #fetch; #providers; #catalog = new Map(); #catalogKey; #campaign; #expectedName; #expectedProvider; #writes = Promise.resolve(); #synthetic; #uncertain; #authorizedMedia = new Set(); #targetVolume; #nativePause;
|
||||
constructor({ baseUrl, token, target, approvedProviders = [], catalogKey = randomKey(), campaign = 'default', expectedName, expectedProvider, syntheticSequences = {}, fetchImpl = fetch }) {
|
||||
#base; #token; #target; #fetch; #providers; #catalog = new Map(); #catalogKey; #legacyCatalogKey; #campaign; #expectedName; #expectedProvider; #writes = Promise.resolve(); #synthetic; #uncertain; #authorizedMedia = new Set(); #targetVolume; #nativePause;
|
||||
constructor({ baseUrl, token, target, approvedProviders = [], catalogKey = randomKey(), legacyCatalogKey, campaign = 'default', expectedName, expectedProvider, syntheticSequences = {}, fetchImpl = fetch }) {
|
||||
const url = new URL(baseUrl);
|
||||
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password ||
|
||||
url.search || url.hash || url.pathname !== '/' || typeof token !== 'string' || !token ||
|
||||
@@ -13,6 +13,7 @@ export class MAReadClient {
|
||||
if (!(catalogKey instanceof Uint8Array) || catalogKey.length !== 32 || !campaign) throw new MusicError('denied');
|
||||
this.#providers = [...new Set(approvedProviders)];
|
||||
this.#catalogKey = Uint8Array.from(catalogKey); this.#campaign = campaign;
|
||||
if (legacyCatalogKey) this.#legacyCatalogKey = Uint8Array.from(legacyCatalogKey);
|
||||
if(!syntheticSequences || typeof syntheticSequences!=='object' || Object.values(syntheticSequences).some(v=>!Array.isArray(v)||!v.length||v.length>5000||v.some(uri=>typeof uri!=='string'||!uri.startsWith('builtin://track/http://'))))throw new MusicError('denied');
|
||||
this.#synthetic = structuredClone(syntheticSequences);
|
||||
for(const uri of Object.values(this.#synthetic).flat())this.#authorizedMedia.add(uri);
|
||||
@@ -96,8 +97,9 @@ export class MAReadClient {
|
||||
const key = JSON.stringify([type, mapping.provider_instance, mapping.item_id]);
|
||||
if (next.has(key)) continue;
|
||||
const id = base64url(await hmac(this.#catalogKey,JSON.stringify([this.#campaign,key])));
|
||||
next.set(key, { id, type, provider: mapping.provider_instance, itemId: mapping.item_id, dynamic: item.is_dynamic === true });
|
||||
choices.push({ provider: 'ma', id, kind: type, name: item.name.replace(/[\x00-\x1f\x7f]/g,'').slice(0,160) });
|
||||
const legacyId = this.#legacyCatalogKey && base64url(await hmac(this.#legacyCatalogKey,JSON.stringify([this.#campaign,key])));
|
||||
next.set(key, { id, legacyId, type, provider: mapping.provider_instance, itemId: mapping.item_id, dynamic: item.is_dynamic === true });
|
||||
choices.push({ provider: 'ma', id, ...(legacyId && {legacyId}), kind: type, name: item.name.replace(/[\x00-\x1f\x7f]/g,'').slice(0,160) });
|
||||
}
|
||||
if (page.length < 100) { complete = true; break; }
|
||||
}
|
||||
@@ -108,7 +110,7 @@ export class MAReadClient {
|
||||
}
|
||||
resolveCatalog(ref) {
|
||||
if (ref?.provider !== 'ma') throw new MusicError('denied');
|
||||
const entry = [...this.#catalog.values()].find(e => e.id === ref.id);
|
||||
const entry = [...this.#catalog.values()].find(e => e.id === ref.id || e.legacyId && e.legacyId === ref.id);
|
||||
if (!entry) throw new MusicError('expired-media');
|
||||
if(entry.dynamic)throw new MusicError('unsupported');
|
||||
const uri=`${entry.provider}://${entry.type}/${entry.itemId}`;this.#authorizedMedia.add(uri);return uri;
|
||||
@@ -123,7 +125,7 @@ export class MAReadClient {
|
||||
await this.inspectSynthetic(media);
|
||||
return media;
|
||||
}
|
||||
const entry=[...this.#catalog.values()].find(e=>e.id===ref.id);
|
||||
const entry=[...this.#catalog.values()].find(e=>e.id===ref.id || e.legacyId && e.legacyId===ref.id);
|
||||
if(entry.type==='radio')return media;
|
||||
const playlist=await this.#read('music/playlists/get',{item_id:entry.itemId,provider_instance_id_or_domain:entry.provider,allow_update_metadata:false});
|
||||
if(playlist?.is_dynamic!==false)throw new MusicError('unsupported');
|
||||
|
||||
@@ -8,6 +8,21 @@ export class MAPlaybackProvider {
|
||||
this.#client=client; this.#campaign=campaign; this.#session=session; this.#fence=fence; this.#authority=authority; this.#key=Uint8Array.from(snapshotKey);
|
||||
}
|
||||
capabilities() { return {seek:true,exactOrderRestore:false,exactUnshuffledRestore:true,concurrentLayers:false,volume:false}; }
|
||||
async playbackStatus() {
|
||||
this.#authority(this.#fence);
|
||||
const queue = await this.#client.queueState();
|
||||
this.#authority(this.#fence);
|
||||
const item = queue.current_item;
|
||||
const paused = this.#paused && queue.state === 'idle' && queue.current_index === this.#paused.index;
|
||||
const elapsed = paused ? this.#paused.position : queue.elapsed_time;
|
||||
const position = Number.isFinite(elapsed) ? Math.max(0, Math.floor(elapsed)) : 0;
|
||||
return {
|
||||
state: paused ? 'paused' : queue.state,
|
||||
title: typeof item?.name === 'string' ? item.name.replace(/[\x00-\x1f\x7f]/g, '').slice(0, 180) : '',
|
||||
duration: Number.isFinite(item?.duration) ? Math.max(0, Math.floor(item.duration)) : 0,
|
||||
position,
|
||||
};
|
||||
}
|
||||
#check(ctx) {
|
||||
if (ctx?.campaign !== this.#campaign || ctx?.session !== this.#session || !Number.isSafeInteger(ctx.generation) || ctx.generation < this.#generation || ctx.generation < 1) throw new MusicError('stale');
|
||||
ctx.check(); this.#authority(this.#fence); this.#generation=ctx.generation;
|
||||
|
||||
Reference in new issue
Block a user