Skip to content

Commit

Permalink
feat(apple): Reworked apple POC
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Dec 27, 2023
1 parent db4e64d commit 8be218a
Show file tree
Hide file tree
Showing 17 changed files with 779 additions and 18 deletions.
117 changes: 117 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"lastfm-node-client": "^2.2.0",
"mopidy": "^1.3.0",
"nanoid": "^3.3.1",
"node-musickit-api": "^2.1.1",
"normalize-url": "^6.1.0",
"ntfy": "1.0.5",
"object-hash": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/backend/common/infrastructure/Atomic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {Request, Response} from "express";
import {NextFunction, ParamsDictionary, Query} from "express-serve-static-core";
import {LogLevel, logLevels, PlayMeta, PlayObject} from "../../../core/Atomic";

export type SourceType = 'spotify' | 'plex' | 'tautulli' | 'subsonic' | 'jellyfin' | 'lastfm' | 'deezer' | 'ytmusic' | 'mpris' | 'mopidy' | 'listenbrainz' | 'jriver' | 'kodi' | 'webscrobbler';
export const sourceTypes: SourceType[] = ['spotify', 'plex', 'tautulli', 'subsonic', 'jellyfin', 'lastfm', 'deezer', 'ytmusic', 'mpris', 'mopidy', 'listenbrainz', 'jriver', 'kodi', 'webscrobbler'];
export type SourceType = 'apple' | 'spotify' | 'plex' | 'tautulli' | 'subsonic' | 'jellyfin' | 'lastfm' | 'deezer' | 'ytmusic' | 'mpris' | 'mopidy' | 'listenbrainz' | 'jriver' | 'kodi' | 'webscrobbler';
export const sourceTypes: SourceType[] = ['apple', 'spotify', 'plex', 'tautulli', 'subsonic', 'jellyfin', 'lastfm', 'deezer', 'ytmusic', 'mpris', 'mopidy', 'listenbrainz', 'jriver', 'kodi', 'webscrobbler'];

export const lowGranularitySources: SourceType[] = ['subsonic','ytmusic'];

Expand Down
35 changes: 35 additions & 0 deletions src/backend/common/infrastructure/config/source/apple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {CommonSourceConfig, CommonSourceData} from "./index";
import {PollingOptions} from "../common";

// See issue for more documentation
// https://github.com/FoxxMD/multi-scrobbler/issues/9#issuecomment-946871774
export interface AppleMusicData extends CommonSourceData, PollingOptions {
/**
* Contents of MusicKit private key or a path to the key file
*
* https://help.apple.com/developer-account/#/devcdfbb56a3
* */
key: string

/**
* Team Id (tid) from Developer account
* */
teamId: string
/**
* Key identifier (kid) from Developer account
* */
keyId: string

/**
* URL to another MS instance running the apple music source *server*
* */
endpoint: string
}

export interface AppleMusicSourceConfig extends CommonSourceConfig {
data: AppleMusicData
}

export interface AppleMusicAIOSourceConfig extends AppleMusicSourceConfig {
type: 'apple'
}
5 changes: 3 additions & 2 deletions src/backend/common/infrastructure/config/source/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import { ListenBrainzSourceAIOConfig, ListenBrainzSourceConfig } from "./listenb
import { JRiverSourceAIOConfig, JRiverSourceConfig } from "./jriver";
import { KodiSourceAIOConfig, KodiSourceConfig } from "./kodi";
import { WebScrobblerSourceAIOConfig, WebScrobblerSourceConfig } from "./webscrobbler";
import {AppleMusicSourceConfig, AppleMusicAIOSourceConfig} from "./apple";


export type SourceConfig = SpotifySourceConfig | PlexSourceConfig | TautulliSourceConfig | DeezerSourceConfig | SubSonicSourceConfig | JellySourceConfig | LastfmSourceConfig | YTMusicSourceConfig | MPRISSourceConfig | MopidySourceConfig | ListenBrainzSourceConfig | JRiverSourceConfig | KodiSourceConfig | WebScrobblerSourceConfig;
export type SourceConfig = AppleMusicSourceConfig | SpotifySourceConfig | PlexSourceConfig | TautulliSourceConfig | DeezerSourceConfig | SubSonicSourceConfig | JellySourceConfig | LastfmSourceConfig | YTMusicSourceConfig | MPRISSourceConfig | MopidySourceConfig | ListenBrainzSourceConfig | JRiverSourceConfig | KodiSourceConfig | WebScrobblerSourceConfig;

