@ngxsp/core 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands.d.ts +40 -0
- package/config/default-config.d.ts +34 -0
- package/domain/audio-identification-routine.d.ts +47 -0
- package/domain/audio-identification.d.ts +78 -0
- package/domain/audio-library.d.ts +59 -0
- package/domain/audio-metadata-harmony.d.ts +29 -0
- package/domain/device-playback.d.ts +40 -0
- package/domain/media-item.d.ts +22 -0
- package/domain/media-library-model.d.ts +75 -0
- package/domain/media-source.d.ts +115 -0
- package/domain/queue.d.ts +12 -0
- package/domain/remote-playback.d.ts +82 -0
- package/domain/ringtone.d.ts +46 -0
- package/domain/shake.d.ts +55 -0
- package/domain/vault.d.ts +55 -0
- package/engine/capability-report.d.ts +35 -0
- package/engine/engine-factory.d.ts +19 -0
- package/engine/engine-profile.d.ts +27 -0
- package/engine/native.engine.d.ts +23 -0
- package/engine/native.factory.d.ts +2 -0
- package/engine/playback-capabilities.d.ts +29 -0
- package/engine/playback-engine.d.ts +44 -0
- package/engine/remote-playback.engine.d.ts +77 -0
- package/engine/types.d.ts +15 -0
- package/events/event-bus.d.ts +15 -0
- package/facade/player-facade.d.ts +125 -0
- package/index.d.ts +60 -2491
- package/online/acoustid.d.ts +29 -0
- package/online/cast-v2.d.ts +62 -0
- package/online/dlna-renderer.d.ts +19 -0
- package/online/dlna.d.ts +48 -0
- package/online/internet-archive.d.ts +105 -0
- package/online/jellyfin.d.ts +24 -0
- package/online/lyrics.d.ts +69 -0
- package/online/md5.d.ts +5 -0
- package/online/mdns.d.ts +61 -0
- package/online/media-cache.d.ts +61 -0
- package/online/musicbrainz.d.ts +41 -0
- package/online/online-http.d.ts +10 -0
- package/online/playback-transfer.d.ts +106 -0
- package/online/radio-browser.d.ts +42 -0
- package/online/subsonic.d.ts +16 -0
- package/online/upnp.d.ts +30 -0
- package/online/webdav.d.ts +21 -0
- package/online/xml-text.d.ts +19 -0
- package/package.json +1 -1
- package/plugins/ads/ssai.plugin.d.ts +14 -0
- package/plugins/metadata/metadata.types.d.ts +28 -0
- package/plugins/metadata/providers/local-metadata.provider.d.ts +11 -0
- package/plugins/plugin.d.ts +20 -0
- package/plugins/progress/progress.plugin.d.ts +10 -0
- package/plugins/resilience/resilience.plugin.d.ts +12 -0
- package/plugins/subtitles/providers/local-subtitle.provider.d.ts +9 -0
- package/plugins/subtitles/subtitle-file.d.ts +14 -0
- package/plugins/subtitles/subtitles.types.d.ts +22 -0
- package/ports/http.port.d.ts +3 -0
- package/ports/log.port.d.ts +12 -0
- package/ports/ports.d.ts +14 -0
- package/ports/storage.port.d.ts +11 -0
- package/ports/telemetry.port.d.ts +7 -0
- package/remote-config/remote-config.d.ts +8 -0
- package/telemetry/telemetry.types.d.ts +11 -0
- package/types.d.ts +345 -0
- package/utils/cache-store.d.ts +12 -0
- package/index.d.cts +0 -2491
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type OnlineJsonHttp } from './online-http';
|
|
2
|
+
/** AcoustID open fingerprint database (MIT server, CC BY-SA data). Free application keys for non-commercial use. */
|
|
3
|
+
export declare const ACOUSTID_ORIGIN = "https://api.acoustid.org";
|
|
4
|
+
export interface AcoustIdLookupQuery {
|
|
5
|
+
/** Application key registered at acoustid.org. */
|
|
6
|
+
clientKey: string;
|
|
7
|
+
/** Compressed Chromaprint fingerprint (`AQAB…`). */
|
|
8
|
+
fingerprint: string;
|
|
9
|
+
durationSec: number;
|
|
10
|
+
}
|
|
11
|
+
export interface AcoustIdRequestOptions {
|
|
12
|
+
http?: OnlineJsonHttp;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
origin?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface AcoustIdRecording {
|
|
17
|
+
id: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
artist?: string;
|
|
20
|
+
durationSec?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface AcoustIdResult {
|
|
23
|
+
id: string;
|
|
24
|
+
/** Fingerprint similarity, 0 to 1. */
|
|
25
|
+
score: number;
|
|
26
|
+
recordings: AcoustIdRecording[];
|
|
27
|
+
}
|
|
28
|
+
export declare function buildAcoustIdLookupUrl(query: AcoustIdLookupQuery, origin?: string): string;
|
|
29
|
+
export declare function lookupAcoustId(query: AcoustIdLookupQuery, request?: AcoustIdRequestOptions): Promise<AcoustIdResult[]>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { RemotePlaybackSession } from '../domain/remote-playback';
|
|
2
|
+
/**
|
|
3
|
+
* Chromecast and Cast-enabled speakers and TVs, spoken without Google's SDK: CASTV2 messages (protobuf `CastMessage`
|
|
4
|
+
* frames carrying JSON) over a TLS connection to port 8009. Media plays in the Default Media Receiver, the player
|
|
5
|
+
* every Cast device ships. The apps' native shells open the TLS connection and find devices with mDNS
|
|
6
|
+
* (`CAST_MDNS_SERVICE`); everything else happens here.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CAST_MDNS_SERVICE = "_googlecast._tcp";
|
|
9
|
+
export declare const CAST_PORT = 8009;
|
|
10
|
+
export declare const CAST_DEFAULT_MEDIA_RECEIVER = "CC1AD845";
|
|
11
|
+
/** The type to send a media to a Cast receiver with, or the format it cannot read. */
|
|
12
|
+
export declare function castContentType(contentType: string): {
|
|
13
|
+
contentType: string;
|
|
14
|
+
} | {
|
|
15
|
+
unsupported: string;
|
|
16
|
+
};
|
|
17
|
+
/** A Cast device found on the network. */
|
|
18
|
+
export interface CastDeviceInfo {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
model?: string;
|
|
22
|
+
address: string;
|
|
23
|
+
port: number;
|
|
24
|
+
/** Speakers and speaker groups have no screen. */
|
|
25
|
+
video: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** Cast devices in the answers to an mDNS question for `CAST_MDNS_SERVICE`, one per device id. */
|
|
28
|
+
export declare function castDevicesFromMdns(answers: ReadonlyArray<{
|
|
29
|
+
from?: string;
|
|
30
|
+
bytes: Uint8Array;
|
|
31
|
+
}>): CastDeviceInfo[];
|
|
32
|
+
/** A TLS connection to a Cast device, opened by the native shell. */
|
|
33
|
+
export interface CastSocket {
|
|
34
|
+
send(frame: Uint8Array): void | Promise<void>;
|
|
35
|
+
onData(listener: (chunk: Uint8Array) => void): () => void;
|
|
36
|
+
onClose(listener: (reason?: string) => void): () => void;
|
|
37
|
+
close(): void;
|
|
38
|
+
}
|
|
39
|
+
export interface CastMessage {
|
|
40
|
+
sourceId: string;
|
|
41
|
+
destinationId: string;
|
|
42
|
+
namespace: string;
|
|
43
|
+
payload: string;
|
|
44
|
+
}
|
|
45
|
+
export interface CastSessionOptions {
|
|
46
|
+
appId?: string;
|
|
47
|
+
senderId?: string;
|
|
48
|
+
requestTimeoutMs?: number;
|
|
49
|
+
/** How long a LOAD may take: a receiver that has just started loads its player first (over 10 s on a TV). */
|
|
50
|
+
loadTimeoutMs?: number;
|
|
51
|
+
/** Interval of the keep-alive PING; 0 disables it (tests). */
|
|
52
|
+
heartbeatMs?: number;
|
|
53
|
+
}
|
|
54
|
+
/** One length-prefixed protobuf `CastMessage` with a UTF-8 payload. */
|
|
55
|
+
export declare function encodeCastMessage(message: CastMessage): Uint8Array;
|
|
56
|
+
/** Splits received bytes into messages; returns the messages and the bytes of an incomplete frame. */
|
|
57
|
+
export declare function decodeCastFrames(buffer: Uint8Array): {
|
|
58
|
+
messages: CastMessage[];
|
|
59
|
+
rest: Uint8Array;
|
|
60
|
+
};
|
|
61
|
+
/** Connects to the device; media is sent with `load`, which starts the Default Media Receiver when needed. */
|
|
62
|
+
export declare function createCastSession(socket: CastSocket, options?: CastSessionOptions): RemotePlaybackSession;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { MediaSourceHttp } from '../domain/media-source';
|
|
2
|
+
import { type RemotePlaybackSession } from '../domain/remote-playback';
|
|
3
|
+
import { type UpnpService } from './upnp';
|
|
4
|
+
/**
|
|
5
|
+
* UPnP AV / DLNA renderers (smart TVs, network speakers, Kodi, gmrender): media is handed over with AVTransport
|
|
6
|
+
* `SetAVTransportURI` and driven with `Play`, `Pause`, `Seek` and `Stop`; RenderingControl sets the volume. Renderers
|
|
7
|
+
* fetch the media themselves, over plain HTTP.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DLNA_MEDIA_RENDERER_SEARCH_TARGET = "urn:schemas-upnp-org:device:MediaRenderer:1";
|
|
10
|
+
export interface DlnaRendererInfo {
|
|
11
|
+
name: string;
|
|
12
|
+
udn?: string;
|
|
13
|
+
modelName?: string;
|
|
14
|
+
avTransport: UpnpService;
|
|
15
|
+
renderingControl?: UpnpService;
|
|
16
|
+
}
|
|
17
|
+
/** Reads a renderer's description; devices without AVTransport cannot play what they are sent. */
|
|
18
|
+
export declare function readDlnaRenderer(descriptionUrl: string, http: MediaSourceHttp): Promise<DlnaRendererInfo>;
|
|
19
|
+
export declare function createDlnaRendererSession(descriptionUrl: string, http: MediaSourceHttp): Promise<RemotePlaybackSession>;
|
package/online/dlna.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type MediaSourceAccount, type MediaSourceBrowseOptions, type MediaSourceConnector, type MediaSourceHttp, type MediaSourceInput, type MediaSourcePage } from '../domain/media-source';
|
|
2
|
+
/**
|
|
3
|
+
* UPnP AV / DLNA media servers (ReadyMedia/MiniDLNA, Gerbera, Kodi, Jellyfin's DLNA plugin, most NAS): the device
|
|
4
|
+
* description names the server and its ContentDirectory service, which is browsed with SOAP `Browse` requests that
|
|
5
|
+
* answer DIDL-Lite documents. Files are served over plain HTTP without credentials.
|
|
6
|
+
*
|
|
7
|
+
* Servers answer neither web pages (no CORS) nor discovery from a browser: applications find them with SSDP through
|
|
8
|
+
* their native shell, using `DLNA_MEDIA_SERVER_SEARCH_TARGET`, or take the address of the description document.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DLNA_MEDIA_SERVER_SEARCH_TARGET = "urn:schemas-upnp-org:device:MediaServer:1";
|
|
11
|
+
export interface DidlResource {
|
|
12
|
+
url: string;
|
|
13
|
+
mimeType?: string;
|
|
14
|
+
durationSec?: number;
|
|
15
|
+
size?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface DidlObject {
|
|
18
|
+
id: string;
|
|
19
|
+
parentId?: string;
|
|
20
|
+
container: boolean;
|
|
21
|
+
title: string;
|
|
22
|
+
upnpClass: string;
|
|
23
|
+
childCount?: number;
|
|
24
|
+
artists: Array<{
|
|
25
|
+
name: string;
|
|
26
|
+
role?: string;
|
|
27
|
+
}>;
|
|
28
|
+
creator?: string;
|
|
29
|
+
album?: string;
|
|
30
|
+
genre?: string;
|
|
31
|
+
date?: string;
|
|
32
|
+
trackNo?: number;
|
|
33
|
+
artworkUrl?: string;
|
|
34
|
+
seriesTitle?: string;
|
|
35
|
+
season?: number;
|
|
36
|
+
episode?: number;
|
|
37
|
+
resources: DidlResource[];
|
|
38
|
+
}
|
|
39
|
+
export declare function createDlnaConnector(): MediaSourceConnector;
|
|
40
|
+
/** Reads the device description (typed, or found on the network) and checks the device serves media. */
|
|
41
|
+
export declare function connectDlna(input: MediaSourceInput, http: MediaSourceHttp): Promise<MediaSourceAccount>;
|
|
42
|
+
/**
|
|
43
|
+
* Children of a container, the root when none is given. Folders come first, then the files the app plays; a search
|
|
44
|
+
* asks the server for matching titles when it supports it.
|
|
45
|
+
*/
|
|
46
|
+
export declare function browseDlna(account: MediaSourceAccount, options: MediaSourceBrowseOptions, http: MediaSourceHttp): Promise<MediaSourcePage>;
|
|
47
|
+
/** Containers and items of a DIDL-Lite document, with relative links resolved against `baseUrl`. */
|
|
48
|
+
export declare function parseDidlLite(xml: string, baseUrl: string): DidlObject[];
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type OnlineJsonHttp } from './online-http';
|
|
2
|
+
/** Internet Archive public APIs: advanced search, item metadata and file downloads. No key required. */
|
|
3
|
+
export declare const INTERNET_ARCHIVE_ORIGIN = "https://archive.org";
|
|
4
|
+
export type InternetArchiveMediaType = 'movies' | 'audio';
|
|
5
|
+
export interface InternetArchiveRequestOptions {
|
|
6
|
+
/** Defaults to plain `fetch`. */
|
|
7
|
+
http?: OnlineJsonHttp;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
origin?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface InternetArchiveSearchOptions {
|
|
12
|
+
mediaType: InternetArchiveMediaType;
|
|
13
|
+
/** Extra Lucene clauses joined with AND, e.g. `collection:(prelinger)`. */
|
|
14
|
+
filters?: readonly string[];
|
|
15
|
+
/** Free text matched against title, creator and subject. */
|
|
16
|
+
text?: string;
|
|
17
|
+
rows?: number;
|
|
18
|
+
page?: number;
|
|
19
|
+
/** Defaults to the most downloaded items first. */
|
|
20
|
+
sort?: string;
|
|
21
|
+
origin?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface InternetArchiveSearchItem {
|
|
24
|
+
identifier: string;
|
|
25
|
+
title: string;
|
|
26
|
+
creator?: string;
|
|
27
|
+
year?: number;
|
|
28
|
+
licenseUrl?: string;
|
|
29
|
+
thumbnailUrl: string;
|
|
30
|
+
detailsUrl: string;
|
|
31
|
+
}
|
|
32
|
+
export interface InternetArchiveSearchResult {
|
|
33
|
+
total: number;
|
|
34
|
+
page: number;
|
|
35
|
+
items: InternetArchiveSearchItem[];
|
|
36
|
+
}
|
|
37
|
+
export interface InternetArchiveFile {
|
|
38
|
+
name: string;
|
|
39
|
+
format?: string;
|
|
40
|
+
source?: string;
|
|
41
|
+
/** For derivatives, the name of the file they were generated from. */
|
|
42
|
+
original?: string;
|
|
43
|
+
title?: string;
|
|
44
|
+
creator?: string;
|
|
45
|
+
album?: string;
|
|
46
|
+
track?: string;
|
|
47
|
+
length?: string;
|
|
48
|
+
size?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface InternetArchiveItem {
|
|
51
|
+
identifier: string;
|
|
52
|
+
title: string;
|
|
53
|
+
creator?: string;
|
|
54
|
+
year?: number;
|
|
55
|
+
description?: string;
|
|
56
|
+
licenseUrl?: string;
|
|
57
|
+
/** Lending, stream-only or dark items cannot be played from their download URLs. */
|
|
58
|
+
restricted: boolean;
|
|
59
|
+
thumbnailUrl: string;
|
|
60
|
+
detailsUrl: string;
|
|
61
|
+
/**
|
|
62
|
+
* Storage servers holding the item (`https://<server>/<dir>`). `/download` redirects to a nearby mirror that may omit
|
|
63
|
+
* CORS headers; these servers send them, so apps download files from here and keep `/download` for streaming.
|
|
64
|
+
*/
|
|
65
|
+
storageUrls: string[];
|
|
66
|
+
files: InternetArchiveFile[];
|
|
67
|
+
}
|
|
68
|
+
export interface InternetArchiveVideoSource {
|
|
69
|
+
fileName: string;
|
|
70
|
+
format: string;
|
|
71
|
+
url: string;
|
|
72
|
+
/** Same file on the item's storage servers, readable with `fetch` from other origins. */
|
|
73
|
+
storageUrls: string[];
|
|
74
|
+
durationSec?: number;
|
|
75
|
+
}
|
|
76
|
+
export interface InternetArchiveAudioTrack {
|
|
77
|
+
/** `<identifier>/<file name>`, unique across the archive. */
|
|
78
|
+
id: string;
|
|
79
|
+
identifier: string;
|
|
80
|
+
fileName: string;
|
|
81
|
+
title: string;
|
|
82
|
+
artist?: string;
|
|
83
|
+
album: string;
|
|
84
|
+
trackNo?: number;
|
|
85
|
+
durationSec?: number;
|
|
86
|
+
url: string;
|
|
87
|
+
/** Same file on the item's storage servers, readable with `fetch` from other origins. */
|
|
88
|
+
storageUrls: string[];
|
|
89
|
+
artworkUrl: string;
|
|
90
|
+
}
|
|
91
|
+
/** Clauses that keep results playable without an account. */
|
|
92
|
+
export declare const INTERNET_ARCHIVE_PLAYABLE_FILTERS: readonly string[];
|
|
93
|
+
export declare function buildInternetArchiveSearchUrl(options: InternetArchiveSearchOptions): string;
|
|
94
|
+
export declare function searchInternetArchive(options: InternetArchiveSearchOptions, request?: InternetArchiveRequestOptions): Promise<InternetArchiveSearchResult>;
|
|
95
|
+
export declare function fetchInternetArchiveItem(identifier: string, request?: InternetArchiveRequestOptions): Promise<InternetArchiveItem>;
|
|
96
|
+
export declare function parseInternetArchiveItem(identifier: string, body: unknown, origin?: string): InternetArchiveItem;
|
|
97
|
+
/** Picks the most widely playable video derivative of an item. */
|
|
98
|
+
export declare function selectInternetArchiveVideo(item: InternetArchiveItem, origin?: string): InternetArchiveVideoSource | null;
|
|
99
|
+
/** Tracks of an audio item, using a single format so derivatives are not listed twice. */
|
|
100
|
+
export declare function internetArchiveAudioTracks(item: InternetArchiveItem, origin?: string): InternetArchiveAudioTrack[];
|
|
101
|
+
export declare function internetArchiveDownloadUrl(identifier: string, fileName: string, origin?: string): string;
|
|
102
|
+
export declare function internetArchiveThumbnailUrl(identifier: string, origin?: string): string;
|
|
103
|
+
export declare function internetArchiveDetailsUrl(identifier: string, origin?: string): string;
|
|
104
|
+
/** Accepts `240.9` seconds as well as `02:31` or `1:31:44`. */
|
|
105
|
+
export declare function parseInternetArchiveLength(length: string | undefined): number | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type MediaSourceAccount, type MediaSourceBrowseOptions, type MediaSourceConnector, type MediaSourceHttp, type MediaSourceInput, type MediaSourceItem, type MediaSourcePage } from '../domain/media-source';
|
|
2
|
+
/**
|
|
3
|
+
* Jellyfin, the free software home media server (GPL). One account gives music and videos with their covers,
|
|
4
|
+
* artists, series and seasons; files are played as they are stored, so seeking works through byte ranges.
|
|
5
|
+
*/
|
|
6
|
+
export declare const JELLYFIN_CLIENT: {
|
|
7
|
+
readonly name: "NGXSP";
|
|
8
|
+
readonly version: "1.0.0";
|
|
9
|
+
};
|
|
10
|
+
export declare function createJellyfinConnector(deviceId?: string): MediaSourceConnector;
|
|
11
|
+
/** Signs in and keeps the access token the server issues; the password is not stored. */
|
|
12
|
+
export declare function connectJellyfin(input: MediaSourceInput, http: MediaSourceHttp, deviceId?: string): Promise<MediaSourceAccount>;
|
|
13
|
+
/** Libraries at the root, then albums, series and seasons, then the files they hold. */
|
|
14
|
+
export declare function browseJellyfin(account: MediaSourceAccount, options: MediaSourceBrowseOptions, http: MediaSourceHttp): Promise<MediaSourcePage>;
|
|
15
|
+
/**
|
|
16
|
+
* Lyrics stored next to the track on the server (Jellyfin 10.9 and later). Timed lines come back as ticks of a
|
|
17
|
+
* hundred nanoseconds and are written as LRC, so the player reads them with its own parser.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readJellyfinLyrics(account: MediaSourceAccount, item: MediaSourceItem, http: MediaSourceHttp): Promise<string | null>;
|
|
20
|
+
/** Plays the file as stored on the server; the browser asks for the byte ranges it needs. */
|
|
21
|
+
export declare function jellyfinStreamUrl(account: MediaSourceAccount, itemId: string, kind: 'audio' | 'video'): string;
|
|
22
|
+
export declare function jellyfinImageUrl(account: MediaSourceAccount, itemId: string, tag?: string, maxHeight?: number): string;
|
|
23
|
+
export declare function jellyfinClientHeader(deviceId: string, token?: string): string;
|
|
24
|
+
export declare function parseJellyfinItem(account: MediaSourceAccount, entry: unknown, kind: 'audio' | 'video'): MediaSourceItem | null;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type OnlineJsonHttp } from './online-http';
|
|
2
|
+
/**
|
|
3
|
+
* Lyrics of a track, timed or plain. They come from the file itself (tags), from an `.lrc` file beside it, or from
|
|
4
|
+
* LRCLIB, an open lyrics database (no key, no account). Timed lines let the player follow the words while it plays.
|
|
5
|
+
*/
|
|
6
|
+
export declare const LRCLIB_ORIGIN = "https://lrclib.net";
|
|
7
|
+
export type LyricsSource = 'tags' | 'file' | 'lrclib';
|
|
8
|
+
export interface LyricsLine {
|
|
9
|
+
/** Start of the line in the track. */
|
|
10
|
+
timeSec: number;
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
export interface Lyrics {
|
|
14
|
+
source: LyricsSource;
|
|
15
|
+
/** Timed lines, when the source has them. */
|
|
16
|
+
lines?: LyricsLine[];
|
|
17
|
+
/** The whole text, always present when anything was found. */
|
|
18
|
+
plain: string;
|
|
19
|
+
/** What the source says it is, to show which version was picked. */
|
|
20
|
+
title?: string;
|
|
21
|
+
artist?: string;
|
|
22
|
+
/** LRCLIB record, to fetch it again or report a wrong match. */
|
|
23
|
+
id?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface LyricsQuery {
|
|
26
|
+
title: string;
|
|
27
|
+
artist?: string;
|
|
28
|
+
album?: string;
|
|
29
|
+
durationSec?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface LyricsRequestOptions {
|
|
32
|
+
/** Defaults to plain `fetch`; apps plug their HTTP client (cache, retries). */
|
|
33
|
+
http?: OnlineJsonHttp;
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
origin?: string;
|
|
36
|
+
}
|
|
37
|
+
/** `[mm:ss.xx]` lines, `[offset:±ms]` and the usual `[ti:]`/`[ar:]` tags; text without timestamps stays plain. */
|
|
38
|
+
export declare function parseLrc(text: string, source?: LyricsSource): Lyrics | null;
|
|
39
|
+
/** Lyrics tags of a file (ID3 USLT/SYLT, Vorbis LYRICS), as music-metadata reports them. */
|
|
40
|
+
export interface TaggedLyrics {
|
|
41
|
+
text?: string;
|
|
42
|
+
syncText?: Array<{
|
|
43
|
+
text?: string;
|
|
44
|
+
timestamp?: number;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
/** Lyrics carried by the file itself; timed words win over a plain block. */
|
|
48
|
+
export declare function lyricsFromTags(tags: readonly TaggedLyrics[] | TaggedLyrics | undefined | null): Lyrics | null;
|
|
49
|
+
/** Index of the line being sung at this position, or -1 before the first one. */
|
|
50
|
+
export declare function lyricsLineIndexAt(lines: readonly LyricsLine[] | undefined, positionSec: number): number;
|
|
51
|
+
interface LrclibRecord {
|
|
52
|
+
id?: number;
|
|
53
|
+
trackName?: string;
|
|
54
|
+
artistName?: string;
|
|
55
|
+
duration?: number;
|
|
56
|
+
instrumental?: boolean;
|
|
57
|
+
plainLyrics?: string | null;
|
|
58
|
+
syncedLyrics?: string | null;
|
|
59
|
+
}
|
|
60
|
+
export declare function buildLrclibGetUrl(query: LyricsQuery, origin?: string): string;
|
|
61
|
+
export declare function buildLrclibSearchUrl(query: LyricsQuery, origin?: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Lyrics for a track from LRCLIB: the exact record when the track, artist, album and duration match, otherwise the
|
|
64
|
+
* closest of the search results. Returns null when the database has nothing, and for instrumental tracks.
|
|
65
|
+
*/
|
|
66
|
+
export declare function fetchLrclibLyrics(query: LyricsQuery, options?: LyricsRequestOptions): Promise<Lyrics | null>;
|
|
67
|
+
/** Closest record: a duration within 5 seconds first, then the title and artist that look most alike. */
|
|
68
|
+
export declare function bestLrclibMatch(records: readonly LrclibRecord[], query: LyricsQuery): LrclibRecord | null;
|
|
69
|
+
export {};
|
package/online/md5.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MD5 of a UTF-8 string, as lowercase hex (RFC 1321). Only for protocols that require it, such as Subsonic request
|
|
3
|
+
* signing; never as a security primitive of its own. WebCrypto does not offer MD5, hence this implementation.
|
|
4
|
+
*/
|
|
5
|
+
export declare function md5Hex(input: string): string;
|
package/online/mdns.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Just enough DNS for mDNS service discovery (RFC 6762/6763): a PTR question for a service type, and the PTR, SRV,
|
|
3
|
+
* TXT and A records devices answer with. Apps send the question from an ordinary UDP port to 224.0.0.251:5353
|
|
4
|
+
* ("legacy unicast" query), so devices answer that port directly and no process has to share port 5353. An app that
|
|
5
|
+
* advertises a service of its own reads the questions (`parseMdnsQuestions`) and answers them (`encodeMdnsResponse`).
|
|
6
|
+
*/
|
|
7
|
+
export declare const MDNS_ADDRESS = "224.0.0.251";
|
|
8
|
+
export declare const MDNS_PORT = 5353;
|
|
9
|
+
export type MdnsRecord = {
|
|
10
|
+
type: 'PTR';
|
|
11
|
+
name: string;
|
|
12
|
+
target: string;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'SRV';
|
|
15
|
+
name: string;
|
|
16
|
+
target: string;
|
|
17
|
+
port: number;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'TXT';
|
|
20
|
+
name: string;
|
|
21
|
+
entries: Record<string, string>;
|
|
22
|
+
} | {
|
|
23
|
+
type: 'A';
|
|
24
|
+
name: string;
|
|
25
|
+
address: string;
|
|
26
|
+
};
|
|
27
|
+
/** A service instance put together from the records of one or more answers. */
|
|
28
|
+
export interface MdnsService {
|
|
29
|
+
/** Full instance name, e.g. `Kitchen._googlecast._tcp.local`. */
|
|
30
|
+
instance: string;
|
|
31
|
+
host?: string;
|
|
32
|
+
address?: string;
|
|
33
|
+
port?: number;
|
|
34
|
+
txt: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
/** A PTR question for a service type (`_googlecast._tcp.local`). */
|
|
37
|
+
export declare function encodeMdnsQuery(serviceType: string, id?: number): Uint8Array;
|
|
38
|
+
/** The questions of a DNS query (not of a response); malformed messages give none. */
|
|
39
|
+
export declare function parseMdnsQuestions(bytes: Uint8Array): Array<{
|
|
40
|
+
name: string;
|
|
41
|
+
type: number;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* A response carrying `records`: what a service advertises (PTR to its instance, SRV, TXT, A). `ttl` 0 says goodbye.
|
|
45
|
+
* `id` and `question` echo a legacy unicast query, which expects them back.
|
|
46
|
+
*/
|
|
47
|
+
export declare function encodeMdnsResponse(records: readonly MdnsRecord[], options?: {
|
|
48
|
+
id?: number;
|
|
49
|
+
ttl?: number;
|
|
50
|
+
question?: {
|
|
51
|
+
name: string;
|
|
52
|
+
type: number;
|
|
53
|
+
};
|
|
54
|
+
}): Uint8Array;
|
|
55
|
+
/** Answer and additional records of a DNS message; malformed messages give no records. */
|
|
56
|
+
export declare function parseMdnsMessage(bytes: Uint8Array): MdnsRecord[];
|
|
57
|
+
/** Instances of a service type found in a set of answers, with their port, TXT entries and IPv4 address. */
|
|
58
|
+
export declare function mdnsServices(serviceType: string, answers: ReadonlyArray<{
|
|
59
|
+
from?: string;
|
|
60
|
+
bytes: Uint8Array;
|
|
61
|
+
}>): MdnsService[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local copies of online media (Internet Archive tracks): instant starts, seamless queue transitions and playback
|
|
3
|
+
* through network drops. Downloads run one at a time in the background and the cache stays under a byte budget by
|
|
4
|
+
* evicting the least recently used copies, never the ones the queue still needs.
|
|
5
|
+
*/
|
|
6
|
+
export interface MediaCacheEntry {
|
|
7
|
+
key: string;
|
|
8
|
+
url: string;
|
|
9
|
+
size: number;
|
|
10
|
+
contentType: string;
|
|
11
|
+
storedAt: number;
|
|
12
|
+
lastUsedAt: number;
|
|
13
|
+
}
|
|
14
|
+
/** Persistence of cached media; browsers implement it with IndexedDB. */
|
|
15
|
+
export interface MediaCacheStore {
|
|
16
|
+
entries(): Promise<MediaCacheEntry[]>;
|
|
17
|
+
read(key: string): Promise<Blob | null>;
|
|
18
|
+
write(entry: MediaCacheEntry, data: Blob): Promise<void>;
|
|
19
|
+
touch(key: string, lastUsedAt: number): Promise<void>;
|
|
20
|
+
remove(keys: readonly string[]): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export interface MediaCacheRequest {
|
|
23
|
+
key: string;
|
|
24
|
+
url: string;
|
|
25
|
+
/** Tried in order when `url` cannot be downloaded (network, HTTP or CORS failure). */
|
|
26
|
+
alternateUrls?: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
export interface MediaCacheUsage {
|
|
29
|
+
bytes: number;
|
|
30
|
+
count: number;
|
|
31
|
+
budgetBytes: number;
|
|
32
|
+
}
|
|
33
|
+
export interface MediaCacheOptions {
|
|
34
|
+
store: MediaCacheStore;
|
|
35
|
+
budgetBytes: number;
|
|
36
|
+
/** Larger media are streamed only. Defaults to a quarter of the budget. */
|
|
37
|
+
maxEntryBytes?: number;
|
|
38
|
+
fetch?: typeof fetch;
|
|
39
|
+
now?: () => number;
|
|
40
|
+
/** Background downloads wait while this returns false (data saver, slow connection). */
|
|
41
|
+
canDownload?: () => boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface MediaCache {
|
|
44
|
+
/** Resolves once the stored index is loaded; `has` answers false before. */
|
|
45
|
+
readonly ready: Promise<void>;
|
|
46
|
+
has(key: string): boolean;
|
|
47
|
+
/** The local copy, marked as recently used; null when absent or unreadable. */
|
|
48
|
+
open(key: string): Promise<Blob | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Media the player needs next, most urgent first. Missing ones are downloaded in that order; a download no longer
|
|
51
|
+
* requested is cancelled. Requested keys are protected from eviction until the next call.
|
|
52
|
+
*/
|
|
53
|
+
keep(requests: readonly MediaCacheRequest[]): void;
|
|
54
|
+
usage(): MediaCacheUsage;
|
|
55
|
+
clear(): Promise<void>;
|
|
56
|
+
/** Called after downloads, evictions and clears. */
|
|
57
|
+
onChange(listener: () => void): () => void;
|
|
58
|
+
}
|
|
59
|
+
/** Keys to evict, least recently used first, so that `incomingBytes` fits in the budget; null when it cannot fit. */
|
|
60
|
+
export declare function planMediaCacheEviction(entries: readonly MediaCacheEntry[], budgetBytes: number, incomingBytes: number, protectedKeys?: ReadonlySet<string>): string[] | null;
|
|
61
|
+
export declare function createMediaCache(options: MediaCacheOptions): MediaCache;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type OnlineJsonHttp } from './online-http';
|
|
2
|
+
/** MusicBrainz open music encyclopedia (GPL server, CC0 core data). No key; one request per second per client. */
|
|
3
|
+
export declare const MUSICBRAINZ_ORIGIN = "https://musicbrainz.org";
|
|
4
|
+
export interface MusicBrainzRecordingQuery {
|
|
5
|
+
title: string;
|
|
6
|
+
artist?: string;
|
|
7
|
+
durationSec?: number;
|
|
8
|
+
/** Tolerance around `durationSec`, in seconds. */
|
|
9
|
+
durationToleranceSec?: number;
|
|
10
|
+
limit?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface MusicBrainzRequestOptions {
|
|
13
|
+
/** Defaults to plain `fetch`; desktop shells should send a descriptive User-Agent and rate limit requests. */
|
|
14
|
+
http?: OnlineJsonHttp;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
origin?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface MusicBrainzRelease {
|
|
19
|
+
id: string;
|
|
20
|
+
title: string;
|
|
21
|
+
artist?: string;
|
|
22
|
+
status?: string;
|
|
23
|
+
primaryType?: string;
|
|
24
|
+
year?: number;
|
|
25
|
+
discNo?: number;
|
|
26
|
+
trackNo?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface MusicBrainzRecording {
|
|
29
|
+
id: string;
|
|
30
|
+
/** Search relevance, 0 to 100. */
|
|
31
|
+
score: number;
|
|
32
|
+
title: string;
|
|
33
|
+
artist?: string;
|
|
34
|
+
durationSec?: number;
|
|
35
|
+
releases: MusicBrainzRelease[];
|
|
36
|
+
}
|
|
37
|
+
export declare function buildMusicBrainzRecordingSearchUrl(query: MusicBrainzRecordingQuery, origin?: string): string;
|
|
38
|
+
export declare function searchMusicBrainzRecordings(query: MusicBrainzRecordingQuery, request?: MusicBrainzRequestOptions): Promise<MusicBrainzRecording[]>;
|
|
39
|
+
/** Recording details by MusicBrainz id, with its releases, release groups and track positions. */
|
|
40
|
+
export declare function lookupMusicBrainzRecording(id: string, request?: MusicBrainzRequestOptions): Promise<MusicBrainzRecording | null>;
|
|
41
|
+
export declare function parseMusicBrainzRecording(entry: unknown): MusicBrainzRecording | null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport used by the online catalogs: resolves a JSON document or throws.
|
|
3
|
+
* Applications plug their HTTP client here (cache, retries, telemetry); the default uses `fetch`.
|
|
4
|
+
*/
|
|
5
|
+
export interface OnlineJsonHttp {
|
|
6
|
+
getJson(url: string, options?: {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}): Promise<unknown>;
|
|
9
|
+
}
|
|
10
|
+
export declare function createFetchOnlineJsonHttp(fetchFn?: typeof fetch): OnlineJsonHttp;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { MediaSourceHttp } from '../domain/media-source';
|
|
2
|
+
import { type MdnsRecord } from './mdns';
|
|
3
|
+
/**
|
|
4
|
+
* Playback transfer between NGXSP apps of a local network: an app hands what it plays (the queue, the item, the
|
|
5
|
+
* position) to another app of the same kind, which carries on from there.
|
|
6
|
+
*
|
|
7
|
+
* - Apps advertise themselves over mDNS as `_ngxsp._tcp` services; TXT entries say which app they are.
|
|
8
|
+
* - The sender POSTs a `PlaybackTransfer` to `/ngxsp/transfer` on the receiver. Its media addresses are ones the
|
|
9
|
+
* receiver can fetch: web addresses as they are, the sender's own media shared on the network.
|
|
10
|
+
* - The first transfer from an app asks on the receiving device (refuse or allow). Allowed, the sender gets a token
|
|
11
|
+
* it presents from then on, and later transfers go through without asking ("accept once").
|
|
12
|
+
*/
|
|
13
|
+
export declare const NGXSP_SERVICE_TYPE = "_ngxsp._tcp.local";
|
|
14
|
+
export declare const PLAYBACK_TRANSFER_PATH = "/ngxsp/transfer";
|
|
15
|
+
export declare const PLAYBACK_TRANSFER_VERSION = 1;
|
|
16
|
+
/** How long the receiving device waits for its user to answer. */
|
|
17
|
+
export declare const PLAYBACK_TRANSFER_PROMPT_MS = 60000;
|
|
18
|
+
export type NgxspAppKind = 'audio' | 'video';
|
|
19
|
+
/** An NGXSP app as the others know it. */
|
|
20
|
+
export interface NgxspAppIdentity {
|
|
21
|
+
/** Random, kept by the app for good. */
|
|
22
|
+
id: string;
|
|
23
|
+
/** The device's name, as its user knows it. */
|
|
24
|
+
name: string;
|
|
25
|
+
app: NgxspAppKind;
|
|
26
|
+
}
|
|
27
|
+
/** Another NGXSP app of the network. */
|
|
28
|
+
export interface NgxspPeer extends NgxspAppIdentity {
|
|
29
|
+
address: string;
|
|
30
|
+
port: number;
|
|
31
|
+
}
|
|
32
|
+
export interface PlaybackTransferItem {
|
|
33
|
+
url: string;
|
|
34
|
+
title: string;
|
|
35
|
+
artist?: string;
|
|
36
|
+
album?: string;
|
|
37
|
+
artworkUrl?: string;
|
|
38
|
+
durationSec?: number;
|
|
39
|
+
/** Radios and live streams. */
|
|
40
|
+
live?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface PlaybackTransfer {
|
|
43
|
+
version: number;
|
|
44
|
+
from: NgxspAppIdentity;
|
|
45
|
+
items: PlaybackTransferItem[];
|
|
46
|
+
/** The item playing, in `items`. */
|
|
47
|
+
index: number;
|
|
48
|
+
positionSec: number;
|
|
49
|
+
playing: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface TrustedSender {
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
/** SHA-256 of the token the sender presents, in hex. */
|
|
55
|
+
tokenHash: string;
|
|
56
|
+
since: number;
|
|
57
|
+
}
|
|
58
|
+
export type PlaybackTransferOutcome = {
|
|
59
|
+
accepted: true;
|
|
60
|
+
token?: string;
|
|
61
|
+
} | {
|
|
62
|
+
accepted: false;
|
|
63
|
+
reason: 'refused' | 'busy' | 'timeout' | 'disabled' | 'other-app' | 'invalid' | 'unreachable';
|
|
64
|
+
};
|
|
65
|
+
/** The TXT entries an app advertises. */
|
|
66
|
+
export declare function ngxspTxt(identity: NgxspAppIdentity): Record<string, string>;
|
|
67
|
+
/** The records an app answers `_ngxsp._tcp` questions with, for each of its addresses. */
|
|
68
|
+
export declare function ngxspServiceRecords(identity: NgxspAppIdentity, port: number, addresses: readonly string[]): MdnsRecord[];
|
|
69
|
+
/** NGXSP apps of kind `app` found in mDNS answers, this one aside. */
|
|
70
|
+
export declare function ngxspPeersFromMdns(answers: ReadonlyArray<{
|
|
71
|
+
from?: string;
|
|
72
|
+
bytes: Uint8Array;
|
|
73
|
+
}>, self: Pick<NgxspAppIdentity, 'id' | 'app'>): NgxspPeer[];
|
|
74
|
+
/** A transfer as received, checked and trimmed; null when it is not one. */
|
|
75
|
+
export declare function readPlaybackTransfer(value: unknown): PlaybackTransfer | null;
|
|
76
|
+
export interface PlaybackTransferReceiverOptions {
|
|
77
|
+
app: NgxspAppKind;
|
|
78
|
+
/** Off, the app refuses every transfer without asking. */
|
|
79
|
+
enabled: () => boolean;
|
|
80
|
+
trusted: () => readonly TrustedSender[];
|
|
81
|
+
saveTrusted: (senders: TrustedSender[]) => void;
|
|
82
|
+
/** Asks the user whether `from` may send its playback here: true to allow. */
|
|
83
|
+
ask: (from: NgxspAppIdentity) => Promise<boolean>;
|
|
84
|
+
/** Plays what was transferred. */
|
|
85
|
+
apply: (transfer: PlaybackTransfer) => void;
|
|
86
|
+
sha256Hex: (value: string) => Promise<string>;
|
|
87
|
+
randomToken: () => string;
|
|
88
|
+
promptMs?: number;
|
|
89
|
+
}
|
|
90
|
+
/** A transfer request as the app's HTTP endpoint hands it over, and what it answers. */
|
|
91
|
+
export interface PlaybackTransferRequest {
|
|
92
|
+
method: string;
|
|
93
|
+
body: string;
|
|
94
|
+
/** The `Authorization` header: `NGXSP <token>` from a sender allowed before. */
|
|
95
|
+
authorization?: string;
|
|
96
|
+
}
|
|
97
|
+
export interface PlaybackTransferResponse {
|
|
98
|
+
status: number;
|
|
99
|
+
body: Record<string, unknown>;
|
|
100
|
+
}
|
|
101
|
+
/** Decides on the transfers an app receives, asking its user the first time an app sends one. */
|
|
102
|
+
export declare function createPlaybackTransferReceiver(options: PlaybackTransferReceiverOptions): {
|
|
103
|
+
handle: (request: PlaybackTransferRequest) => Promise<PlaybackTransferResponse>;
|
|
104
|
+
};
|
|
105
|
+
/** Sends a transfer to a peer, with the token it gave the last time if there is one. */
|
|
106
|
+
export declare function sendPlaybackTransfer(http: MediaSourceHttp, peer: Pick<NgxspPeer, 'address' | 'port'>, transfer: PlaybackTransfer, token?: string): Promise<PlaybackTransferOutcome>;
|