export type SourceAIOConfig = SpotifySourceAIOConfig | PlexSourceAIOConfig | TautulliSourceAIOConfig | DeezerSourceAIOConfig | SubsonicSourceAIOConfig | JellySourceAIOConfig | LastFmSouceAIOConfig | YTMusicSourceAIOConfig | MPRISSourceAIOConfig | MopidySourceAIOConfig | ListenBrainzSourceAIOConfig | JRiverSourceAIOConfig | KodiSourceAIOConfig | WebScrobblerSourceAIOConfig;
export type SourceAIOConfig = AppleMusicAIOSourceConfig | SpotifySourceAIOConfig | PlexSourceAIOConfig | TautulliSourceAIOConfig | DeezerSourceAIOConfig | SubsonicSourceAIOConfig | JellySourceAIOConfig | LastFmSouceAIOConfig | YTMusicSourceAIOConfig | MPRISSourceAIOConfig | MopidySourceAIOConfig | ListenBrainzSourceAIOConfig | JRiverSourceAIOConfig | KodiSourceAIOConfig | WebScrobblerSourceAIOConfig;
142 changes: 142 additions & 0 deletions src/backend/common/schema/aio-source.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,145 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"AppleMusicAIOSourceConfig": {
"properties": {
"clients": {
"description": "Restrict scrobbling tracks played from this source to Clients with names from this list. If list is empty is not present Source scrobbles to all configured Clients.",
"examples": [
[
"MyMalojaConfigName",
"MyLastFMConfigName"
]
],
"items": {
"type": "string"
},
"title": "clients",
"type": "array"
},
"data": {
"$ref": "#/definitions/AppleMusicData",
"title": "data"
},
"enable": {
"default": true,
"description": "Should MS use this client/source? Defaults to true",
"examples": [
true
],
"title": "enable",
"type": "boolean"
},
"name": {
"description": "Unique identifier for this source.",
"title": "name",
"type": "string"
},
"options": {
"$ref": "#/definitions/CommonSourceOptions",
"title": "options"
},
"type": {
"enum": [
"apple"
],
"title": "type",
"type": "string"
}
},
"required": [
"data",
"type"
],
"title": "AppleMusicAIOSourceConfig",
"type": "object"
},
"AppleMusicData": {
"properties": {
"endpoint": {
"description": "URL to another MS instance running the apple music source *server*",
"title": "endpoint",
"type": "string"
},
"interval": {
"default": 10,
"description": "How long to wait before polling the source API for new tracks (in seconds)",
"examples": [
10
],
"title": "interval",
"type": "number"
},
"key": {
"description": "Contents of MusicKit private key or a path to the key file\n\nhttps://help.apple.com/developer-account/#/devcdfbb56a3",
"title": "key",
"type": "string"
},
"keyId": {
"description": "Key identifier (kid) from Developer account",
"title": "keyId",
"type": "string"
},
"maxInterval": {
"default": 30,
"description": "When there has been no new activity from the Source API multi-scrobbler will gradually increase the wait time between polling up to this value (in seconds)",
"examples": [
30
],
"title": "maxInterval",
"type": "number"
},
"maxPollRetries": {
"default": 5,
"description": "default # of automatic polling restarts on error",
"examples": [
5
],
"title": "maxPollRetries",
"type": "number"
},
"maxRequestRetries": {
"default": 1,
"description": "default # of http request retries a source can make before error is thrown",
"examples": [
1
],
"title": "maxRequestRetries",
"type": "number"
},
"options": {
"$ref": "#/definitions/Record<string,any>",
"title": "options"
},
"retryMultiplier": {
"default": 1.5,
"description": "default retry delay multiplier (retry attempt * multiplier = # of seconds to wait before retrying)",
"examples": [
1.5
],
"title": "retryMultiplier",
"type": "number"
},
"scrobbleThresholds": {
"$ref": "#/definitions/ScrobbleThresholds",
"description": "Set thresholds for when multi-scrobbler should consider a tracked play to be \"scrobbable\". If both duration and percent are defined then if either condition is met the track is scrobbled.",
"title": "scrobbleThresholds"
},
"teamId": {
"description": "Team Id (tid) from Developer account",
"title": "teamId",
"type": "string"
}
},
"required": [
"endpoint",
"key",
"keyId",
"teamId"
],
"title": "AppleMusicData",
"type": "object"
},
"CommonSourceOptions": {
"properties": {
"logFilterFailure": {
Expand Down Expand Up @@ -1461,6 +1600,9 @@
},
{
"$ref": "#/definitions/WebScrobblerSourceAIOConfig"
},
{
"$ref": "#/definitions/AppleMusicAIOSourceConfig"
}
],
"title": "SourceAIOConfig"
Expand Down
Loading

0 comments on commit 8be218a

Please sign in to comment.