mirror of
https://github.com/FoxxMD/multi-scrobbler.git
synced 2026-09-03 05:10:00 +03:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fdd346c00 | ||
|
|
4f26b63ab1 | ||
|
|
0fed91302c | ||
|
|
831cefd9a7 | ||
|
|
114a3dda8b | ||
|
|
55ddd2c5a0 | ||
|
|
1d276186f8 | ||
|
|
fb3886b981 | ||
|
|
2bed7be654 | ||
|
|
5c460ad747 | ||
|
|
32220d7509 | ||
|
|
b0265001f8 | ||
|
|
9ede4634cb | ||
|
|
0e008ecd5c | ||
|
|
2ae82fdd9e | ||
|
|
3b430b95ed | ||
|
|
e907892c4a | ||
|
|
d9cd3764b9 | ||
|
|
9c2bf05a24 | ||
|
|
91e52c4c5d | ||
|
|
b41d7f539f | ||
|
|
9735b980d7 | ||
|
|
706483ed06 | ||
|
|
7760776a5f | ||
|
|
8b9a7893d3 | ||
|
|
729250a2cc | ||
|
|
f14203f85e |
@@ -1,7 +1,7 @@
|
||||
name: Delete Untagged Packages
|
||||
on:
|
||||
schedule:
|
||||
- cron: '30 1 * * *'
|
||||
- cron: '30 1 * * 0'
|
||||
workflow_run:
|
||||
workflows: ["Publish Docker image to Dockerhub"]
|
||||
types:
|
||||
|
||||
@@ -20,13 +20,14 @@ A javascript app to scrobble music you listened to, to [Maloja](https://github.c
|
||||
* [Youtube Music](https://foxxmd.github.io/multi-scrobbler/docs/configuration#youtube-music)
|
||||
* [Last.fm](https://foxxmd.github.io/multi-scrobbler/docs/configuration#lastfm-source)
|
||||
* [ListenBrainz](https://foxxmd.github.io/multi-scrobbler/docs/configuration#listenbrainz-source)
|
||||
* [Deezer](https://foxxmd.github.io/multi-scrobbler/docs/configuration#deezer)
|
||||
* [~~Deezer~~](https://foxxmd.github.io/multi-scrobbler/docs/configuration#deezer)
|
||||
* [MPRIS (Linux Desktop)](https://foxxmd.github.io/multi-scrobbler/docs/configuration#mpris)
|
||||
* [Mopidy](https://foxxmd.github.io/multi-scrobbler/docs/configuration#mopidy)
|
||||
* [JRiver](https://foxxmd.github.io/multi-scrobbler/docs/configuration#jriver)
|
||||
* [Kodi](https://foxxmd.github.io/multi-scrobbler/docs/configuration#kodi)
|
||||
* [Google Cast (Chromecast)](https://foxxmd.github.io/multi-scrobbler/docs/configuration#google-cast-chromecast)
|
||||
* [Musikcube](https://foxxmd.github.io/multi-scrobbler/docs/configuration#muikcube)
|
||||
* [MPD (Music Player Daemon)](https://foxxmd.github.io/multi-scrobbler/docs/configuration#mpd-music-player-daemon)
|
||||
* Supports scrobbling to many **Clients**
|
||||
* [Maloja](https://foxxmd.github.io/multi-scrobbler/docs/configuration#maloja)
|
||||
* [Last.fm](https://foxxmd.github.io/multi-scrobbler/docs/configuration#lastfm)
|
||||
@@ -37,7 +38,8 @@ A javascript app to scrobble music you listened to, to [Maloja](https://github.c
|
||||
* Graceful network and client failure handling (queued scrobbles that auto-retry)
|
||||
* Smart handling of credentials (persistent, authorization through app)
|
||||
* Easy configuration through ENVs or JSON
|
||||
* Install using [Docker images for x86/ARM](https://foxxmd.github.io/multi-scrobbler/docs/installation#docker#docker), [flatpak](https://foxxmd.github.io/multi-scrobbler/docs/installation#docker#flatpak), or [locally with NodeJS](https://foxxmd.github.io/multi-scrobbler/docs/installation#docker#nodejs)
|
||||
* Modify data before scrobbling with [regular expression or search patterns](https://foxxmd.github.io/multi-scrobbler/docs/transforms)
|
||||
* Install using [Docker images for x86/ARM](https://foxxmd.github.io/multi-scrobbler/docs/installation#docker), [flatpak](https://foxxmd.github.io/multi-scrobbler/docs/installationr#flatpak), or [locally with NodeJS](https://foxxmd.github.io/multi-scrobbler/docs/installation#nodejs)
|
||||
|
||||
[**Quick Start Guide**](https://foxxmd.github.io/multi-scrobbler/docs/quickstart)
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
[
|
||||
{
|
||||
"enable": true,
|
||||
"name": "MyMPD",
|
||||
"data": {
|
||||
"url": "192.168.0.100:6600",
|
||||
"password": "MY_PASSWORD"
|
||||
},
|
||||
"options": {
|
||||
"disableDiscovery": false
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -4,6 +4,7 @@
|
||||
"enable": true,
|
||||
"name": "musikcube",
|
||||
"data": {
|
||||
"url": "ws://localhost:7905",
|
||||
"password": "MY_PASSWORD"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +124,10 @@ If multi-scrobbler is not running on the same machine your browser is on then th
|
||||
|
||||
EX `http://localhost:9078/lastfm/callback` -> `http://192.168.0.220:9078/lastfm/callback`
|
||||
|
||||
### Deezer is not working
|
||||
|
||||
Deezer has discontinued support for their API and the Deezer Source is now [**deprecated.**](configuration/configuration.mdx#deezer) See [this issue for more discussion.](https://github.com/FoxxMD/multi-scrobbler/issues/175#issuecomment-2296776625)
|
||||
|
||||
## Configuration Issues
|
||||
|
||||
### Config could not be parsed
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,320 @@
|
||||
---
|
||||
sidebar_position: 4
|
||||
title: Scrobble Modification
|
||||
toc_max_heading_level: 4
|
||||
---
|
||||
|
||||
Multi-scrobbler configs support the ability to modify scrobble data in an automated fashion by matching and replacing strings in **title, artists, and album** at many different times in multi-scrobbler's lifecycle.
|
||||
|
||||
### Why?
|
||||
|
||||
You may need to "clean up" data from a Source or before sending to a scrobble Client due to any number of reasons:
|
||||
|
||||
* ID3 tags in your music collection are dirty or have repeating garbage IE `[YourMusicSource.com] My Artist - My Title`
|
||||
* A Source's service often incorrectly adds data to some field IE `My Artist - My Title (Album Version)` when the title should just be `My Title`
|
||||
* An Artist you listen to often is spelled different between a Source and a Client which causes duplicate scrobbles
|
||||
|
||||
In any scenario where a repeating pattern can be found in the data it would be nice to be able to fix it before the data gets downstream or to help prevent duplicate scrobbling. Multi-scrobbler can help you do this.
|
||||
|
||||
## Overview
|
||||
|
||||
### Journey of a Scrobble
|
||||
|
||||
First, let's recap the lifecycle of a scrobble in multi-scrobbler:
|
||||
|
||||
**Sources** are the beginning of the journey for a **Play** (song you've listened to long enough to be scrobblable)
|
||||
|
||||
* A Source finds a new valid **Play**
|
||||
* The Source **compares** this new Play to all the other Plays it has already seen, if the Play is unique (title/artist/album/listened datetime) then...
|
||||
* The Source **discovers** the Play, adds it to Plays it has seen already, and broadcasts the Play should be scrobbled to all Clients
|
||||
|
||||
Scrobble **Clients** listen for discovered Plays from Sources, then...
|
||||
|
||||
* A Client receives a **Play** from a Source
|
||||
* The Client **compares** this Play to all the other scrobbles it has already seen, if the Play is unique (title/artist/album/listened datetime) then...
|
||||
* The Client **scrobbles** the Play downstream to the scrobble service and adds it as a Scrobble it has seen already
|
||||
|
||||
### Lifecyle Hooks
|
||||
|
||||
You'll notice there is a pattern above that looks like this:
|
||||
|
||||
* **Before** data is compared
|
||||
* Data is **compared**
|
||||
* **After** data is compared
|
||||
|
||||
These points, during both Source and Client processes, are when you can hook into the scrobble lifecycle and modify it.
|
||||
|
||||
#### TLDR
|
||||
|
||||
In more concrete terms this is the structure of hooks within a configuration (can be used in any **Source** or **Client**):
|
||||
|
||||
```json5 title="lastfm.json" {10-14}
|
||||
[
|
||||
{
|
||||
"name": "myLastFm",
|
||||
"enable": true,
|
||||
"configureAs": "source",
|
||||
"data": {
|
||||
// ...
|
||||
},
|
||||
"options": {
|
||||
"playTransform": {
|
||||
"preCompare": {/* ... */},
|
||||
"compare": {/* ... */},
|
||||
"postCompare": {/* ... */}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
##### Hook
|
||||
|
||||
For **Sources**:
|
||||
|
||||
* `preCompare` - modify Play data immediately when received
|
||||
* `compare` - temporarily modify Play data when it is being compared to see if Play was already discovered
|
||||
* `postCompare` - modify Play data before sending to scrobble **Clients**
|
||||
|
||||
For **Clients**:
|
||||
|
||||
* `preCompare` - modify Play data immediately when received
|
||||
* `compare` - temporarily modify Play data when it is being compared to see if it was already scrobbled
|
||||
* `postCompare` - modify Play data before scrobbling it to downstream service and adding to already seen scrobbles
|
||||
|
||||
:::tip
|
||||
|
||||
Keep in mind that modifying Scrobble/Play data earlier in the lifecycle will affect that data at all times later in the lifecycle.
|
||||
|
||||
For example, to modify the track so it's the same anywhere it is processed in multi-scrobbler you only need to modify it in the **Source's** `preCompare` hook because all later processes will receive the data with the modified track.
|
||||
|
||||
:::
|
||||
|
||||
### Modification Parts
|
||||
|
||||
|
||||
Each [**hook**](#hook) (`preCompare` etc...) is an object that specifies what part of the **Play** to modify:
|
||||
|
||||
```json5
|
||||
{
|
||||
"title": [/* ... */],
|
||||
"artists": [/* ... */],
|
||||
"album": [/* ... */]
|
||||
}
|
||||
```
|
||||
|
||||
##### Expression
|
||||
|
||||
and then a **list** what pattern/replacements (expressions) to use for the modification by using either simple strings or `search-replace` objects:
|
||||
|
||||
```json5
|
||||
[
|
||||
"badTerm", // remove all instances of 'badTerm'
|
||||
{
|
||||
"search": "anotherBadTerm", // and also match all instances of 'anotherBadTerm'
|
||||
"replace": "goodTerm" // replace with the string 'goodTerm'
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
Putting it all together:
|
||||
|
||||
```json5 title="lastfm.json"
|
||||
[
|
||||
{
|
||||
"name": "myLastFm",
|
||||
"enable": true,
|
||||
"configureAs": "source",
|
||||
"data": {
|
||||
// ...
|
||||
},
|
||||
"options": {
|
||||
"playTransform": {
|
||||
"preCompare": {
|
||||
"title": [
|
||||
[
|
||||
"badTerm",
|
||||
{
|
||||
"search": "badTerm",
|
||||
"replace": "goodTerm"
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
If the value of the field (title, an artist, album) is an empty string after transforming then the field is **removed.**
|
||||
|
||||
:::
|
||||
|
||||
:::tip
|
||||
|
||||
Modifications can also be applied to **all Sources** or **all Clients** when using the [AIO Config](./configuration.mdx?configType=aio#configuration-types) `config.json` by setting `playTransform` in `sourceDefaults` or `clientDefaults`:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Example</summary>
|
||||
```json5 title="config.json"
|
||||
{
|
||||
"sourceDefaults": { // will apply playTransform to all sources
|
||||
"playTransform": {
|
||||
"preCompare": {
|
||||
"title": [
|
||||
"(Album Version)"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"sources": [/* ... */],
|
||||
"clients": [/* ... */]
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
:::
|
||||
|
||||
#### Compare Hook
|
||||
|
||||
The `compare` [hook](#hook) is slightly different than `preCompare` and `postCompare`. It consists of an object where you define which side(s) of the comparison should be modified. It also **does not modify downstream data!** Instead, the modifications are made only for use in the comparison.
|
||||
|
||||
```json5 title="lastfm.json"
|
||||
[
|
||||
{
|
||||
"name": "myLastFm",
|
||||
// ...
|
||||
"options": {
|
||||
"playTransform": {
|
||||
"compare": {
|
||||
"candidate": {/* ... */}, // modify the "new" Play being compared
|
||||
"existing": {/* ... */}, // modify all "existing" Play/Scrobbles the new Play is being compared against
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
#### Regular Expressions
|
||||
|
||||
In addition to plain strings [expressions](#expression) that are matched and removed you can also use Regular Expressions. Write your regex like you normally would, but as a string, and it'll automatically be parsed:
|
||||
|
||||
```json5
|
||||
[
|
||||
"/^\(\w+.com)/i", // matches any string that starts with '(YourMusic.com)' and removes it
|
||||
{
|
||||
"search": "/^\(\w+.com)/i", // matches any string that starts with '(YourMusic.com)'
|
||||
"replace": "[MySite.com]" // replace with the string '[MySite.com]'
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
The `replace` property uses javascript's [`replace()` function and so can use any special string characters.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement)
|
||||
|
||||
## Examples
|
||||
|
||||
### Remove phrase from Title in all new Plays
|
||||
|
||||
Removes the phrase `(Album Version)` from the Title of a Play
|
||||
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Example</summary>
|
||||
```json5 title="config.json"
|
||||
{
|
||||
"sourceDefaults": {
|
||||
"playTransform": {
|
||||
"preCompare": {
|
||||
"title": [
|
||||
"(Album Version)"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
</details>
|
||||
|
||||
### Remove all parenthesized content from the end of a title
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Example</summary>
|
||||
```json5 title="lastfm.json"
|
||||
[
|
||||
{
|
||||
"name": "myLastFm",
|
||||
// ...
|
||||
"options": {
|
||||
"playTransform": {
|
||||
"compare": {
|
||||
"candidate": {
|
||||
"title": [
|
||||
"/(\(.+\))\s*$/"
|
||||
]
|
||||
},
|
||||
"existing": {
|
||||
"title": [
|
||||
"/(\(.+\))\s*$/"
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
</details>
|
||||
|
||||
### Rename misspelled artist in all new Plays
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Example</summary>
|
||||
```json5 title="config.json"
|
||||
{
|
||||
"sourceDefaults": {
|
||||
"playTransform": {
|
||||
"preCompare": {
|
||||
"artists": [
|
||||
{
|
||||
"search": "Boz Skaggs",
|
||||
"replace": "Boz Scaggs"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
### Remove "Various Artists" albums in all new Plays
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Example</summary>
|
||||
```json5 title="config.json"
|
||||
{
|
||||
"sourceDefaults": {
|
||||
"playTransform": {
|
||||
"preCompare": {
|
||||
"album": [
|
||||
{
|
||||
"search": "Various Artists",
|
||||
"replace": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
@@ -21,13 +21,14 @@ A javascript app to scrobble music you listened to, to [Maloja](https://github.c
|
||||
* [Youtube Music](docs/configuration#youtube-music)
|
||||
* [Last.fm](docs/configuration#lastfm-source)
|
||||
* [ListenBrainz](docs/configuration#listenbrainz-source)
|
||||
* [Deezer](docs/configuration#deezer)
|
||||
* [~~Deezer~~](docs/configuration#deezer)
|
||||
* [MPRIS (Linux Desktop)](docs/configuration#mpris)
|
||||
* [Mopidy](docs/configuration#mopidy)
|
||||
* [JRiver](docs/configuration#jriver)
|
||||
* [Kodi](docs/configuration#kodi)
|
||||
* [Google Cast (Chromecast)](docs/configuration#google-cast-chromecast)
|
||||
* [Musikcube](docs/configuration#musikcube)
|
||||
* [MPD (Music Player Daemon)](docs/configuration#mpd-music-player-daemon)
|
||||
* Supports scrobbling to many **Clients**
|
||||
* [Maloja](docs/configuration#maloja)
|
||||
* [Last.fm](docs/configuration#lastfm)
|
||||
@@ -38,6 +39,7 @@ A javascript app to scrobble music you listened to, to [Maloja](https://github.c
|
||||
* Graceful network and client failure handling (queued scrobbles that auto-retry)
|
||||
* Smart handling of credentials (persistent, authorization through app)
|
||||
* Easy configuration through ENVs or JSON
|
||||
* Modify data before scrobbling with [regular expression or search patterns](docs/transforms)
|
||||
* Install using [Docker images for x86/ARM](docs/installation#docker), [flatpak](docs/installation#flatpak), or [locally with NodeJS](docs/installation#nodejs)
|
||||
|
||||
[**Quick Start Guide**](docs/quickstart)
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
<li>Jellyfin</li>
|
||||
<li>WebScrobbler</li>
|
||||
<li>Mopidy</li>
|
||||
<li>Deezer</li>
|
||||
<li>JRiver</li>
|
||||
<li>Kodi</li>
|
||||
<li>Webscrobbler</li>
|
||||
@@ -50,6 +49,7 @@
|
||||
</screenshot>
|
||||
</screenshots>
|
||||
<releases>
|
||||
<release version="0.8.2" date="2024-08-20"/>
|
||||
<release version="0.8.1" date="2024-07-17"/>
|
||||
<release version="0.8.0" date="2024-07-08"/>
|
||||
<release version="0.7.1" date="2024-04-11"/>
|
||||
|
||||
Generated
+314
-17
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "multi-scrobbler",
|
||||
"version": "0.8.1",
|
||||
"version": "0.8.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "multi-scrobbler",
|
||||
"version": "0.8.0",
|
||||
"version": "0.8.2",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -20,6 +20,7 @@
|
||||
"@foxxmd/chromecast-client": "^1.0.4",
|
||||
"@foxxmd/get-version": "^0.0.3",
|
||||
"@foxxmd/logging": "^0.1.14",
|
||||
"@foxxmd/regex-buddy-core": "^0.1.0",
|
||||
"@foxxmd/string-sameness": "^0.4.0",
|
||||
"@kenyip/backoff-strategies": "^1.0.4",
|
||||
"@react-nano/use-event-source": "^0.13.0",
|
||||
@@ -45,12 +46,13 @@
|
||||
"fixed-size-list": "^0.3.0",
|
||||
"formidable": "^2.1",
|
||||
"gotify": "^1.1.0",
|
||||
"iso-websocket": "^0.2.0",
|
||||
"iso-websocket": "^0.3.0",
|
||||
"iti": "^0.6.0",
|
||||
"json5": "^2.2.3",
|
||||
"kodi-api": "^0.2.1",
|
||||
"lastfm-node-client": "^2.2.0",
|
||||
"mopidy": "^1.3.0",
|
||||
"mpd-api": "^1.1.2",
|
||||
"nanoid": "^3.3.1",
|
||||
"normalize-url": "^8.0.1",
|
||||
"ntfy": "^1.5.4",
|
||||
@@ -77,7 +79,7 @@
|
||||
"devDependencies": {
|
||||
"@dbus-types/notifications": "^0.0.5",
|
||||
"@eslint/js": "^8.56.0",
|
||||
"@faker-js/faker": "^8.1.0",
|
||||
"@faker-js/faker": "^9.0.0-rc.1",
|
||||
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
||||
"@testing-library/jest-dom": "^5.17.0",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
@@ -1119,9 +1121,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@faker-js/faker": {
|
||||
"version": "8.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-8.4.1.tgz",
|
||||
"integrity": "sha512-XQ3cU+Q8Uqmrbf2e0cIC/QN43sTBSC8KF12u29Mb47tWrt2hAgBXSgpZMj4Ao8Uk0iJcU99QsOCaIL8934obCg==",
|
||||
"version": "9.0.0-rc.1",
|
||||
"resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-9.0.0-rc.1.tgz",
|
||||
"integrity": "sha512-d9uL+O7Bud4W0axuHYxjCsfwazwo6iPRbgDkIPgWhtxpnziHqbFafOuKubnQ++4V31dI9NYYkajzGNJADHas4A==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
@@ -1130,8 +1132,8 @@
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": "^14.17.0 || ^16.13.0 || >=18.0.0",
|
||||
"npm": ">=6.14.13"
|
||||
"node": ">=18.0.0",
|
||||
"npm": ">=9.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@fortawesome/fontawesome-common-types": {
|
||||
@@ -1220,6 +1222,18 @@
|
||||
"npm": ">=9.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@foxxmd/regex-buddy-core": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@foxxmd/regex-buddy-core/-/regex-buddy-core-0.1.0.tgz",
|
||||
"integrity": "sha512-CzmFvnbl2mWnH4jJZzBIe6HwLCKFfahHMKUvj3IB6bCnHn0yTO2BKVpm6tqTvIw8BNXqggbiONp5mMLe8DroLA==",
|
||||
"dependencies": {
|
||||
"@stdlib/regexp-regexp": "^0.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0",
|
||||
"npm": ">=9.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@foxxmd/string-sameness": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@foxxmd/string-sameness/-/string-sameness-0.4.0.tgz",
|
||||
@@ -2014,6 +2028,188 @@
|
||||
"url": "https://github.com/sindresorhus/is?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/@stdlib/error-tools-fmtprodmsg": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@stdlib/error-tools-fmtprodmsg/-/error-tools-fmtprodmsg-0.2.1.tgz",
|
||||
"integrity": "sha512-SaxvGeGfWfda/O3rTNGRGBzAL9gsY/yd8n1hXwzOl/2aUHf8nxcf6Fz6/BQ5PguT0GiBkca19XEhHZZHxX3X/g==",
|
||||
"os": [
|
||||
"aix",
|
||||
"darwin",
|
||||
"freebsd",
|
||||
"linux",
|
||||
"macos",
|
||||
"openbsd",
|
||||
"sunos",
|
||||
"win32",
|
||||
"windows"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=0.10.0",
|
||||
"npm": ">2.7.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/stdlib"
|
||||
}
|
||||
},
|
||||
"node_modules/@stdlib/regexp-regexp": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@stdlib/regexp-regexp/-/regexp-regexp-0.2.1.tgz",
|
||||
"integrity": "sha512-f25kXWc73YVPxDxC8/25NM6AKHn3gH5WVcQfhjyy1FMM++XLNFy2M+1sdAyQ8PnlZ9qJwtn3/NjbACeETGfYHQ==",
|
||||
"os": [
|
||||
"aix",
|
||||
"darwin",
|
||||
"freebsd",
|
||||
"linux",
|
||||
"macos",
|
||||
"openbsd",
|
||||
"sunos",
|
||||
"win32",
|
||||
"windows"
|
||||
],
|
||||
"dependencies": {
|
||||
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0",
|
||||
"npm": ">2.7.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/stdlib"
|
||||
}
|
||||
},
|
||||
"node_modules/@stdlib/string-base-format-interpolate": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@stdlib/string-base-format-interpolate/-/string-base-format-interpolate-0.2.1.tgz",
|
||||
"integrity": "sha512-Uxz89eUi4m9yao4VjsqXIxLIF7qDmqEAH0e+XBRWRGC2zx6DhmK2kLnaU0xW69+VJPn3dq4itxq0oryw2E+qIQ==",
|
||||
"os": [
|
||||
"aix",
|
||||
"darwin",
|
||||
"freebsd",
|
||||
"linux",
|
||||
"macos",
|
||||
"openbsd",
|
||||
"sunos",
|
||||
"win32",
|
||||
"windows"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=0.10.0",
|
||||
"npm": ">2.7.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/stdlib"
|
||||
}
|
||||
},
|
||||
"node_modules/@stdlib/string-base-format-tokenize": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@stdlib/string-base-format-tokenize/-/string-base-format-tokenize-0.2.1.tgz",
|
||||
"integrity": "sha512-3Ut96pmCgEFArrdwXKm1q0j1FOqTnG/uOsh24uYNU/ABRsMOOajRlAjCCdQv9f8P916qPrSnF1V3Pd18LAaksg==",
|
||||
"os": [
|
||||
"aix",
|
||||
"darwin",
|
||||
"freebsd",
|
||||
"linux",
|
||||
"macos",
|
||||
"openbsd",
|
||||
"sunos",
|
||||
"win32",
|
||||
"windows"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=0.10.0",
|
||||
"npm": ">2.7.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/stdlib"
|
||||
}
|
||||
},
|
||||
"node_modules/@stdlib/string-format": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@stdlib/string-format/-/string-format-0.2.1.tgz",
|
||||
"integrity": "sha512-+HpXkEJ0Z4gthH5KicXvRRJiCiCTSrKzM+mS8N6vwaAD+OG+Oq8Cn43XBD1ic/UHROI9un42MruF1ZLlkSmdOw==",
|
||||
"os": [
|
||||
"aix",
|
||||
"darwin",
|
||||
"freebsd",
|
||||
"linux",
|
||||
"macos",
|
||||
"openbsd",
|
||||
"sunos",
|
||||
"win32",
|
||||
"windows"
|
||||
],
|
||||
"dependencies": {
|
||||
"@stdlib/string-base-format-interpolate": "^0.2.1",
|
||||
"@stdlib/string-base-format-tokenize": "^0.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0",
|
||||
"npm": ">2.7.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/stdlib"
|
||||
}
|
||||
},
|
||||
"node_modules/@stdlib/utils-define-nonenumerable-read-only-property": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@stdlib/utils-define-nonenumerable-read-only-property/-/utils-define-nonenumerable-read-only-property-0.2.1.tgz",
|
||||
"integrity": "sha512-L8fs1kI79T2RQIg8rHR9aQnnSDELqiDGWbK3jA1NP8iW+ydxlxXyO8Dw17fBCXVua3Y19a1NVyGtIN5WGe2UCw==",
|
||||
"os": [
|
||||
"aix",
|
||||
"darwin",
|
||||
"freebsd",
|
||||
"linux",
|
||||
"macos",
|
||||
"openbsd",
|
||||
"sunos",
|
||||
"win32",
|
||||
"windows"
|
||||
],
|
||||
"dependencies": {
|
||||
"@stdlib/utils-define-property": "^0.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0",
|
||||
"npm": ">2.7.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/stdlib"
|
||||
}
|
||||
},
|
||||
"node_modules/@stdlib/utils-define-property": {
|
||||
"version": "0.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@stdlib/utils-define-property/-/utils-define-property-0.2.3.tgz",
|
||||
"integrity": "sha512-+EzWImaQR/6XNFbXIITFi3PLQGTbKVIWSYxJfHXAuTtibAMnhHOWvEzKOumVe/Q4Cdsrc3/PIkpjJzliqAX9AA==",
|
||||
"os": [
|
||||
"aix",
|
||||
"darwin",
|
||||
"freebsd",
|
||||
"linux",
|
||||
"macos",
|
||||
"openbsd",
|
||||
"sunos",
|
||||
"win32",
|
||||
"windows"
|
||||
],
|
||||
"dependencies": {
|
||||
"@stdlib/error-tools-fmtprodmsg": "^0.2.1",
|
||||
"@stdlib/string-format": "^0.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0",
|
||||
"npm": ">2.7.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/stdlib"
|
||||
}
|
||||
},
|
||||
"node_modules/@supercharge/promise-pool": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@supercharge/promise-pool/-/promise-pool-3.2.0.tgz",
|
||||
@@ -2150,6 +2346,11 @@
|
||||
"@testing-library/dom": ">=7.21.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@tokenizer/token": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.3.0.tgz",
|
||||
"integrity": "sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A=="
|
||||
},
|
||||
"node_modules/@tsconfig/node10": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz",
|
||||
@@ -4852,6 +5053,22 @@
|
||||
"node": "^10.12.0 || >=12.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/file-type": {
|
||||
"version": "16.5.4",
|
||||
"resolved": "https://registry.npmjs.org/file-type/-/file-type-16.5.4.tgz",
|
||||
"integrity": "sha512-/yFHK0aGjFEgDJjEKP0pWCplsPFPhwyfwevf/pVxiN0tmE4L9LmwWxWukdJSHdoCli4VgQLehjJtwQBnqmsKcw==",
|
||||
"dependencies": {
|
||||
"readable-web-to-node-stream": "^3.0.0",
|
||||
"strtok3": "^6.2.4",
|
||||
"token-types": "^4.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sindresorhus/file-type?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/fill-range": {
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||
@@ -6063,15 +6280,15 @@
|
||||
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="
|
||||
},
|
||||
"node_modules/iso-websocket": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/iso-websocket/-/iso-websocket-0.2.0.tgz",
|
||||
"integrity": "sha512-imBalzmPSq0C9CfMouimB2kZ5X1qS4Yai8kGTQdluGRb0T0iu+BkPcakFelh4FIlTM8y6+BNuCEGog3lf8HC4A==",
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/iso-websocket/-/iso-websocket-0.3.0.tgz",
|
||||
"integrity": "sha512-RCzPkKMtX36F1FnoII4TO42aQF+ypGgtNuIamR2TwM+9a8JGBbxkxOcFf1WJKsSAh8sv1HXSjR+Lu+jGz/6oVA==",
|
||||
"dependencies": {
|
||||
"debug": "^4.3.4",
|
||||
"debug": "^4.3.5",
|
||||
"retry": "^0.13.1",
|
||||
"typescript-event-target": "^1.1.0",
|
||||
"unws": "^0.2.4",
|
||||
"ws": "^8.16.0"
|
||||
"ws": "^8.18.0"
|
||||
}
|
||||
},
|
||||
"node_modules/isomorphic-ws": {
|
||||
@@ -6934,6 +7151,27 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/mpd-api": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/mpd-api/-/mpd-api-1.1.2.tgz",
|
||||
"integrity": "sha512-UWSkIzYQnTvuvhLTfD0bIhBa4PCGCz6OsnDlojp319khsL8xXwS4qLVyJ+R5J7gNUTWiV9Y6d1j6apSYt2WDVA==",
|
||||
"dependencies": {
|
||||
"debug": "^4.3.4",
|
||||
"file-type": "^16.5.3",
|
||||
"mpd2": "^1.0.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/mpd2": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/mpd2/-/mpd2-1.0.5.tgz",
|
||||
"integrity": "sha512-DcIy3jISfjmFTlOpwDE2KDhBLcGuFIAMTvY23OMkCikJXRnDqqm1jaHG3/LVYkKjrUVzQhlABW31roGqv/esRw==",
|
||||
"dependencies": {
|
||||
"debug": "^4.1.1"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
@@ -7927,6 +8165,18 @@
|
||||
"resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz",
|
||||
"integrity": "sha512-KG8UEiEVkR3wGEb4m5yZkVCzigAD+cVEJck2CzYZO37ZGJfctvVptVO192MwrtPhzONn6go8ylnOdMhKqi4nfg=="
|
||||
},
|
||||
"node_modules/peek-readable": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-4.1.0.tgz",
|
||||
"integrity": "sha512-ZI3LnwUv5nOGbQzD9c2iDG6toheuXSZP5esSHBjopsXH4dg19soufvpUGA3uohi5anFtGb2lhAVdHzH6R/Evvg==",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Borewit"
|
||||
}
|
||||
},
|
||||
"node_modules/picocolors": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz",
|
||||
@@ -8633,6 +8883,21 @@
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/readable-web-to-node-stream": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/readable-web-to-node-stream/-/readable-web-to-node-stream-3.0.2.tgz",
|
||||
"integrity": "sha512-ePeK6cc1EcKLEhJFt/AebMCLL+GgSKhuygrZ/GLaKZYEecIgIECf4UaUuaByiGtzckwR4ain9VzUh95T1exYGw==",
|
||||
"dependencies": {
|
||||
"readable-stream": "^3.6.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Borewit"
|
||||
}
|
||||
},
|
||||
"node_modules/readdirp": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
|
||||
@@ -9426,6 +9691,22 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/strtok3": {
|
||||
"version": "6.3.0",
|
||||
"resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.3.0.tgz",
|
||||
"integrity": "sha512-fZtbhtvI9I48xDSywd/somNqgUHl2L2cstmXCCif0itOf96jeW18MBSyrLuNicYQVkvpOxkZtkzujiTJ9LW5Jw==",
|
||||
"dependencies": {
|
||||
"@tokenizer/token": "^0.3.0",
|
||||
"peek-readable": "^4.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Borewit"
|
||||
}
|
||||
},
|
||||
"node_modules/sucrase": {
|
||||
"version": "3.35.0",
|
||||
"resolved": "https://registry.npmjs.org/sucrase/-/sucrase-3.35.0.tgz",
|
||||
@@ -9744,6 +10025,22 @@
|
||||
"node": ">=0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/token-types": {
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/token-types/-/token-types-4.2.1.tgz",
|
||||
"integrity": "sha512-6udB24Q737UD/SDsKAHI9FCRP7Bqc9D/MQUV02ORQg5iskjtLJlZJNdN4kKtcdtwCeWIwIHDGaUsTsCCAa8sFQ==",
|
||||
"dependencies": {
|
||||
"@tokenizer/token": "^0.3.0",
|
||||
"ieee754": "^1.2.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Borewit"
|
||||
}
|
||||
},
|
||||
"node_modules/touch": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz",
|
||||
@@ -10437,9 +10734,9 @@
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.17.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz",
|
||||
"integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==",
|
||||
"version": "8.18.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz",
|
||||
"integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
|
||||
+5
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "multi-scrobbler",
|
||||
"version": "0.8.1",
|
||||
"version": "0.8.2",
|
||||
"type": "module",
|
||||
"description": "scrobble plays from multiple sources to multiple clients",
|
||||
"scripts": {
|
||||
@@ -55,6 +55,7 @@
|
||||
"@foxxmd/chromecast-client": "^1.0.4",
|
||||
"@foxxmd/get-version": "^0.0.3",
|
||||
"@foxxmd/logging": "^0.1.14",
|
||||
"@foxxmd/regex-buddy-core": "^0.1.0",
|
||||
"@foxxmd/string-sameness": "^0.4.0",
|
||||
"@kenyip/backoff-strategies": "^1.0.4",
|
||||
"@react-nano/use-event-source": "^0.13.0",
|
||||
@@ -80,12 +81,13 @@
|
||||
"fixed-size-list": "^0.3.0",
|
||||
"formidable": "^2.1",
|
||||
"gotify": "^1.1.0",
|
||||
"iso-websocket": "^0.2.0",
|
||||
"iso-websocket": "^0.3.0",
|
||||
"iti": "^0.6.0",
|
||||
"json5": "^2.2.3",
|
||||
"kodi-api": "^0.2.1",
|
||||
"lastfm-node-client": "^2.2.0",
|
||||
"mopidy": "^1.3.0",
|
||||
"mpd-api": "^1.1.2",
|
||||
"nanoid": "^3.3.1",
|
||||
"normalize-url": "^8.0.1",
|
||||
"ntfy": "^1.5.4",
|
||||
@@ -112,7 +114,7 @@
|
||||
"devDependencies": {
|
||||
"@dbus-types/notifications": "^0.0.5",
|
||||
"@eslint/js": "^8.56.0",
|
||||
"@faker-js/faker": "^8.1.0",
|
||||
"@faker-js/faker": "^9.0.0-rc.1",
|
||||
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
||||
"@testing-library/jest-dom": "^5.17.0",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import { Logger } from "@foxxmd/logging";
|
||||
import { childLogger, Logger } from "@foxxmd/logging";
|
||||
import { searchAndReplace, SearchAndReplaceRegExp } from "@foxxmd/regex-buddy-core";
|
||||
import { compare } from "compare-versions";
|
||||
import { ObjectPlayData, PlayData, PlayObject } from "../../core/Atomic.js";
|
||||
import { buildTrackString } from "../../core/StringUtils.js";
|
||||
import { configPartsToStrongParts, configValToSearchReplace } from "../utils.js";
|
||||
import { hasNodeNetworkException } from "./errors/NodeErrors.js";
|
||||
import { hasUpstreamError } from "./errors/UpstreamError.js";
|
||||
import { PlayTransformParts, PlayTransformRules, TRANSFORM_HOOK, TransformHook } from "./infrastructure/Atomic.js";
|
||||
import { CommonClientConfig } from "./infrastructure/config/client/index.js";
|
||||
import { CommonSourceConfig } from "./infrastructure/config/source/index.js";
|
||||
|
||||
export default abstract class AbstractComponent {
|
||||
requiresAuth: boolean = false;
|
||||
@@ -13,13 +21,22 @@ export default abstract class AbstractComponent {
|
||||
|
||||
initializing: boolean = false;
|
||||
|
||||
config: CommonClientConfig | CommonSourceConfig;
|
||||
|
||||
transformRules!: PlayTransformRules;
|
||||
|
||||
logger: Logger;
|
||||
|
||||
protected constructor(config: CommonClientConfig | CommonSourceConfig) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
initialize = async () => {
|
||||
this.logger.debug('Attempting to initialize...');
|
||||
try {
|
||||
this.initializing = true;
|
||||
await this.buildInitData();
|
||||
this.buildTransformRules();
|
||||
await this.checkConnection();
|
||||
await this.testAuth();
|
||||
this.logger.info('Fully Initialized!');
|
||||
@@ -72,6 +89,74 @@ export default abstract class AbstractComponent {
|
||||
return;
|
||||
}
|
||||
|
||||
public buildTransformRules() {
|
||||
try {
|
||||
this.doBuildTransformRules();
|
||||
} catch (e) {
|
||||
this.buildOK = false;
|
||||
throw new Error('Could not build playTransform rules. Check your configuration is valid.', {cause: e});
|
||||
}
|
||||
}
|
||||
|
||||
protected doBuildTransformRules() {
|
||||
const {
|
||||
options: {
|
||||
playTransform
|
||||
} = {}
|
||||
} = this.config;
|
||||
|
||||
if (playTransform === undefined) {
|
||||
this.transformRules = {};
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
preCompare: preConfig,
|
||||
compare: {
|
||||
candidate: candidateConfig,
|
||||
existing: existingConfig,
|
||||
} = {},
|
||||
postCompare: postConfig
|
||||
} = playTransform;
|
||||
|
||||
let preCompare,
|
||||
candidate,
|
||||
existing,
|
||||
postCompare;
|
||||
|
||||
try {
|
||||
preCompare = configPartsToStrongParts(preConfig)
|
||||
} catch (e) {
|
||||
throw new Error('preCompare was not valid', {cause: e});
|
||||
}
|
||||
|
||||
try {
|
||||
candidate = configPartsToStrongParts(candidateConfig)
|
||||
} catch (e) {
|
||||
throw new Error('candidate was not valid', {cause: e});
|
||||
}
|
||||
|
||||
try {
|
||||
existing = configPartsToStrongParts(existingConfig)
|
||||
} catch (e) {
|
||||
throw new Error('existing was not valid', {cause: e});
|
||||
}
|
||||
|
||||
try {
|
||||
postCompare = configPartsToStrongParts(postConfig)
|
||||
} catch (e) {
|
||||
throw new Error('postCompare was not valid', {cause: e});
|
||||
}
|
||||
|
||||
this.transformRules = {
|
||||
preCompare,
|
||||
compare: {
|
||||
candidate,
|
||||
existing,
|
||||
},
|
||||
postCompare,
|
||||
}
|
||||
}
|
||||
|
||||
public async checkConnection() {
|
||||
try {
|
||||
@@ -111,10 +196,13 @@ export default abstract class AbstractComponent {
|
||||
protected doAuthentication = async (): Promise<boolean> => this.authed
|
||||
|
||||
// default init function, should be overridden if auth stage is required
|
||||
testAuth = async () => {
|
||||
testAuth = async (force: boolean = false) => {
|
||||
if(!this.requiresAuth) {
|
||||
return;
|
||||
}
|
||||
if(this.authed && !force) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.authed = await this.doAuthentication();
|
||||
@@ -146,4 +234,143 @@ export default abstract class AbstractComponent {
|
||||
protected async postInitialize(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
public transformPlay = (play: PlayObject, hookType: TransformHook, log?: boolean) => {
|
||||
|
||||
let logger: Logger;
|
||||
const labels = ['Play Transform', hookType];
|
||||
const getLogger = () => logger !== undefined ? logger : childLogger(this.logger, labels);
|
||||
|
||||
try {
|
||||
let hook: PlayTransformParts<SearchAndReplaceRegExp> | undefined;
|
||||
|
||||
switch (hookType) {
|
||||
case TRANSFORM_HOOK.preCompare:
|
||||
hook = this.transformRules.preCompare;
|
||||
break;
|
||||
case TRANSFORM_HOOK.candidate:
|
||||
hook = this.transformRules.compare?.candidate;
|
||||
break;
|
||||
case TRANSFORM_HOOK.existing:
|
||||
hook = this.transformRules.compare?.existing;
|
||||
break;
|
||||
case TRANSFORM_HOOK.postCompare:
|
||||
hook = this.transformRules.postCompare;
|
||||
break;
|
||||
}
|
||||
|
||||
if (hook === undefined) {
|
||||
return play;
|
||||
}
|
||||
|
||||
const {
|
||||
data: {
|
||||
track,
|
||||
artists,
|
||||
albumArtists,
|
||||
album
|
||||
} = {}
|
||||
} = play;
|
||||
|
||||
const transformedPlayData: Partial<ObjectPlayData> = {};
|
||||
|
||||
let isTransformed = false;
|
||||
|
||||
if (hook.title !== undefined && track !== undefined) {
|
||||
try {
|
||||
const t = searchAndReplace(track, hook.title);
|
||||
if (t !== track) {
|
||||
transformedPlayData.track = t.trim() === '' ? undefined : t;
|
||||
isTransformed = true;
|
||||
}
|
||||
} catch (e) {
|
||||
getLogger().warn(new Error(`Failed to transform title: ${track}`, {cause: e}));
|
||||
}
|
||||
}
|
||||
|
||||
if (hook.artists !== undefined && artists !== undefined && artists.length > 0) {
|
||||
const transformedArtists: string[] = [];
|
||||
let anyArtistTransformed = false;
|
||||
for (const artist of artists) {
|
||||
try {
|
||||
const t = searchAndReplace(artist, hook.artists);
|
||||
if (t !== artist) {
|
||||
anyArtistTransformed = true;
|
||||
isTransformed = true;
|
||||
}
|
||||
if(t.trim() !== '') {
|
||||
transformedArtists.push(t);
|
||||
}
|
||||
} catch (e) {
|
||||
getLogger().warn(new Error(`Failed to transform artist: ${artist}`, {cause: e}));
|
||||
transformedArtists.push(artist);
|
||||
}
|
||||
}
|
||||
if(anyArtistTransformed) {
|
||||
transformedPlayData.artists = transformedArtists;
|
||||
}
|
||||
}
|
||||
|
||||
if (hook.artists !== undefined && albumArtists !== undefined && albumArtists.length > 0) {
|
||||
const transformedArtists: string[] = [];
|
||||
let anyArtistTransformed = false;
|
||||
for (const artist of albumArtists) {
|
||||
try {
|
||||
const t = searchAndReplace(artist, hook.artists);
|
||||
if (t !== artist) {
|
||||
anyArtistTransformed = true;
|
||||
isTransformed = true;
|
||||
}
|
||||
if(t.trim() !== '') {
|
||||
transformedArtists.push(t);
|
||||
}
|
||||
} catch (e) {
|
||||
getLogger().warn(new Error(`Failed to transform albumArtist: ${artist}`, {cause: e}));
|
||||
transformedArtists.push(artist);
|
||||
}
|
||||
}
|
||||
if(anyArtistTransformed) {
|
||||
transformedPlayData.albumArtists = transformedArtists;
|
||||
}
|
||||
}
|
||||
|
||||
if (hook.album !== undefined && album !== undefined) {
|
||||
try {
|
||||
const t = searchAndReplace(album, hook.album);
|
||||
if (t !== album) {
|
||||
isTransformed = true;
|
||||
transformedPlayData.album = t.trim() === '' ? undefined : t;
|
||||
}
|
||||
} catch (e) {
|
||||
getLogger().warn(new Error(`Failed to transform album: ${album}`, {cause: e}));
|
||||
}
|
||||
}
|
||||
|
||||
if(isTransformed) {
|
||||
|
||||
const transformedPlay = {
|
||||
...play,
|
||||
data: {
|
||||
...play.data,
|
||||
...transformedPlayData
|
||||
}
|
||||
}
|
||||
|
||||
const shouldLog = log ?? this.config.options?.playTransform?.log ?? true;
|
||||
if(shouldLog) {
|
||||
this.logger.debug({labels}, `Play transformed by ${hookType}:
|
||||
Original : ${buildTrackString(play, {include: ['artist', 'track', 'album']})}
|
||||
Transformed : ${buildTrackString(transformedPlay, {include: ['artist', 'track', 'album']})}
|
||||
`);
|
||||
}
|
||||
|
||||
return transformedPlay;
|
||||
}
|
||||
|
||||
return play;
|
||||
} catch (e) {
|
||||
getLogger().warn(new Error(`Unexpected error occurred, returning original play.`, {cause: e}));
|
||||
return play;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Logger } from '@foxxmd/logging';
|
||||
import { SearchAndReplaceRegExp } from "@foxxmd/regex-buddy-core";
|
||||
import { Dayjs } from "dayjs";
|
||||
import { Request, Response } from "express";
|
||||
import { NextFunction, ParamsDictionary, Query } from "express-serve-static-core";
|
||||
@@ -22,7 +23,8 @@ export type SourceType =
|
||||
| 'kodi'
|
||||
| 'webscrobbler'
|
||||
| 'chromecast'
|
||||
| 'musikcube';
|
||||
| 'musikcube'
|
||||
| 'mpd';
|
||||
|
||||
export const sourceTypes: SourceType[] = [
|
||||
'spotify',
|
||||
@@ -40,7 +42,8 @@ export const sourceTypes: SourceType[] = [
|
||||
'kodi',
|
||||
'webscrobbler',
|
||||
'chromecast',
|
||||
'musikcube'
|
||||
'musikcube',
|
||||
'mpd'
|
||||
];
|
||||
|
||||
export const lowGranularitySources: SourceType[] = ['subsonic', 'ytmusic'];
|
||||
@@ -238,3 +241,30 @@ export interface MdnsDeviceInfo {
|
||||
export type AbstractApiOptions = Record<any, any> & { logger: Logger }
|
||||
|
||||
export type keyOmit<T, U extends keyof any> = T & { [P in U]?: never }
|
||||
|
||||
export type SearchAndReplaceTerm = string | SearchAndReplaceRegExp;
|
||||
|
||||
export interface PlayTransformParts<T> {
|
||||
title?: T[]
|
||||
artists?: T[]
|
||||
album?: T[]
|
||||
}
|
||||
|
||||
export interface PlayTransformHooks<T> {
|
||||
preCompare?: PlayTransformParts<T>
|
||||
compare?: {
|
||||
candidate?: PlayTransformParts<T>
|
||||
existing?: PlayTransformParts<T>
|
||||
}
|
||||
postCompare?: PlayTransformParts<T>
|
||||
}
|
||||
|
||||
export type PlayTransformRules = PlayTransformHooks<SearchAndReplaceRegExp>
|
||||
|
||||
export type TransformHook = 'preCompare' | 'compare' | 'candidate' | 'existing' | 'postCompare';
|
||||
export const TRANSFORM_HOOK = {
|
||||
preCompare: 'preCompare' as TransformHook,
|
||||
candidate: 'candidate' as TransformHook,
|
||||
existing: 'existing' as TransformHook,
|
||||
postCompare: 'postCompare' as TransformHook,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CommonConfig, CommonData, RequestRetryOptions } from "../common.js";
|
||||
import { CommonConfig, CommonData, PlayTransformConfig, PlayTransformOptions, RequestRetryOptions } from "../common.js";
|
||||
|
||||
/**
|
||||
* Scrobble matching (between new source track and existing client scrobbles) logging options. Used for debugging.
|
||||
@@ -37,6 +37,16 @@ export interface CommonClientOptions extends RequestRetryOptions {
|
||||
* @examples [true]
|
||||
* */
|
||||
refreshEnabled?: boolean
|
||||
/**
|
||||
* Force client to refresh scrobbled plays from upstream service if last refresh was at least X seconds ago
|
||||
*
|
||||
* **In most case this setting should NOT be used.** MS intelligently refreshes based on activity so using this setting may increase upstream service load and slow down scrobbles.
|
||||
*
|
||||
* This setting should only be used in specific scenarios where MS is handling multiple "relaying" client-services (IE lfm -> lz -> lfm) and there is the potential for a client to be out of sync after more than a few seconds.
|
||||
*
|
||||
* @examples [3]
|
||||
* */
|
||||
refreshStaleAfter?: number
|
||||
|
||||
/**
|
||||
* The number of tracks to retrieve on initial refresh (related to scrobbleBacklogCount). If not specified this is the maximum supported for the client.
|
||||
@@ -63,6 +73,8 @@ export interface CommonClientOptions extends RequestRetryOptions {
|
||||
* @examples [1]
|
||||
* */
|
||||
deadLetterRetries?: number
|
||||
|
||||
playTransform?: PlayTransformOptions
|
||||
}
|
||||
|
||||
export interface CommonClientConfig extends CommonConfig {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { keyOmit } from "../Atomic.js";
|
||||
import { keyOmit, PlayTransformHooks, SearchAndReplaceTerm } from "../Atomic.js";
|
||||
|
||||
export interface CommonConfig {
|
||||
name?: string
|
||||
@@ -49,3 +49,7 @@ export interface PollingOptions {
|
||||
* */
|
||||
maxInterval?: number
|
||||
}
|
||||
|
||||
export type PlayTransformConfig = PlayTransformHooks<SearchAndReplaceTerm>;
|
||||
|
||||
export type PlayTransformOptions = PlayTransformConfig & { log?: boolean }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CommonConfig, CommonData, RequestRetryOptions } from "../common.js";
|
||||
import { CommonConfig, CommonData, PlayTransformConfig, PlayTransformOptions, RequestRetryOptions } from "../common.js";
|
||||
|
||||
export interface SourceRetryOptions extends RequestRetryOptions {
|
||||
/**
|
||||
@@ -96,6 +96,8 @@ export interface CommonSourceOptions extends SourceRetryOptions {
|
||||
* * If not specified it defaults to the maximum number of listens the source API supports
|
||||
* */
|
||||
scrobbleBacklogCount?: number
|
||||
|
||||
playTransform?: PlayTransformOptions
|
||||
}
|
||||
|
||||
export interface CommonSourceData extends CommonData {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { CommonSourceConfig, CommonSourceData, CommonSourceOptions } from "./index.js";
|
||||
|
||||
export interface MPDData extends CommonSourceData {
|
||||
/**
|
||||
* URL:PORT of the MPD server to connect to
|
||||
*
|
||||
* To use this you must have TCP connections enabled for your MPD server https://mpd.readthedocs.io/en/stable/user.html#client-connections
|
||||
*
|
||||
* @examples ["localhost:6600"]
|
||||
* @default "localhost:6600"
|
||||
* */
|
||||
url?: string
|
||||
|
||||
/**
|
||||
* If using socket specify the path instead of url.
|
||||
*
|
||||
* trailing `~` is replaced by your home directory
|
||||
* */
|
||||
path?: string
|
||||
|
||||
/**
|
||||
* Password for the server, if set https://mpd.readthedocs.io/en/stable/user.html#permissions-and-passwords
|
||||
* */
|
||||
password?: string
|
||||
|
||||
}
|
||||
|
||||
export interface MPDSourceOptions extends CommonSourceOptions {
|
||||
//disableDiscovery?: boolean
|
||||
}
|
||||
|
||||
export interface MPDSourceConfig extends CommonSourceConfig {
|
||||
data: MPDData
|
||||
options: MPDSourceOptions
|
||||
}
|
||||
|
||||
export interface MPDSourceAIOConfig extends MPDSourceConfig {
|
||||
type: 'mpd'
|
||||
}
|
||||
|
||||
export type PlayerState = 'play' | 'stop' | 'pause';
|
||||
|
||||
export interface StatusResponse {
|
||||
state: PlayerState
|
||||
/**
|
||||
* Position within the current song in seconds
|
||||
* */
|
||||
elapsed?: number
|
||||
/**
|
||||
* Duration of the current song in seconds
|
||||
* */
|
||||
duration?: number
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface CurrentSongResponse {
|
||||
file: string
|
||||
time: number
|
||||
name?: string
|
||||
performer?: string
|
||||
artist?: string
|
||||
album?: string
|
||||
albumartist?: string
|
||||
title?: string
|
||||
musicbrainz_albumartistid?: string
|
||||
musicbrainz_albumid?: string
|
||||
musicbrainz_artistid?: string
|
||||
musicbrainz_releasetrackid?: string
|
||||
musicbrainz_trackid?: string
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { KodiSourceAIOConfig, KodiSourceConfig } from "./kodi.js";
|
||||
import { LastFmSouceAIOConfig, LastfmSourceConfig } from "./lastfm.js";
|
||||
import { ListenBrainzSourceAIOConfig, ListenBrainzSourceConfig } from "./listenbrainz.js";
|
||||
import { MopidySourceAIOConfig, MopidySourceConfig } from "./mopidy.js";
|
||||
import { MPDSourceAIOConfig, MPDSourceConfig } from "./mpd.js";
|
||||
import { MPRISSourceAIOConfig, MPRISSourceConfig } from "./mpris.js";
|
||||
import { MusikcubeSourceAIOConfig, MusikcubeSourceConfig } from "./musikcube.js";
|
||||
import { PlexSourceAIOConfig, PlexSourceConfig } from "./plex.js";
|
||||
@@ -32,7 +33,8 @@ export type SourceConfig =
|
||||
| KodiSourceConfig
|
||||
| WebScrobblerSourceConfig
|
||||
| ChromecastSourceConfig
|
||||
| MusikcubeSourceConfig;
|
||||
| MusikcubeSourceConfig
|
||||
| MPDSourceConfig;
|
||||
|
||||
export type SourceAIOConfig =
|
||||
SpotifySourceAIOConfig
|
||||
@@ -50,4 +52,5 @@ export type SourceAIOConfig =
|
||||
| KodiSourceAIOConfig
|
||||
| WebScrobblerSourceAIOConfig
|
||||
| ChromecastSourceAIOConfig
|
||||
| MusikcubeSourceAIOConfig;
|
||||
| MusikcubeSourceAIOConfig
|
||||
| MPDSourceAIOConfig;
|
||||
|
||||
@@ -57,6 +57,15 @@
|
||||
"title": "refreshEnabled",
|
||||
"type": "boolean"
|
||||
},
|
||||
"refreshForce": {
|
||||
"default": false,
|
||||
"description": "Force client to always refresh scrobbled plays from service before scrobbling new play\n\nWARNING: This will cause increased load on the scrobble service and potentially slow down scrobble speed as well. This should be used as a debugging tool and not be always-on.",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"title": "refreshForce",
|
||||
"type": "boolean"
|
||||
},
|
||||
"refreshInitialCount": {
|
||||
"description": "The number of tracks to retrieve on initial refresh (related to scrobbleBacklogCount). If not specified this is the maximum supported for the client.",
|
||||
"title": "refreshInitialCount",
|
||||
|
||||
@@ -969,6 +969,169 @@
|
||||
"title": "ListenBrainzSourceData",
|
||||
"type": "object"
|
||||
},
|
||||
"MPDData": {
|
||||
"properties": {
|
||||
"password": {
|
||||
"description": "Password for the server, if set https://mpd.readthedocs.io/en/stable/user.html#permissions-and-passwords",
|
||||
"title": "password",
|
||||
"type": "string"
|
||||
},
|
||||
"path": {
|
||||
"description": "If using socket specify the path instead of url.\n\ntrailing `~` is replaced by your home directory",
|
||||
"title": "path",
|
||||
"type": "string"
|
||||
},
|
||||
"url": {
|
||||
"default": "localhost:6600",
|
||||
"description": "URL:PORT of the MPD server to connect to\n\nTo use this you must have TCP connections enabled for your MPD server https://mpd.readthedocs.io/en/stable/user.html#client-connections",
|
||||
"examples": [
|
||||
"localhost:6600"
|
||||
],
|
||||
"title": "url",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"title": "MPDData",
|
||||
"type": "object"
|
||||
},
|
||||
"MPDSourceAIOConfig": {
|
||||
"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/MPDData",
|
||||
"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/MPDSourceOptions",
|
||||
"title": "options"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"mpd"
|
||||
],
|
||||
"title": "type",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data",
|
||||
"options",
|
||||
"type"
|
||||
],
|
||||
"title": "MPDSourceAIOConfig",
|
||||
"type": "object"
|
||||
},
|
||||
"MPDSourceOptions": {
|
||||
"properties": {
|
||||
"logFilterFailure": {
|
||||
"default": "warn",
|
||||
"description": "If this source has INGRESS to MS and has filters this determines how MS logs when a payload (event) fails a defined filter (IE users/servers/library filters)\n\n* `false` => do not log\n* `debug` => log to DEBUG level\n* `warn` => log to WARN level (default)\n\nHint: This is useful if you are sure this source is setup correctly and you have multiple other sources. Set to `debug` or `false` to reduce log noise.",
|
||||
"enum": [
|
||||
"debug",
|
||||
false,
|
||||
"warn"
|
||||
],
|
||||
"examples": [
|
||||
"warn"
|
||||
],
|
||||
"title": "logFilterFailure"
|
||||
},
|
||||
"logPayload": {
|
||||
"default": false,
|
||||
"description": "If this source has INGRESS to MS (sends a payload, rather than MS GETTING requesting a payload)\nthen setting this option to true will make MS log the payload JSON to DEBUG output",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"title": "logPayload",
|
||||
"type": "boolean"
|
||||
},
|
||||
"logPlayerState": {
|
||||
"default": false,
|
||||
"description": "For Sources that track Player State (currently playing) this logs a simple player state/summary to DEBUG output",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"title": "logPlayerState",
|
||||
"type": "boolean"
|
||||
},
|
||||
"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/client can make before error is thrown",
|
||||
"examples": [
|
||||
1
|
||||
],
|
||||
"title": "maxRequestRetries",
|
||||
"type": "number"
|
||||
},
|
||||
"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"
|
||||
},
|
||||
"scrobbleBacklog": {
|
||||
"default": true,
|
||||
"description": "If this source\n\n* supports fetching a listen history\n* and this option is enabled\n\nthen on startup MS will attempt to scrobble the recent listens from that history",
|
||||
"examples": [
|
||||
true,
|
||||
false
|
||||
],
|
||||
"title": "scrobbleBacklog",
|
||||
"type": "boolean"
|
||||
},
|
||||
"scrobbleBacklogCount": {
|
||||
"description": "The number of listens to fetch when scrobbling from backlog\n\n* Only applies if this source supports fetching a listen history\n* If not specified it defaults to the maximum number of listens the source API supports",
|
||||
"title": "scrobbleBacklogCount",
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"title": "MPDSourceOptions",
|
||||
"type": "object"
|
||||
},
|
||||
"MPRISData": {
|
||||
"properties": {
|
||||
"blacklist": {
|
||||
@@ -1440,6 +1603,9 @@
|
||||
{
|
||||
"$ref": "#/definitions/MopidySourceAIOConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MPDSourceAIOConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MPRISSourceAIOConfig"
|
||||
},
|
||||
|
||||
@@ -346,6 +346,15 @@
|
||||
"title": "refreshEnabled",
|
||||
"type": "boolean"
|
||||
},
|
||||
"refreshForce": {
|
||||
"default": false,
|
||||
"description": "Force client to always refresh scrobbled plays from service before scrobbling new play\n\nWARNING: This will cause increased load on the scrobble service and potentially slow down scrobble speed as well. This should be used as a debugging tool and not be always-on.",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"title": "refreshForce",
|
||||
"type": "boolean"
|
||||
},
|
||||
"refreshInitialCount": {
|
||||
"description": "The number of tracks to retrieve on initial refresh (related to scrobbleBacklogCount). If not specified this is the maximum supported for the client.",
|
||||
"title": "refreshInitialCount",
|
||||
@@ -417,6 +426,15 @@
|
||||
"title": "refreshEnabled",
|
||||
"type": "boolean"
|
||||
},
|
||||
"refreshForce": {
|
||||
"default": false,
|
||||
"description": "Force client to always refresh scrobbled plays from service before scrobbling new play\n\nWARNING: This will cause increased load on the scrobble service and potentially slow down scrobble speed as well. This should be used as a debugging tool and not be always-on.",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"title": "refreshForce",
|
||||
"type": "boolean"
|
||||
},
|
||||
"refreshInitialCount": {
|
||||
"description": "The number of tracks to retrieve on initial refresh (related to scrobbleBacklogCount). If not specified this is the maximum supported for the client.",
|
||||
"title": "refreshInitialCount",
|
||||
@@ -1603,6 +1621,169 @@
|
||||
"title": "LogOptions",
|
||||
"type": "object"
|
||||
},
|
||||
"MPDData": {
|
||||
"properties": {
|
||||
"password": {
|
||||
"description": "Password for the server, if set https://mpd.readthedocs.io/en/stable/user.html#permissions-and-passwords",
|
||||
"title": "password",
|
||||
"type": "string"
|
||||
},
|
||||
"path": {
|
||||
"description": "If using socket specify the path instead of url.\n\ntrailing `~` is replaced by your home directory",
|
||||
"title": "path",
|
||||
"type": "string"
|
||||
},
|
||||
"url": {
|
||||
"default": "localhost:6600",
|
||||
"description": "URL:PORT of the MPD server to connect to\n\nTo use this you must have TCP connections enabled for your MPD server https://mpd.readthedocs.io/en/stable/user.html#client-connections",
|
||||
"examples": [
|
||||
"localhost:6600"
|
||||
],
|
||||
"title": "url",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"title": "MPDData",
|
||||
"type": "object"
|
||||
},
|
||||
"MPDSourceAIOConfig": {
|
||||
"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/MPDData",
|
||||
"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/MPDSourceOptions",
|
||||
"title": "options"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"mpd"
|
||||
],
|
||||
"title": "type",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data",
|
||||
"options",
|
||||
"type"
|
||||
],
|
||||
"title": "MPDSourceAIOConfig",
|
||||
"type": "object"
|
||||
},
|
||||
"MPDSourceOptions": {
|
||||
"properties": {
|
||||
"logFilterFailure": {
|
||||
"default": "warn",
|
||||
"description": "If this source has INGRESS to MS and has filters this determines how MS logs when a payload (event) fails a defined filter (IE users/servers/library filters)\n\n* `false` => do not log\n* `debug` => log to DEBUG level\n* `warn` => log to WARN level (default)\n\nHint: This is useful if you are sure this source is setup correctly and you have multiple other sources. Set to `debug` or `false` to reduce log noise.",
|
||||
"enum": [
|
||||
"debug",
|
||||
false,
|
||||
"warn"
|
||||
],
|
||||
"examples": [
|
||||
"warn"
|
||||
],
|
||||
"title": "logFilterFailure"
|
||||
},
|
||||
"logPayload": {
|
||||
"default": false,
|
||||
"description": "If this source has INGRESS to MS (sends a payload, rather than MS GETTING requesting a payload)\nthen setting this option to true will make MS log the payload JSON to DEBUG output",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"title": "logPayload",
|
||||
"type": "boolean"
|
||||
},
|
||||
"logPlayerState": {
|
||||
"default": false,
|
||||
"description": "For Sources that track Player State (currently playing) this logs a simple player state/summary to DEBUG output",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"title": "logPlayerState",
|
||||
"type": "boolean"
|
||||
},
|
||||
"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/client can make before error is thrown",
|
||||
"examples": [
|
||||
1
|
||||
],
|
||||
"title": "maxRequestRetries",
|
||||
"type": "number"
|
||||
},
|
||||
"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"
|
||||
},
|
||||
"scrobbleBacklog": {
|
||||
"default": true,
|
||||
"description": "If this source\n\n* supports fetching a listen history\n* and this option is enabled\n\nthen on startup MS will attempt to scrobble the recent listens from that history",
|
||||
"examples": [
|
||||
true,
|
||||
false
|
||||
],
|
||||
"title": "scrobbleBacklog",
|
||||
"type": "boolean"
|
||||
},
|
||||
"scrobbleBacklogCount": {
|
||||
"description": "The number of listens to fetch when scrobbling from backlog\n\n* Only applies if this source supports fetching a listen history\n* If not specified it defaults to the maximum number of listens the source API supports",
|
||||
"title": "scrobbleBacklogCount",
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"title": "MPDSourceOptions",
|
||||
"type": "object"
|
||||
},
|
||||
"MPRISData": {
|
||||
"properties": {
|
||||
"blacklist": {
|
||||
@@ -2285,6 +2466,9 @@
|
||||
{
|
||||
"$ref": "#/definitions/MopidySourceAIOConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MPDSourceAIOConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MPRISSourceAIOConfig"
|
||||
},
|
||||
|
||||
@@ -54,6 +54,15 @@
|
||||
"title": "refreshEnabled",
|
||||
"type": "boolean"
|
||||
},
|
||||
"refreshForce": {
|
||||
"default": false,
|
||||
"description": "Force client to always refresh scrobbled plays from service before scrobbling new play\n\nWARNING: This will cause increased load on the scrobble service and potentially slow down scrobble speed as well. This should be used as a debugging tool and not be always-on.",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"title": "refreshForce",
|
||||
"type": "boolean"
|
||||
},
|
||||
"refreshInitialCount": {
|
||||
"description": "The number of tracks to retrieve on initial refresh (related to scrobbleBacklogCount). If not specified this is the maximum supported for the client.",
|
||||
"title": "refreshInitialCount",
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
{
|
||||
"$ref": "#/definitions/MopidySourceConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MPDSourceConfig"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/MPRISSourceConfig"
|
||||
},
|
||||
@@ -963,6 +966,161 @@
|
||||
"title": "ListenBrainzSourceData",
|
||||
"type": "object"
|
||||
},
|
||||
"MPDData": {
|
||||
"properties": {
|
||||
"password": {
|
||||
"description": "Password for the server, if set https://mpd.readthedocs.io/en/stable/user.html#permissions-and-passwords",
|
||||
"title": "password",
|
||||
"type": "string"
|
||||
},
|
||||
"path": {
|
||||
"description": "If using socket specify the path instead of url.\n\ntrailing `~` is replaced by your home directory",
|
||||
"title": "path",
|
||||
"type": "string"
|
||||
},
|
||||
"url": {
|
||||
"default": "localhost:6600",
|
||||
"description": "URL:PORT of the MPD server to connect to\n\nTo use this you must have TCP connections enabled for your MPD server https://mpd.readthedocs.io/en/stable/user.html#client-connections",
|
||||
"examples": [
|
||||
"localhost:6600"
|
||||
],
|
||||
"title": "url",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"title": "MPDData",
|
||||
"type": "object"
|
||||
},
|
||||
"MPDSourceConfig": {
|
||||
"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/MPDData",
|
||||
"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/MPDSourceOptions",
|
||||
"title": "options"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data",
|
||||
"options"
|
||||
],
|
||||
"title": "MPDSourceConfig",
|
||||
"type": "object"
|
||||
},
|
||||
"MPDSourceOptions": {
|
||||
"properties": {
|
||||
"logFilterFailure": {
|
||||
"default": "warn",
|
||||
"description": "If this source has INGRESS to MS and has filters this determines how MS logs when a payload (event) fails a defined filter (IE users/servers/library filters)\n\n* `false` => do not log\n* `debug` => log to DEBUG level\n* `warn` => log to WARN level (default)\n\nHint: This is useful if you are sure this source is setup correctly and you have multiple other sources. Set to `debug` or `false` to reduce log noise.",
|
||||
"enum": [
|
||||
"debug",
|
||||
false,
|
||||
"warn"
|
||||
],
|
||||
"examples": [
|
||||
"warn"
|
||||
],
|
||||
"title": "logFilterFailure"
|
||||
},
|
||||
"logPayload": {
|
||||
"default": false,
|
||||
"description": "If this source has INGRESS to MS (sends a payload, rather than MS GETTING requesting a payload)\nthen setting this option to true will make MS log the payload JSON to DEBUG output",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"title": "logPayload",
|
||||
"type": "boolean"
|
||||
},
|
||||
"logPlayerState": {
|
||||
"default": false,
|
||||
"description": "For Sources that track Player State (currently playing) this logs a simple player state/summary to DEBUG output",
|
||||
"examples": [
|
||||
false
|
||||
],
|
||||
"title": "logPlayerState",
|
||||
"type": "boolean"
|
||||
},
|
||||
"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/client can make before error is thrown",
|
||||
"examples": [
|
||||
1
|
||||
],
|
||||
"title": "maxRequestRetries",
|
||||
"type": "number"
|
||||
},
|
||||
"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"
|
||||
},
|
||||
"scrobbleBacklog": {
|
||||
"default": true,
|
||||
"description": "If this source\n\n* supports fetching a listen history\n* and this option is enabled\n\nthen on startup MS will attempt to scrobble the recent listens from that history",
|
||||
"examples": [
|
||||
true,
|
||||
false
|
||||
],
|
||||
"title": "scrobbleBacklog",
|
||||
"type": "boolean"
|
||||
},
|
||||
"scrobbleBacklogCount": {
|
||||
"description": "The number of listens to fetch when scrobbling from backlog\n\n* Only applies if this source supports fetching a listen history\n* If not specified it defaults to the maximum number of listens the source API supports",
|
||||
"title": "scrobbleBacklogCount",
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"title": "MPDSourceOptions",
|
||||
"type": "object"
|
||||
},
|
||||
"MPRISData": {
|
||||
"properties": {
|
||||
"blacklist": {
|
||||
|
||||
+30
-5
@@ -1,6 +1,6 @@
|
||||
import { stringSameness } from '@foxxmd/string-sameness';
|
||||
import dayjs from "dayjs";
|
||||
import request, { Request } from 'superagent';
|
||||
import request, { Request, Response } from 'superagent';
|
||||
import { PlayObject } from "../../../core/Atomic.js";
|
||||
import { slice } from "../../../core/StringUtils.js";
|
||||
import { combinePartsToString } from "../../utils.js";
|
||||
@@ -127,7 +127,7 @@ export class ListenbrainzApiClient extends AbstractApiClient {
|
||||
}
|
||||
|
||||
|
||||
callApi = async <T>(req: Request, retries = 0): Promise<T> => {
|
||||
callApi = async <T = Response>(req: Request, retries = 0): Promise<T> => {
|
||||
const {
|
||||
maxRequestRetries = 2,
|
||||
retryMultiplier = DEFAULT_RETRY_MULTIPLIER
|
||||
@@ -248,17 +248,27 @@ export class ListenbrainzApiClient extends AbstractApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
submitListen = async (play: PlayObject) => {
|
||||
submitListen = async (play: PlayObject, log: boolean = false) => {
|
||||
try {
|
||||
const listenPayload: SubmitPayload = {listen_type: 'single', payload: [ListenbrainzApiClient.playToListenPayload(play)]};
|
||||
await this.callApi(request.post(`${this.url}1/submit-listens`).type('json').send(listenPayload));
|
||||
if(log) {
|
||||
this.logger.debug(`Submit Payload: ${JSON.stringify(listenPayload)}`);
|
||||
}
|
||||
// response consists of {"status": "ok"}
|
||||
// so no useful information
|
||||
// https://listenbrainz.readthedocs.io/en/latest/users/api-usage.html#submitting-listens
|
||||
// TODO may we should make a call to recent-listens to get the parsed scrobble?
|
||||
const resp = await this.callApi(request.post(`${this.url}1/submit-listens`).type('json').send(listenPayload));
|
||||
if(log) {
|
||||
this.logger.debug(`Submit Response: ${resp.text}`)
|
||||
}
|
||||
return listenPayload;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
static playToListenPayload = (play: PlayObject): ListenPayload => {
|
||||
static playToListenPayload(play: PlayObject): ListenPayload {
|
||||
const {
|
||||
data: {
|
||||
playDate,
|
||||
@@ -581,6 +591,21 @@ export class ListenbrainzApiClient extends AbstractApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
static submitToPlayObj(submitObj: SubmitPayload, playObj: PlayObject): PlayObject {
|
||||
if (submitObj.payload.length > 0) {
|
||||
const respPlay = {
|
||||
...playObj,
|
||||
};
|
||||
respPlay.data = {
|
||||
...playObj.data,
|
||||
album: submitObj.payload[0].track_metadata?.release_name ?? playObj.data.album,
|
||||
track: submitObj.payload[0].track_metadata?.track_name ?? playObj.data.album,
|
||||
};
|
||||
return respPlay;
|
||||
}
|
||||
return playObj;
|
||||
}
|
||||
|
||||
static formatPlayObj(obj: any, options: FormatPlayObjectOptions): PlayObject {
|
||||
return ListenbrainzApiClient.listenResponseToPlay(obj);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import dayjs, { Dayjs } from "dayjs";
|
||||
import EventEmitter from "events";
|
||||
import { FixedSizeList } from 'fixed-size-list';
|
||||
import { nanoid } from "nanoid";
|
||||
import { Simulate } from "react-dom/test-utils";
|
||||
import {
|
||||
DeadLetterScrobble,
|
||||
PlayObject,
|
||||
@@ -23,7 +24,7 @@ import {
|
||||
FormatPlayObjectOptions,
|
||||
ScrobbledPlayObject,
|
||||
TIME_WEIGHT,
|
||||
TITLE_WEIGHT,
|
||||
TITLE_WEIGHT, TRANSFORM_HOOK,
|
||||
} from "../common/infrastructure/Atomic.js";
|
||||
import { CommonClientConfig } from "../common/infrastructure/config/client/index.js";
|
||||
import { Notifiers } from "../notifier/Notifiers.js";
|
||||
@@ -73,13 +74,13 @@ export default abstract class AbstractScrobbleClient extends AbstractComponent i
|
||||
queuedScrobbles: QueuedScrobble<PlayObject>[] = [];
|
||||
deadLetterScrobbles: DeadLetterScrobble<PlayObject>[] = [];
|
||||
|
||||
config: CommonClientConfig;
|
||||
declare config: CommonClientConfig;
|
||||
|
||||
notifier: Notifiers;
|
||||
emitter: EventEmitter;
|
||||
|
||||
constructor(type: any, name: any, config: CommonClientConfig, notifier: Notifiers, emitter: EventEmitter, logger: Logger) {
|
||||
super();
|
||||
super(config);
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.identifier = `${capitalize(this.type)} - ${name}`;
|
||||
@@ -89,7 +90,6 @@ export default abstract class AbstractScrobbleClient extends AbstractComponent i
|
||||
|
||||
this.scrobbledPlayObjs = new FixedSizeList<ScrobbledPlayObject>(this.MAX_STORED_SCROBBLES);
|
||||
|
||||
this.config = config;
|
||||
const {
|
||||
options: {
|
||||
refreshEnabled = true,
|
||||
@@ -148,8 +148,60 @@ export default abstract class AbstractScrobbleClient extends AbstractComponent i
|
||||
await this.refreshScrobbles(initialLimit);
|
||||
}
|
||||
|
||||
refreshScrobbles = async (limit?: number) => {
|
||||
this.logger.debug('Scrobbler does not have refresh function implemented!');
|
||||
refreshScrobbles = async (limit: number = this.MAX_STORED_SCROBBLES) => {
|
||||
if (this.refreshEnabled) {
|
||||
this.logger.debug('Refreshing recent scrobbles');
|
||||
const recent = await this.getScrobblesForRefresh(limit);
|
||||
this.logger.debug(`Found ${recent.length} recent scrobbles`);
|
||||
if (this.recentScrobbles.length > 0) {
|
||||
const [{data: {playDate: newestScrobbleTime = dayjs()} = {}} = {}] = this.recentScrobbles.slice(-1);
|
||||
const [{data: {playDate: oldestScrobbleTime = dayjs()} = {}} = {}] = this.recentScrobbles.slice(0, 1);
|
||||
this.newestScrobbleTime = newestScrobbleTime;
|
||||
this.oldestScrobbleTime = oldestScrobbleTime;
|
||||
|
||||
this.filterScrobbledTracks();
|
||||
}
|
||||
}
|
||||
this.lastScrobbleCheck = dayjs();
|
||||
}
|
||||
|
||||
protected abstract getScrobblesForRefresh(limit: number): Promise<PlayObject[]>;
|
||||
|
||||
shouldRefreshScrobble = () => {
|
||||
const {
|
||||
refreshStaleAfter
|
||||
} = this.config.options || {};
|
||||
|
||||
if (!this.refreshEnabled) {
|
||||
this.logger.debug(`Should NOT refresh scrobbles => refreshEnabled is false`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const queuedPlayedDate = this.getLatestQueuePlayDate();
|
||||
|
||||
// if next queued play was played more recently than the last time we refreshed upstream scrobbles
|
||||
if (this.lastScrobbleCheck.unix() < queuedPlayedDate.unix()) {
|
||||
this.logger.debug('Should refresh scrobbles => queued scrobble playDate is newer than last upstream scrobble refresh');
|
||||
return true;
|
||||
}
|
||||
|
||||
// if the last scrobbled play is at or is newer than the next scrobble then we are inserting (or potentially duping)
|
||||
// in which case our data is probably stale
|
||||
if(this.newestScrobbleTime !== undefined && this.newestScrobbleTime.unix() >= queuedPlayedDate.unix()) {
|
||||
this.logger.debug('Should refresh scrobbles => queued scrobble playDate is equal to or older than the newest upstream scrobble');
|
||||
return true;
|
||||
}
|
||||
|
||||
if(refreshStaleAfter !== undefined) {
|
||||
const diff = dayjs().diff(this.lastScrobbleCheck, 's');
|
||||
if(diff > refreshStaleAfter) {
|
||||
this.logger.debug(`Should refresh scrobbles => last refresh (${diff}s ago) was longer than refreshStaleAfter (${refreshStaleAfter}s)`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.debug('Scrobble refresh not needed');
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract alreadyScrobbled(playObj: PlayObject, log?: boolean): Promise<boolean>;
|
||||
@@ -193,17 +245,13 @@ export default abstract class AbstractScrobbleClient extends AbstractComponent i
|
||||
|
||||
getScrobbledPlays = () => this.scrobbledPlayObjs.data.map(x => x.scrobble)
|
||||
|
||||
findExistingSubmittedPlayObj = (playObj: PlayObject): ([undefined, undefined] | [ScrobbledPlayObject, ScrobbledPlayObject[]]) => {
|
||||
const {
|
||||
data: {
|
||||
playDate
|
||||
} = {},
|
||||
meta: {
|
||||
source,
|
||||
} = {}
|
||||
} = playObj;
|
||||
findExistingSubmittedPlayObj = (playObjPre: PlayObject): ([undefined, undefined] | [ScrobbledPlayObject, ScrobbledPlayObject[]]) => {
|
||||
|
||||
const dtInvariantMatches = this.scrobbledPlayObjs.data.filter(x => playObjDataMatch(playObj, x.play));
|
||||
const playObj = this.transformPlay(playObjPre, TRANSFORM_HOOK.candidate);
|
||||
|
||||
const dtInvariantMatches = this.scrobbledPlayObjs.data
|
||||
.map(x => ({...x, play: this.transformPlay(x.play, TRANSFORM_HOOK.existing)}))
|
||||
.filter(x => playObjDataMatch(playObj, x.play));
|
||||
|
||||
if (dtInvariantMatches.length === 0) {
|
||||
return [undefined, []];
|
||||
@@ -240,7 +288,10 @@ export default abstract class AbstractScrobbleClient extends AbstractComponent i
|
||||
return [Math.min(compareScrobbleArtists(existing, candidate)/100, 1), wholeMatches]
|
||||
}
|
||||
|
||||
existingScrobble = async (playObj: PlayObject) => {
|
||||
existingScrobble = async (playObjPre: PlayObject) => {
|
||||
|
||||
const playObj = this.transformPlay(playObjPre, TRANSFORM_HOOK.candidate);
|
||||
|
||||
const tr = truncateStringToLength(27);
|
||||
const scoreTrackOpts: TrackStringOptions = {include: ['track', 'artist', 'time'], transformers: {track: (t: any, data, existing) => `${existing ? '- ': ''}${tr(t)}`}};
|
||||
|
||||
@@ -256,7 +307,7 @@ export default abstract class AbstractScrobbleClient extends AbstractComponent i
|
||||
let closestMatch: {score: number, breakdowns: string[], confidence: string, scrobble?: PlayObject} = {score: 0, breakdowns: [], confidence: 'No existing scrobble matched with a score higher than 0'};
|
||||
|
||||
// then check if we have already recorded this
|
||||
const [existingExactSubmitted, existingDataSubmitted = []] = this.findExistingSubmittedPlayObj(playObj);
|
||||
const [existingExactSubmitted, existingDataSubmitted = []] = this.findExistingSubmittedPlayObj(playObjPre);
|
||||
|
||||
// if we have an submitted play with matching data and play date then we can just return the response from the original scrobble
|
||||
if (existingExactSubmitted !== undefined) {
|
||||
@@ -287,7 +338,9 @@ export default abstract class AbstractScrobbleClient extends AbstractComponent i
|
||||
// in which case we can check the scrobble api response against recent scrobbles (also from api) for a more accurate comparison
|
||||
const referenceApiScrobbleResponse = existingDataSubmitted.length > 0 ? existingDataSubmitted[0].scrobble : undefined;
|
||||
|
||||
existingScrobble = this.recentScrobbles.find((x) => {
|
||||
existingScrobble = this.recentScrobbles.find((xPre) => {
|
||||
|
||||
const x = this.transformPlay(xPre, TRANSFORM_HOOK.existing);
|
||||
|
||||
//const referenceMatch = referenceApiScrobbleResponse !== undefined && playObjDataMatch(x, referenceApiScrobbleResponse);
|
||||
|
||||
@@ -525,20 +578,21 @@ ${closestMatch.breakdowns.join('\n')}`, {leaf: ['Dupe Check']});
|
||||
this.scrobbling = true;
|
||||
while (!this.shouldStopScrobbleProcessing()) {
|
||||
while (this.queuedScrobbles.length > 0) {
|
||||
if (this.lastScrobbleCheck.unix() < this.getLatestQueuePlayDate().unix()) {
|
||||
if (this.shouldRefreshScrobble()) {
|
||||
await this.refreshScrobbles();
|
||||
}
|
||||
const currQueuedPlay = this.queuedScrobbles.shift();
|
||||
const [timeFrameValid, timeFrameValidLog] = this.timeFrameIsValid(currQueuedPlay.play);
|
||||
if (timeFrameValid && !(await this.alreadyScrobbled(currQueuedPlay.play))) {
|
||||
const transformedScrobble = this.transformPlay(currQueuedPlay.play, TRANSFORM_HOOK.postCompare);
|
||||
try {
|
||||
const scrobbledPlay = await this.scrobble(currQueuedPlay.play);
|
||||
this.emitEvent('scrobble', {play: currQueuedPlay.play});
|
||||
this.addScrobbledTrack(currQueuedPlay.play, scrobbledPlay);
|
||||
const scrobbledPlay = await this.scrobble(transformedScrobble);
|
||||
this.emitEvent('scrobble', {play: transformedScrobble});
|
||||
this.addScrobbledTrack(transformedScrobble, scrobbledPlay);
|
||||
} catch (e) {
|
||||
if (e instanceof UpstreamError && e.showStopper === false) {
|
||||
this.addDeadLetterScrobble(currQueuedPlay, e);
|
||||
this.logger.warn(new Error(`Could not scrobble ${buildTrackString(currQueuedPlay.play)} from Source '${currQueuedPlay.source}' but error was not show stopping. Adding scrobble to Dead Letter Queue and will retry on next heartbeat.`, {cause: e}));
|
||||
this.logger.warn(new Error(`Could not scrobble ${buildTrackString(transformedScrobble)} from Source '${currQueuedPlay.source}' but error was not show stopping. Adding scrobble to Dead Letter Queue and will retry on next heartbeat.`, {cause: e}));
|
||||
} else {
|
||||
this.queuedScrobbles.unshift(currQueuedPlay);
|
||||
throw new Error('Error occurred while trying to scrobble', {cause: e});
|
||||
@@ -613,15 +667,16 @@ ${closestMatch.breakdowns.join('\n')}`, {leaf: ['Dupe Check']});
|
||||
}
|
||||
const [timeFrameValid, timeFrameValidLog] = this.timeFrameIsValid(deadScrobble.play);
|
||||
if (timeFrameValid && !(await this.alreadyScrobbled(deadScrobble.play))) {
|
||||
const transformedScrobble = this.transformPlay(deadScrobble.play, TRANSFORM_HOOK.postCompare);
|
||||
try {
|
||||
const scrobbledPlay = await this.scrobble(deadScrobble.play);
|
||||
this.emitEvent('scrobble', {play: deadScrobble.play});
|
||||
this.addScrobbledTrack(deadScrobble.play, scrobbledPlay);
|
||||
const scrobbledPlay = await this.scrobble(transformedScrobble);
|
||||
this.emitEvent('scrobble', {play: transformedScrobble});
|
||||
this.addScrobbledTrack(transformedScrobble, scrobbledPlay);
|
||||
} catch (e) {
|
||||
deadScrobble.retries++;
|
||||
deadScrobble.error = messageWithCauses(e);
|
||||
deadScrobble.lastRetry = dayjs();
|
||||
this.logger.error(new Error(`Could not scrobble ${buildTrackString(deadScrobble.play)} from Source '${deadScrobble.source}' due to error`, {cause: e}));
|
||||
this.logger.error(new Error(`Could not scrobble ${buildTrackString(transformedScrobble)} from Source '${deadScrobble.source}' due to error`, {cause: e}));
|
||||
this.deadLetterScrobbles[deadScrobbleIndex] = deadScrobble;
|
||||
return [false, deadScrobble];
|
||||
} finally {
|
||||
@@ -661,7 +716,8 @@ ${closestMatch.breakdowns.join('\n')}`, {leaf: ['Dupe Check']});
|
||||
queueScrobble = (data: PlayObject | PlayObject[], source: string) => {
|
||||
const plays = Array.isArray(data) ? data : [data];
|
||||
for(const p of plays) {
|
||||
const queuedPlay = {id: nanoid(), source, play: p}
|
||||
const transformedPlay = this.transformPlay(p, TRANSFORM_HOOK.preCompare);
|
||||
const queuedPlay = {id: nanoid(), source, play: transformedPlay}
|
||||
this.emitEvent('scrobbleQueued', {queuedPlay: queuedPlay});
|
||||
this.queuedScrobbles.push(queuedPlay);
|
||||
}
|
||||
|
||||
@@ -46,9 +46,7 @@ export default class LastfmScrobbler extends AbstractScrobbleClient {
|
||||
}
|
||||
}
|
||||
|
||||
refreshScrobbles = async (limit = this.MAX_STORED_SCROBBLES) => {
|
||||
if (this.refreshEnabled) {
|
||||
this.logger.debug('Refreshing recent scrobbles');
|
||||
getScrobblesForRefresh = async (limit: number) => {
|
||||
const resp = await this.api.callApi<UserGetRecentTracksResponse>((client: any) => client.userGetRecentTracks({
|
||||
user: this.api.user,
|
||||
sk: this.api.client.sessionKey,
|
||||
@@ -60,7 +58,7 @@ export default class LastfmScrobbler extends AbstractScrobbleClient {
|
||||
track: list = [],
|
||||
}
|
||||
} = resp;
|
||||
this.recentScrobbles = list.reduce((acc: any, x: any) => {
|
||||
return list.reduce((acc: any, x: any) => {
|
||||
try {
|
||||
const formatted = LastfmApiClient.formatPlayObj(x);
|
||||
const {
|
||||
@@ -91,17 +89,6 @@ export default class LastfmScrobbler extends AbstractScrobbleClient {
|
||||
return acc;
|
||||
}
|
||||
}, []);
|
||||
this.logger.debug(`Found ${this.recentScrobbles.length} recent scrobbles`);
|
||||
if (this.recentScrobbles.length > 0) {
|
||||
const [{data: {playDate: newestScrobbleTime = dayjs()} = {}} = {}] = this.recentScrobbles.slice(-1);
|
||||
const [{data: {playDate: oldestScrobbleTime = dayjs()} = {}} = {}] = this.recentScrobbles.slice(0, 1);
|
||||
this.newestScrobbleTime = newestScrobbleTime;
|
||||
this.oldestScrobbleTime = oldestScrobbleTime;
|
||||
|
||||
this.filterScrobbledTracks();
|
||||
}
|
||||
}
|
||||
this.lastScrobbleCheck = dayjs();
|
||||
}
|
||||
|
||||
cleanSourceSearchTitle = (playObj: PlayObject) => {
|
||||
|
||||
@@ -59,22 +59,8 @@ export default class ListenbrainzScrobbler extends AbstractScrobbleClient {
|
||||
}
|
||||
}
|
||||
|
||||
refreshScrobbles = async (limit = this.MAX_STORED_SCROBBLES) => {
|
||||
if (this.refreshEnabled) {
|
||||
this.logger.debug('Refreshing recent scrobbles');
|
||||
const resp = await this.api.getRecentlyPlayed(limit);
|
||||
this.logger.debug(`Found ${resp.length} recent scrobbles`);
|
||||
this.recentScrobbles = resp;
|
||||
if (this.recentScrobbles.length > 0) {
|
||||
const [{data: {playDate: newestScrobbleTime = dayjs()} = {}} = {}] = this.recentScrobbles.slice(-1);
|
||||
const [{data: {playDate: oldestScrobbleTime = dayjs()} = {}} = {}] = this.recentScrobbles.slice(0, 1);
|
||||
this.newestScrobbleTime = newestScrobbleTime;
|
||||
this.oldestScrobbleTime = oldestScrobbleTime;
|
||||
|
||||
this.filterScrobbledTracks();
|
||||
}
|
||||
}
|
||||
this.lastScrobbleCheck = dayjs();
|
||||
getScrobblesForRefresh = async (limit: number) => {
|
||||
return await this.api.getRecentlyPlayed(limit);
|
||||
}
|
||||
|
||||
alreadyScrobbled = async (playObj: PlayObject, log = false) => (await this.existingScrobble(playObj)) !== undefined
|
||||
@@ -91,30 +77,18 @@ export default class ListenbrainzScrobbler extends AbstractScrobbleClient {
|
||||
} = {}
|
||||
} = playObj;
|
||||
|
||||
let rawPayload = {listen_type: 'single', payload: [this.playToClientPayload(playObj)]};
|
||||
|
||||
try {
|
||||
const resp = await this.api.submitListen(playObj);
|
||||
rawPayload = resp;
|
||||
await this.api.submitListen(playObj, true);
|
||||
|
||||
if (newFromSource) {
|
||||
this.logger.info(`Scrobbled (New) => (${source}) ${buildTrackString(playObj)}`);
|
||||
} else {
|
||||
this.logger.info(`Scrobbled (Backlog) => (${source}) ${buildTrackString(playObj)}`);
|
||||
}
|
||||
// last fm has rate limits but i can't find a specific example of what that limit is. going to default to 1 scrobble/sec to be safe
|
||||
//await sleep(1000);
|
||||
return playObj;
|
||||
} catch (e) {
|
||||
await this.notifier.notify({title: `Client - ${capitalize(this.type)} - ${this.name} - Scrobble Error`, message: `Failed to scrobble => ${buildTrackString(playObj)} | Error: ${e.message}`, priority: 'error'});
|
||||
this.logger.error(`Failed to scrobble => ${e.message}`, {payload: rawPayload});
|
||||
if(e instanceof UpstreamError) {
|
||||
throw e;
|
||||
} else {
|
||||
throw new UpstreamError(`Error occurred while making Listenbrainz API request: ${e.message}`, {cause: e, showStopper: true});
|
||||
}
|
||||
} finally {
|
||||
this.logger.debug(`Raw Payload:`, {rawPayload});
|
||||
throw new UpstreamError(`Error occurred while making Listenbrainz API scrobble request: ${e.message}`, {cause: e, showStopper: !(e instanceof UpstreamError)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,28 +299,15 @@ export default class MalojaScrobbler extends AbstractScrobbleClient {
|
||||
}
|
||||
}
|
||||
|
||||
refreshScrobbles = async (limit = this.MAX_STORED_SCROBBLES) => {
|
||||
if (this.refreshEnabled) {
|
||||
this.logger.debug('Refreshing recent scrobbles');
|
||||
const {url} = this.config.data;
|
||||
const resp = await this.callApi(request.get(`${url}/apis/mlj_1/scrobbles?perpage=${limit}`));
|
||||
const {
|
||||
body: {
|
||||
list = [],
|
||||
} = {},
|
||||
} = resp;
|
||||
this.logger.debug(`Found ${list.length} recent scrobbles`);
|
||||
this.recentScrobbles = list.map((x: any) => this.formatPlayObj(x));
|
||||
if (this.recentScrobbles.length > 0) {
|
||||
const [{data: {playDate: newestScrobbleTime = dayjs()} = {}} = {}] = this.recentScrobbles.slice(-1);
|
||||
const [{data: {playDate: oldestScrobbleTime = dayjs()} = {}} = {}] = this.recentScrobbles.slice(0, 1);
|
||||
this.newestScrobbleTime = newestScrobbleTime;
|
||||
this.oldestScrobbleTime = oldestScrobbleTime;
|
||||
|
||||
this.filterScrobbledTracks();
|
||||
}
|
||||
}
|
||||
this.lastScrobbleCheck = dayjs();
|
||||
getScrobblesForRefresh = async (limit: number) => {
|
||||
const {url} = this.config.data;
|
||||
const resp = await this.callApi(request.get(`${url}/apis/mlj_1/scrobbles?perpage=${limit}`));
|
||||
const {
|
||||
body: {
|
||||
list = [],
|
||||
} = {},
|
||||
} = resp;
|
||||
return list.map((x: any) => this.formatPlayObj(x));
|
||||
}
|
||||
|
||||
cleanSourceSearchTitle = (playObj: PlayObject) => {
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
PlayUserId,
|
||||
ProgressAwarePlayObject,
|
||||
SINGLE_USER_PLATFORM_ID,
|
||||
SourceType,
|
||||
SourceType, TRANSFORM_HOOK,
|
||||
} from "../common/infrastructure/Atomic.js";
|
||||
import { SourceConfig } from "../common/infrastructure/config/source/sources.js";
|
||||
import TupleMap from "../common/TupleMap.js";
|
||||
@@ -46,7 +46,7 @@ export default abstract class AbstractSource extends AbstractComponent implement
|
||||
type: SourceType;
|
||||
identifier: string;
|
||||
|
||||
config: SourceConfig;
|
||||
declare config: SourceConfig;
|
||||
clients: string[];
|
||||
instantiatedAt: Dayjs;
|
||||
lastActivityAt: Dayjs;
|
||||
@@ -64,6 +64,9 @@ export default abstract class AbstractSource extends AbstractComponent implement
|
||||
pollRetries: number = 0;
|
||||
tracksDiscovered: number = 0;
|
||||
|
||||
protected isSleeping: boolean = false;
|
||||
protected wakeAt: Dayjs = dayjs();
|
||||
|
||||
supportsUpstreamRecentlyPlayed: boolean = false;
|
||||
supportsUpstreamNowPlaying: boolean = false;
|
||||
|
||||
@@ -74,7 +77,7 @@ export default abstract class AbstractSource extends AbstractComponent implement
|
||||
protected recentDiscoveredPlays: GroupedFixedPlays = new TupleMap<DeviceId, PlayUserId, FixedSizeList<ProgressAwarePlayObject>>();
|
||||
|
||||
constructor(type: SourceType, name: string, config: SourceConfig, internal: InternalConfig, emitter: EventEmitter) {
|
||||
super();
|
||||
super(config);
|
||||
const {clients = [] } = config;
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
@@ -144,8 +147,12 @@ export default abstract class AbstractSource extends AbstractComponent implement
|
||||
}
|
||||
});
|
||||
}
|
||||
const candidate = this.transformPlay(play, TRANSFORM_HOOK.candidate);
|
||||
for(const list of lists) {
|
||||
const existing = list.find(x => playObjDataMatch(x, play) && temporalAccuracyIsAtLeast(TA_CLOSE, comparePlayTemporally(x, play).match));
|
||||
const existing = list.find(x => {
|
||||
const e = this.transformPlay(x, TRANSFORM_HOOK.existing);
|
||||
return playObjDataMatch(e, candidate) && temporalAccuracyIsAtLeast(TA_CLOSE, comparePlayTemporally(e, candidate).match)
|
||||
});
|
||||
if(existing) {
|
||||
return existing;
|
||||
}
|
||||
@@ -163,7 +170,9 @@ export default abstract class AbstractSource extends AbstractComponent implement
|
||||
discover = (plays: PlayObject[], options: { checkAll?: boolean, [key: string]: any } = {}): PlayObject[] => {
|
||||
const newDiscoveredPlays: PlayObject[] = [];
|
||||
|
||||
for(const play of plays) {
|
||||
const transformedPlayed = plays.map(x => this.transformPlay(x, TRANSFORM_HOOK.preCompare));
|
||||
|
||||
for(const play of transformedPlayed) {
|
||||
if(!this.alreadyDiscovered(play, options)) {
|
||||
this.addPlayToDiscovered(play);
|
||||
newDiscoveredPlays.push(play);
|
||||
@@ -181,7 +190,7 @@ export default abstract class AbstractSource extends AbstractComponent implement
|
||||
if(newDiscoveredPlays.length > 0) {
|
||||
newDiscoveredPlays.sort(sortByOldestPlayDate);
|
||||
this.emitter.emit('discoveredToScrobble', {
|
||||
data: newDiscoveredPlays,
|
||||
data: newDiscoveredPlays.map(x => this.transformPlay(x, TRANSFORM_HOOK.postCompare)),
|
||||
options: {
|
||||
...options,
|
||||
checkTime: newDiscoveredPlays[newDiscoveredPlays.length-1].data.playDate.add(2, 'second'),
|
||||
@@ -305,6 +314,13 @@ export default abstract class AbstractSource extends AbstractComponent implement
|
||||
let pollRes: boolean | undefined = undefined;
|
||||
while (pollRes === undefined && this.pollRetries <= maxRetries) {
|
||||
try {
|
||||
if(!this.isReady() && this.buildOK) {
|
||||
this.logger.verbose(`Source is no longer ready! Will attempt to reinitialize => Connection OK: ${this.connectionOK} | Auth OK: ${this.authed}`);
|
||||
const init = await this.initialize();
|
||||
if(init === false) {
|
||||
throw new Error('Source failed reinitialization');
|
||||
}
|
||||
}
|
||||
pollRes = await this.doPolling();
|
||||
if(pollRes === true) {
|
||||
break;
|
||||
@@ -420,11 +436,13 @@ export default abstract class AbstractSource extends AbstractComponent implement
|
||||
} else {
|
||||
this.logger.debug(`Last activity was at ${this.lastActivityAt.format()} | Next check interval: ${formatNumber(sleepTime)}s`);
|
||||
}
|
||||
const wakeUpAt = pollFrom.add(sleepTime, 'seconds');
|
||||
while(!this.shouldStopPolling() && dayjs().isBefore(wakeUpAt)) {
|
||||
this.setWakeAt(pollFrom.add(sleepTime, 'seconds'));
|
||||
this.setIsSleeping(true);
|
||||
while(!this.shouldStopPolling() && dayjs().isBefore(this.getWakeAt())) {
|
||||
// check for polling status every half second and wait till wake up time
|
||||
await sleep(500);
|
||||
}
|
||||
this.setIsSleeping(false);
|
||||
|
||||
}
|
||||
if(this.shouldStopPolling()) {
|
||||
@@ -441,9 +459,27 @@ export default abstract class AbstractSource extends AbstractComponent implement
|
||||
this.emitEvent('statusChange', {status: 'Idle'});
|
||||
this.polling = false;
|
||||
throw e;
|
||||
} finally {
|
||||
this.setIsSleeping(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected setIsSleeping(sleeping: boolean) {
|
||||
this.isSleeping = sleeping;
|
||||
}
|
||||
|
||||
protected getIsSleeping() {
|
||||
return this.isSleeping;
|
||||
}
|
||||
|
||||
protected setWakeAt(dt: Dayjs) {
|
||||
this.wakeAt = dt;
|
||||
}
|
||||
|
||||
protected getWakeAt() {
|
||||
return this.wakeAt;
|
||||
}
|
||||
|
||||
protected getInterval() {
|
||||
const {interval = DEFAULT_POLLING_INTERVAL} = this.config.data;
|
||||
return interval;
|
||||
|
||||
@@ -90,6 +90,8 @@ export default class DeezerSource extends AbstractSource {
|
||||
}
|
||||
|
||||
protected async doBuildInitData(): Promise<true | string | undefined> {
|
||||
this.logger.warn('This Source is DEPRECATED! Deezer has dropped support official API support. New apps cannot be created and existing apps are not guaranteed to continue working. See the documentation or this issue for more information: https://github.com/FoxxMD/multi-scrobbler/issues/175#issuecomment-2296776625');
|
||||
|
||||
try {
|
||||
const credFile = await readJson(this.workingCredsPath, {throwOnNotFound: false});
|
||||
if(credFile !== undefined) {
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
import dayjs from "dayjs";
|
||||
import { EventEmitter } from "events";
|
||||
import mpdapiNS, { MPDApi } from 'mpd-api';
|
||||
import mpd2 from 'mpd2';
|
||||
import { BrainzMeta, PlayObject } from "../../core/Atomic.js";
|
||||
import {
|
||||
FormatPlayObjectOptions,
|
||||
InternalConfig,
|
||||
PlayerStateData,
|
||||
REPORTED_PLAYER_STATUSES,
|
||||
ReportedPlayerStatus,
|
||||
SINGLE_USER_PLATFORM_ID,
|
||||
} from "../common/infrastructure/Atomic.js";
|
||||
import {
|
||||
CurrentSongResponse,
|
||||
MPDSourceConfig,
|
||||
PlayerState,
|
||||
StatusResponse,
|
||||
} from "../common/infrastructure/config/source/mpd.js";
|
||||
import { isPortReachable } from "../utils/NetworkUtils.js";
|
||||
import { RecentlyPlayedOptions } from "./AbstractSource.js";
|
||||
import MemorySource from "./MemorySource.js";
|
||||
|
||||
const mpdClient = mpdapiNS.default;
|
||||
|
||||
const CLIENT_PLAYER_STATE: Record<PlayerState, ReportedPlayerStatus> = {
|
||||
'play': REPORTED_PLAYER_STATUSES.playing,
|
||||
'pause': REPORTED_PLAYER_STATUSES.paused,
|
||||
'stop': REPORTED_PLAYER_STATUSES.stopped,
|
||||
}
|
||||
|
||||
export class MPDSource extends MemorySource {
|
||||
declare config: MPDSourceConfig;
|
||||
|
||||
host?: string
|
||||
port?: number
|
||||
// {host?: string, port?: number, path?: string, password?: string};
|
||||
clientConfig: mpd2.MPD.Config;
|
||||
client!: MPDApi.ClientAPI;
|
||||
deviceId: string
|
||||
|
||||
constructor(name: any, config: MPDSourceConfig, internal: InternalConfig, emitter: EventEmitter) {
|
||||
const {
|
||||
data = {}
|
||||
} = config;
|
||||
const {
|
||||
interval = 5, // reduced polling interval because its likely we are on the same network
|
||||
...rest
|
||||
} = data;
|
||||
super('mpd', name, {...config, data: {...rest, interval}}, internal, emitter);
|
||||
|
||||
this.requiresAuth = true;
|
||||
this.canPoll = true;
|
||||
}
|
||||
|
||||
static parseConnectionUrl(valRaw: string): [string, string] {
|
||||
if(valRaw.trim() === '') {
|
||||
throw new Error(`'url' cannot be an empty string`);
|
||||
}
|
||||
|
||||
const [host, port] = valRaw.trim().split(':');
|
||||
return [host, port ?? '6600'];
|
||||
}
|
||||
|
||||
protected async doBuildInitData(): Promise<true | string | undefined> {
|
||||
const {
|
||||
data: {
|
||||
url,
|
||||
path,
|
||||
password,
|
||||
} = {}
|
||||
} = this.config;
|
||||
|
||||
if(path === undefined) {
|
||||
const [host, port] = MPDSource.parseConnectionUrl(url ?? 'localhost:6600');
|
||||
this.logger.verbose(`Config URL: '${url ?? '(None Given)'}' => Normalized: '${host}:${port}'`);
|
||||
this.host = host;
|
||||
this.port = Number.parseInt(port);
|
||||
this.clientConfig = {
|
||||
host,
|
||||
port: this.port,
|
||||
password
|
||||
}
|
||||
} else {
|
||||
this.logger.verbose(`Using socket path: ${path}`);
|
||||
this.clientConfig = {
|
||||
path,
|
||||
password
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected async doCheckConnection(): Promise<true | string | undefined> {
|
||||
if(this.host !== undefined) {
|
||||
try {
|
||||
await isPortReachable(this.port, {host: this.host});
|
||||
return `${this.host}:${this.port} is reachable.`;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
doAuthentication = async () => {
|
||||
|
||||
try {
|
||||
this.client = await mpdClient.connect({...this.clientConfig, timeout: 1000});
|
||||
this.client.on('system-player', () => {
|
||||
if(this.getIsSleeping()) {
|
||||
// wake up now!
|
||||
this.logger.debug(`Waking up from sleeping ${Math.abs(this.getWakeAt().diff(dayjs(), 'ms'))}ms early due to player state change`)
|
||||
this.setWakeAt(dayjs());
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch (e) {
|
||||
let friendlyError: string | undefined;
|
||||
if(e.code === 'ENOENT') {
|
||||
friendlyError = 'Socket file does not exist'
|
||||
} else if(e.code === 'EACCES') {
|
||||
friendlyError = 'Incorrect permissions to access socket file'
|
||||
}
|
||||
// if(e.errno !== undefined) {
|
||||
// switch(e.errno) {
|
||||
// case mpd2.default.MPDError.CODES.PERMISSION:
|
||||
// friendlyError = 'No permission to connect';
|
||||
// break;
|
||||
// case mpd2.default.MPDError.CODES.PASSWORD:
|
||||
// friendlyError = 'Password is probably not correct';
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
throw new Error(`Could not connect to MPD server${friendlyError !== undefined ? ` (Hint: ${friendlyError})` : ''}`, {cause: e});
|
||||
}
|
||||
}
|
||||
|
||||
formatPlayObj(obj: CurrentSongResponse, options: FormatPlayObjectOptions = {}): PlayObject {
|
||||
const {
|
||||
file,
|
||||
time,
|
||||
artist,
|
||||
performer,
|
||||
album,
|
||||
albumartist,
|
||||
title,
|
||||
name,
|
||||
musicbrainz_albumartistid,
|
||||
musicbrainz_albumid,
|
||||
musicbrainz_artistid,
|
||||
musicbrainz_releasetrackid,
|
||||
musicbrainz_trackid,
|
||||
} = obj;
|
||||
|
||||
let artists = [];
|
||||
let albumArtists = [];
|
||||
if(artist !== undefined) {
|
||||
artists.push(artist);
|
||||
}
|
||||
if(albumartist !== undefined && albumartist !== artist) {
|
||||
albumArtists.push(albumartist);
|
||||
}
|
||||
if(artists.length === 0 && performer !== undefined) {
|
||||
artists.push(performer);
|
||||
}
|
||||
if(artists.length === 0 && albumArtists.length !== 0) {
|
||||
// switch these, tags are probably improper
|
||||
artists = albumArtists;
|
||||
albumArtists = [];
|
||||
}
|
||||
|
||||
let trackName = title;
|
||||
if(trackName === undefined && name !== undefined) {
|
||||
trackName = name;
|
||||
} else if(trackName === undefined && file !== undefined) {
|
||||
trackName = file;
|
||||
}
|
||||
|
||||
const brainz: BrainzMeta = {
|
||||
albumArtist: musicbrainz_albumartistid,
|
||||
album: musicbrainz_albumid,
|
||||
track: musicbrainz_trackid,
|
||||
};
|
||||
if(musicbrainz_artistid !== undefined) {
|
||||
brainz.artist = [musicbrainz_artistid];
|
||||
}
|
||||
|
||||
return {
|
||||
data: {
|
||||
artists: artists,
|
||||
albumArtists,
|
||||
album,
|
||||
track: trackName,
|
||||
duration: time
|
||||
},
|
||||
meta: {
|
||||
brainz,
|
||||
trackProgressPosition: options.trackProgressPosition,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getRecentlyPlayed = async (options: RecentlyPlayedOptions = {}) => {
|
||||
|
||||
let state: StatusResponse;
|
||||
let currentSong: CurrentSongResponse;
|
||||
try {
|
||||
state = await this.client.api.status.get<StatusResponse>();
|
||||
currentSong = await this.client.api.status.currentsong<CurrentSongResponse>();
|
||||
} catch (e) {
|
||||
this.connectionOK = false;
|
||||
this.authed = false;
|
||||
throw e;
|
||||
}
|
||||
|
||||
let play: PlayObject | undefined;
|
||||
if(currentSong !== undefined) {
|
||||
play = this.formatPlayObj(currentSong, {trackProgressPosition: state.elapsed});
|
||||
}
|
||||
|
||||
const playerState: PlayerStateData = {
|
||||
platformId: SINGLE_USER_PLATFORM_ID,
|
||||
status: CLIENT_PLAYER_STATE[state.state],
|
||||
play,
|
||||
position: state.elapsed
|
||||
}
|
||||
|
||||
return this.processRecentPlays([playerState]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
import { childLogger } from "@foxxmd/logging";
|
||||
import { EventEmitter } from "events";
|
||||
import { WS } from 'iso-websocket'
|
||||
// TODO remove when/if iso-websocket exports these
|
||||
// @ ts-expect-error not exported properly by package
|
||||
//import { CloseEvent, ErrorEvent, RetryEvent } from "iso-websocket/dist/src/events.js";
|
||||
import { WS, CloseEvent, ErrorEvent, RetryEvent } from 'iso-websocket'
|
||||
import { randomUUID } from "node:crypto";
|
||||
import normalizeUrl from 'normalize-url';
|
||||
import pEvent from 'p-event';
|
||||
@@ -102,8 +99,7 @@ export class MusikcubeSource extends MemorySource {
|
||||
automaticOpen: false,
|
||||
retry: {
|
||||
retries: 0
|
||||
},
|
||||
//errorInfo: true
|
||||
}
|
||||
});
|
||||
const wsLogger = childLogger(this.logger, 'WS');
|
||||
this.client.addEventListener('retry', (e) => {
|
||||
@@ -128,12 +124,8 @@ export class MusikcubeSource extends MemorySource {
|
||||
this.connectionOK = false;
|
||||
this.authed = false;
|
||||
}
|
||||
if(e.error.message === ('Websocket error')) {
|
||||
wsLogger.error('Communication with server failed => Websocket error');
|
||||
|
||||
} else {
|
||||
wsLogger.error(new Error('Communication with server failed', {cause: e.error}));
|
||||
}
|
||||
const hint = e.error?.cause?.message ?? undefined;
|
||||
wsLogger.error(new Error(`Communication with server failed${hint !== undefined ? ` (${hint})` : ''}`, {cause: e.error}));
|
||||
});
|
||||
|
||||
this.client.addEventListener('message', (e) => {
|
||||
@@ -148,11 +140,12 @@ export class MusikcubeSource extends MemorySource {
|
||||
protected async doCheckConnection(): Promise<true | string | undefined> {
|
||||
try {
|
||||
this.client.open();
|
||||
const e = await pEvent(this.client, 'open');
|
||||
const opened = await pEvent(this.client, 'open');
|
||||
return true;
|
||||
} catch (e) {
|
||||
this.client.close();
|
||||
throw new Error(`Could not connect to Musikcube metadata server`);
|
||||
const hint = e.error?.cause?.message ?? undefined;
|
||||
throw new Error(`Could not connect to Musikcube metadata server${hint !== undefined ? ` (${hint})` : ''}`, {cause: e.error ?? e});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -284,21 +277,6 @@ const isRetryEvent = (e: Event): e is RetryEvent => {
|
||||
return e.type === 'retry';
|
||||
}
|
||||
|
||||
// TODO remove when/if iso-websockets exports these
|
||||
interface ErrorEvent extends Event {
|
||||
type: 'error'
|
||||
error: Error
|
||||
message: string
|
||||
}
|
||||
interface CloseEvent extends Event {
|
||||
type: 'close'
|
||||
reason: string
|
||||
code: number
|
||||
}
|
||||
interface RetryEvent extends Event {
|
||||
type: 'retry'
|
||||
}
|
||||
|
||||
const isAuthenticateResponse = (data: any): data is MCAuthenticateResponse => {
|
||||
return 'name' in data && data.name === 'authenticate';
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { KodiData, KodiSourceConfig } from "../common/infrastructure/config/sour
|
||||
import { LastfmSourceConfig } from "../common/infrastructure/config/source/lastfm.js";
|
||||
import { ListenBrainzSourceConfig } from "../common/infrastructure/config/source/listenbrainz.js";
|
||||
import { MopidySourceConfig } from "../common/infrastructure/config/source/mopidy.js";
|
||||
import { MPDSourceConfig } from "../common/infrastructure/config/source/mpd.js";
|
||||
import { MPRISData, MPRISSourceConfig } from "../common/infrastructure/config/source/mpris.js";
|
||||
import { MusikcubeData, MusikcubeSourceConfig } from "../common/infrastructure/config/source/musikcube.js";
|
||||
import { PlexSourceConfig } from "../common/infrastructure/config/source/plex.js";
|
||||
@@ -34,6 +35,7 @@ import { KodiSource } from "./KodiSource.js";
|
||||
import LastfmSource from "./LastfmSource.js";
|
||||
import ListenbrainzSource from "./ListenbrainzSource.js";
|
||||
import { MopidySource } from "./MopidySource.js";
|
||||
import { MPDSource } from "./MPDSource.js";
|
||||
import { MPRISSource } from "./MPRISSource.js";
|
||||
import { MusikcubeSource } from "./MusikcubeSource.js";
|
||||
import PlexSource from "./PlexSource.js";
|
||||
@@ -543,6 +545,9 @@ export default class ScrobbleSources {
|
||||
case 'musikcube':
|
||||
newSource = await new MusikcubeSource(name, compositeConfig as MusikcubeSourceConfig, internal, this.emitter);
|
||||
break;
|
||||
case 'mpd':
|
||||
newSource = await new MPDSource(name, compositeConfig as MPDSourceConfig, internal, this.emitter);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
import { loggerTest, loggerDebug, childLogger } from "@foxxmd/logging";
|
||||
import chai, { assert, expect } from 'chai';
|
||||
import asPromised from 'chai-as-promised';
|
||||
import { after, before, describe, it } from 'mocha';
|
||||
import AbstractComponent from "../../common/AbstractComponent.js";
|
||||
import { TRANSFORM_HOOK } from "../../common/infrastructure/Atomic.js";
|
||||
import { isSearchAndReplace } from "../../utils.js";
|
||||
import { asPlays, generatePlay, normalizePlays } from "../utils/PlayTestUtils.js";
|
||||
|
||||
chai.use(asPromised);
|
||||
|
||||
class TestComponent extends AbstractComponent {
|
||||
constructor() {
|
||||
super({});
|
||||
}
|
||||
}
|
||||
|
||||
const component = new TestComponent();
|
||||
component.logger = childLogger(loggerTest, 'App');
|
||||
|
||||
describe('Play Transforms', function () {
|
||||
|
||||
beforeEach(function() {
|
||||
component.config = {};
|
||||
component.transformRules = undefined;
|
||||
});
|
||||
|
||||
describe('Transform Config Parsing', function() {
|
||||
|
||||
it('Sets transform rules as empty object if config is not present', function() {
|
||||
component.buildTransformRules();
|
||||
expect(component.transformRules).exist;
|
||||
expect(Object.keys(component.transformRules).length).eq(0);
|
||||
});
|
||||
|
||||
it('Converts transform config into real S&P data', function() {
|
||||
component.config = {
|
||||
options: {
|
||||
playTransform: {
|
||||
preCompare: {
|
||||
title: ['something']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component.buildTransformRules();
|
||||
|
||||
expect(component.transformRules.preCompare).to.exist;
|
||||
expect(component.transformRules.preCompare.title).to.exist;
|
||||
expect(Array.isArray(component.transformRules.preCompare.title)).is.true;
|
||||
expect( isSearchAndReplace(component.transformRules.preCompare.title[0])).is.true
|
||||
});
|
||||
|
||||
it('Converts transform config into real S&P data with default being empty string', function() {
|
||||
component.config = {
|
||||
options: {
|
||||
playTransform: {
|
||||
preCompare: {
|
||||
title: ['something']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component.buildTransformRules();
|
||||
|
||||
expect(component.transformRules.preCompare).to.exist;
|
||||
expect(component.transformRules.preCompare.title).to.exist;
|
||||
expect(Array.isArray(component.transformRules.preCompare.title)).is.true;
|
||||
expect( isSearchAndReplace(component.transformRules.preCompare.title[0])).is.true
|
||||
expect( component.transformRules.preCompare.title[0].search).is.eq('something');
|
||||
expect( component.transformRules.preCompare.title[0].replace).is.eq('');
|
||||
});
|
||||
|
||||
it('Respects transform config when it is already S&P data', function() {
|
||||
component.config = {
|
||||
options: {
|
||||
playTransform: {
|
||||
preCompare: {
|
||||
title: [
|
||||
{
|
||||
search: 'nothing',
|
||||
replace: 'anything'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component.buildTransformRules();
|
||||
|
||||
expect(component.transformRules.preCompare).to.exist;
|
||||
expect(component.transformRules.preCompare.title).to.exist;
|
||||
expect(Array.isArray(component.transformRules.preCompare.title)).is.true;
|
||||
expect( isSearchAndReplace(component.transformRules.preCompare.title[0])).is.true
|
||||
expect( component.transformRules.preCompare.title[0].search).is.eq('nothing');
|
||||
expect( component.transformRules.preCompare.title[0].replace).is.eq('anything');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Play Transforming', function() {
|
||||
|
||||
it('Returns original play if no hooks are defined', function () {
|
||||
component.buildTransformRules();
|
||||
|
||||
const play = generatePlay();
|
||||
const transformed = component.transformPlay(play, TRANSFORM_HOOK.preCompare);
|
||||
expect(JSON.stringify(play)).equal(JSON.stringify(transformed));
|
||||
});
|
||||
|
||||
it('Transforms when hook is present', function () {
|
||||
component.config = {
|
||||
options: {
|
||||
playTransform: {
|
||||
preCompare: {
|
||||
title: ['something']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
component.buildTransformRules();
|
||||
|
||||
const play = generatePlay({track: 'My coolsomething track'});
|
||||
const transformed = component.transformPlay(play, TRANSFORM_HOOK.preCompare);
|
||||
expect(transformed.data.track).equal('My cool track');
|
||||
});
|
||||
|
||||
it('Transforms consecutively when hook is present with multiple values', function () {
|
||||
component.config = {
|
||||
options: {
|
||||
playTransform: {
|
||||
preCompare: {
|
||||
title: ['something', 'cool']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
component.buildTransformRules();
|
||||
|
||||
const play = generatePlay({track: 'My coolsomething track'});
|
||||
const transformed = component.transformPlay(play, TRANSFORM_HOOK.preCompare);
|
||||
expect(transformed.data.track).equal('My track');
|
||||
});
|
||||
|
||||
it('Transforms using parsed regex', function () {
|
||||
component.config = {
|
||||
options: {
|
||||
playTransform: {
|
||||
preCompare: {
|
||||
title: [
|
||||
{
|
||||
search: '/(cool )(some)(thing)/i',
|
||||
replace: '$1$3'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
component.buildTransformRules();
|
||||
|
||||
const play = generatePlay({track: 'My cool something track'});
|
||||
const transformed = component.transformPlay(play, TRANSFORM_HOOK.preCompare);
|
||||
expect(transformed.data.track).equal('My cool thing track');
|
||||
});
|
||||
|
||||
it('Removes title when transform replaces with empty string', function () {
|
||||
component.config = {
|
||||
options: {
|
||||
playTransform: {
|
||||
preCompare: {
|
||||
title: ['something']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
component.buildTransformRules();
|
||||
|
||||
const play = generatePlay({track: 'something'});
|
||||
const transformed = component.transformPlay(play, TRANSFORM_HOOK.preCompare);
|
||||
expect(transformed.data.track).is.undefined;
|
||||
});
|
||||
|
||||
it('Removes album when transform replaces with empty string', function () {
|
||||
component.config = {
|
||||
options: {
|
||||
playTransform: {
|
||||
preCompare: {
|
||||
album: ['something']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
component.buildTransformRules();
|
||||
|
||||
const play = generatePlay({album: 'something'});
|
||||
const transformed = component.transformPlay(play, TRANSFORM_HOOK.preCompare);
|
||||
expect(transformed.data.album).is.undefined;
|
||||
});
|
||||
|
||||
it('Removes an artist when transform replaces with empty string', function () {
|
||||
component.config = {
|
||||
options: {
|
||||
playTransform: {
|
||||
preCompare: {
|
||||
artists: ['something']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
component.buildTransformRules();
|
||||
|
||||
const play = generatePlay({artists: ['something', 'big']});
|
||||
const transformed = component.transformPlay(play, TRANSFORM_HOOK.preCompare);
|
||||
expect(transformed.data.artists.length).is.eq(1)
|
||||
expect(transformed.data.artists[0]).is.eq('big')
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
@@ -6,6 +6,9 @@ import { Notifiers } from "../../notifier/Notifiers.js";
|
||||
import AbstractScrobbleClient from "../../scrobblers/AbstractScrobbleClient.js";
|
||||
|
||||
export class TestScrobbler extends AbstractScrobbleClient {
|
||||
protected async getScrobblesForRefresh(limit: number): Promise<PlayObject[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
constructor() {
|
||||
const logger = loggerTest;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import chai, { assert } from 'chai';
|
||||
import chai, { assert, expect } from 'chai';
|
||||
import asPromised from 'chai-as-promised';
|
||||
import clone from 'clone';
|
||||
import { source } from "common-tags";
|
||||
import dayjs from "dayjs";
|
||||
import { after, before, describe, it } from 'mocha';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
@@ -26,17 +27,20 @@ const normalizedWithMixedDur = normalizePlays(mixedDurPlays, {initialDate: first
|
||||
|
||||
const normalizedWithMixedDurOlder = normalizePlays(mixedDurPlays, {initialDate: olderFirstPlayDate});
|
||||
|
||||
const testScrobbler = new TestScrobbler();
|
||||
testScrobbler.verboseOptions = {
|
||||
match: {
|
||||
onMatch: true,
|
||||
onNoMatch: true,
|
||||
confidenceBreakdown: true
|
||||
}
|
||||
};
|
||||
testScrobbler.lastScrobbleCheck = dayjs().subtract(60, 'seconds');
|
||||
const generateTestScrobbler = () => {
|
||||
const testScrobbler = new TestScrobbler();
|
||||
testScrobbler.verboseOptions = {
|
||||
match: {
|
||||
onMatch: true,
|
||||
onNoMatch: true,
|
||||
confidenceBreakdown: true
|
||||
}
|
||||
};
|
||||
testScrobbler.lastScrobbleCheck = dayjs().subtract(60, 'seconds');
|
||||
return testScrobbler;
|
||||
}
|
||||
|
||||
const authScrobbler = new TestAuthScrobbler();
|
||||
let testScrobbler: TestScrobbler = generateTestScrobbler()
|
||||
|
||||
describe('Networking', function () {
|
||||
|
||||
@@ -52,6 +56,7 @@ describe('Networking', function () {
|
||||
)
|
||||
],
|
||||
async function() {
|
||||
const authScrobbler = new TestAuthScrobbler();
|
||||
await authScrobbler.testAuth();
|
||||
assert.isFalse(authScrobbler.authGated());
|
||||
}
|
||||
@@ -66,6 +71,7 @@ describe('Networking', function () {
|
||||
)
|
||||
],
|
||||
async function() {
|
||||
const authScrobbler = new TestAuthScrobbler();
|
||||
await authScrobbler.testAuth();
|
||||
assert.isTrue(authScrobbler.authGated());
|
||||
assert.isFalse(authScrobbler.authFailure);
|
||||
@@ -81,6 +87,7 @@ describe('Networking', function () {
|
||||
)
|
||||
],
|
||||
async function() {
|
||||
const authScrobbler = new TestAuthScrobbler();
|
||||
await authScrobbler.testAuth();
|
||||
assert.isTrue(authScrobbler.authGated());
|
||||
assert.isTrue(authScrobbler.authFailure);
|
||||
@@ -93,6 +100,10 @@ describe('Detects duplicate and unique scrobbles from client recent history', fu
|
||||
|
||||
describe('When scrobble is unique', function () {
|
||||
|
||||
beforeEach(function() {
|
||||
testScrobbler = generateTestScrobbler();
|
||||
});
|
||||
|
||||
it('It is not detected as duplicate when play date is newer than most recent', async function () {
|
||||
|
||||
testScrobbler.recentScrobbles = normalizedWithMixedDur;
|
||||
@@ -136,6 +147,10 @@ describe('Detects duplicate and unique scrobbles from client recent history', fu
|
||||
|
||||
describe('When scrobble track/artist/album matches existing but is a new scrobble', function () {
|
||||
|
||||
beforeEach(function() {
|
||||
testScrobbler = generateTestScrobbler();
|
||||
});
|
||||
|
||||
it('Is not detected as duplicate when artist is same, time is similar, but track is different', async function () {
|
||||
|
||||
testScrobbler.recentScrobbles = normalizedWithMixedDur;
|
||||
@@ -191,6 +206,11 @@ describe('Detects duplicate and unique scrobbles from client recent history', fu
|
||||
});
|
||||
|
||||
describe('When existing has duration', function () {
|
||||
|
||||
beforeEach(function() {
|
||||
testScrobbler = generateTestScrobbler();
|
||||
});
|
||||
|
||||
it('A track with continuity to the previous track is not detected as a duplicate', async function () {
|
||||
|
||||
testScrobbler.recentScrobbles = normalizedWithDur;
|
||||
@@ -221,6 +241,10 @@ describe('Detects duplicate and unique scrobbles from client recent history', fu
|
||||
|
||||
describe('When scrobble is a duplicate (title/artists/album)', function () {
|
||||
|
||||
beforeEach(function() {
|
||||
testScrobbler = generateTestScrobbler();
|
||||
});
|
||||
|
||||
it('Is detected as duplicate when an exact match', async function () {
|
||||
testScrobbler.recentScrobbles = normalizedWithMixedDur;
|
||||
assert.isTrue(await testScrobbler.alreadyScrobbled(normalizedWithMixedDur[normalizedWithMixedDur.length - 1]));
|
||||
@@ -354,6 +378,10 @@ describe('Detects duplicate and unique scrobbles from client recent history', fu
|
||||
|
||||
describe('When at least one play has duration', function () {
|
||||
|
||||
beforeEach(function() {
|
||||
testScrobbler = generateTestScrobbler();
|
||||
});
|
||||
|
||||
it('Is detected as duplicate when play date is close to the end of an existing scrobble', async function () {
|
||||
|
||||
testScrobbler.recentScrobbles = normalizedWithDur;
|
||||
@@ -380,11 +408,17 @@ describe('Detects duplicate and unique scrobbles from client recent history', fu
|
||||
|
||||
describe('Detects duplicate and unique scrobbles using actively tracked scrobbles', function() {
|
||||
|
||||
before(function () {
|
||||
beforeEach(function() {
|
||||
testScrobbler = generateTestScrobbler();
|
||||
testScrobbler.recentScrobbles = normalizedWithMixedDur;
|
||||
testScrobbler.lastScrobbleCheck = dayjs().subtract(60, 'seconds');
|
||||
});
|
||||
|
||||
// before(function () {
|
||||
// testScrobbler.recentScrobbles = normalizedWithMixedDur;
|
||||
// testScrobbler.lastScrobbleCheck = dayjs().subtract(60, 'seconds');
|
||||
// });
|
||||
|
||||
it('Detects a unique play', async function() {
|
||||
const newScrobble = generatePlay({
|
||||
playDate: normalizedWithMixedDur[normalizedWithMixedDur.length - 3].data.playDate.add(3, 'seconds')
|
||||
@@ -424,14 +458,181 @@ describe('Detects duplicate and unique scrobbles using actively tracked scrobble
|
||||
});
|
||||
});
|
||||
|
||||
describe('Manages scrobble queue', function() {
|
||||
describe('Detects when upstream scrobbles should be refreshed', function() {
|
||||
|
||||
before(function() {
|
||||
const normalizedClose = normalizePlays(withDurPlays, {initialDate: dayjs().subtract(100, 'seconds')});
|
||||
|
||||
beforeEach(function () {
|
||||
testScrobbler = generateTestScrobbler();
|
||||
testScrobbler.recentScrobbles = normalizedWithMixedDur;
|
||||
testScrobbler.newestScrobbleTime = normalizedWithMixedDur[0].data.playDate;
|
||||
testScrobbler.lastScrobbleCheck = dayjs().subtract(60, 'seconds');
|
||||
testScrobbler.queuedScrobbles = [];
|
||||
testScrobbler.config.options = {};
|
||||
});
|
||||
|
||||
it('Detects queued scrobble date is newer than last scrobble refresh', async function() {
|
||||
const newScrobble = generatePlay({
|
||||
playDate: dayjs()
|
||||
});
|
||||
|
||||
testScrobbler.queueScrobble(newScrobble, 'test');
|
||||
assert.isTrue(testScrobbler.shouldRefreshScrobble());
|
||||
});
|
||||
|
||||
it('Detects queued scrobble date is older than newest scrobble', async function() {
|
||||
testScrobbler.recentScrobbles = normalizedClose;
|
||||
testScrobbler.newestScrobbleTime = normalizedClose[0].data.playDate;
|
||||
|
||||
const newScrobble = generatePlay({
|
||||
playDate: dayjs().subtract(120, 'seconds')
|
||||
});
|
||||
|
||||
testScrobbler.queueScrobble(newScrobble, 'test');
|
||||
assert.isTrue(testScrobbler.shouldRefreshScrobble());
|
||||
});
|
||||
|
||||
it('Forces refresh if refreshStaleAfter is set', async function() {
|
||||
testScrobbler.recentScrobbles = normalizedClose;
|
||||
testScrobbler.newestScrobbleTime = normalizedClose[0].data.playDate;
|
||||
testScrobbler.config.options = { refreshStaleAfter: 10 };
|
||||
|
||||
const newScrobble = generatePlay({
|
||||
playDate: dayjs().subtract(80, 'seconds')
|
||||
});
|
||||
|
||||
testScrobbler.queueScrobble(newScrobble, 'test');
|
||||
assert.isTrue(testScrobbler.shouldRefreshScrobble());
|
||||
});
|
||||
|
||||
it('Does not refresh if scrobble is older than last check but newer than newest upstream scrobble', async function() {
|
||||
testScrobbler.recentScrobbles = normalizedClose;
|
||||
testScrobbler.newestScrobbleTime = normalizedClose[0].data.playDate;
|
||||
|
||||
const newScrobble = generatePlay({
|
||||
playDate: dayjs().subtract(80, 'seconds')
|
||||
});
|
||||
|
||||
testScrobbler.queueScrobble(newScrobble, 'test');
|
||||
assert.isFalse(testScrobbler.shouldRefreshScrobble());
|
||||
});
|
||||
});
|
||||
|
||||
describe('Scrobble client uses transform plays correctly', function() {
|
||||
|
||||
beforeEach(async function() {
|
||||
testScrobbler = generateTestScrobbler();
|
||||
await testScrobbler.initialize();
|
||||
testScrobbler.recentScrobbles = normalizedWithMixedDur;
|
||||
testScrobbler.scrobbleSleep = 500;
|
||||
testScrobbler.scrobbleDelay = 0;
|
||||
testScrobbler.lastScrobbleCheck = dayjs().subtract(60, 'seconds');
|
||||
testScrobbler.initScrobbleMonitoring();
|
||||
testScrobbler.config.options = {};
|
||||
//testScrobbler.initScrobbleMonitoring().catch(console.error);
|
||||
});
|
||||
|
||||
it('Transforms play before queue when preCompare is present', async function() {
|
||||
testScrobbler.config.options = {
|
||||
playTransform: {
|
||||
preCompare: {
|
||||
title: [
|
||||
'cool'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
testScrobbler.buildTransformRules();
|
||||
const newScrobble = generatePlay({
|
||||
track: 'my cool track'
|
||||
});
|
||||
testScrobbler.queueScrobble(newScrobble, 'test');
|
||||
expect(testScrobbler.queuedScrobbles[0].play.data.track).is.eq('my track');
|
||||
});
|
||||
|
||||
it('Transforms play on scrobble when postCompare is present', async function() {
|
||||
testScrobbler.config.options = {
|
||||
playTransform: {
|
||||
postCompare: {
|
||||
title: [
|
||||
'cool'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
testScrobbler.buildTransformRules();
|
||||
const newScrobble = generatePlay({
|
||||
track: 'my cool track'
|
||||
});
|
||||
testScrobbler.queueScrobble(newScrobble, 'test');
|
||||
expect(testScrobbler.queuedScrobbles[0].play.data.track).is.eq('my cool track');
|
||||
testScrobbler.scrobbleSleep = 100;
|
||||
testScrobbler.initScrobbleMonitoring().catch(console.error);
|
||||
|
||||
const e = (await pEvent(testScrobbler.emitter, 'scrobble')) as {data: {play: PlayObject }};
|
||||
expect(e.data.play.data.track).is.eq('my track');
|
||||
});
|
||||
|
||||
it('Transforms candidate play on comparison', async function() {
|
||||
testScrobbler.config.options = {
|
||||
playTransform: {
|
||||
compare: {
|
||||
candidate: {
|
||||
title: [
|
||||
'hugely cool and very different track'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const newScrobble = generatePlay({
|
||||
track: 'my hugely cool and very different track title'
|
||||
});
|
||||
|
||||
testScrobbler.recentScrobbles = normalizePlays([newScrobble, ...withDurPlays], {initialDate: firstPlayDate});
|
||||
testScrobbler.buildTransformRules();
|
||||
|
||||
expect(await testScrobbler.alreadyScrobbled(newScrobble)).is.false;
|
||||
});
|
||||
|
||||
it('Transforms existing play on comparison', async function() {
|
||||
testScrobbler.config.options = {
|
||||
playTransform: {
|
||||
compare: {
|
||||
existing: {
|
||||
title: [
|
||||
'hugely cool and very different track'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const newScrobble = generatePlay({
|
||||
track: 'my hugely cool and very different track title'
|
||||
});
|
||||
|
||||
testScrobbler.recentScrobbles = normalizePlays([newScrobble, ...withDurPlays], {initialDate: firstPlayDate});
|
||||
testScrobbler.buildTransformRules();
|
||||
|
||||
expect(await testScrobbler.alreadyScrobbled(newScrobble)).is.false;
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
this.timeout(3500);
|
||||
await testScrobbler.tryStopScrobbling()
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Manages scrobble queue', function() {
|
||||
|
||||
before(async function() {
|
||||
testScrobbler = generateTestScrobbler();
|
||||
await testScrobbler.initialize();
|
||||
testScrobbler.recentScrobbles = normalizedWithMixedDur;
|
||||
testScrobbler.scrobbleSleep = 500;
|
||||
testScrobbler.scrobbleDelay = 0;
|
||||
testScrobbler.lastScrobbleCheck = dayjs().subtract(60, 'seconds');
|
||||
testScrobbler.initScrobbleMonitoring().catch(console.error);
|
||||
});
|
||||
|
||||
it('Scrobbles a uniquely queued play', async function() {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { PlayObject } from "../../../core/Atomic.js";
|
||||
import AbstractSource from "../../sources/AbstractSource.js";
|
||||
|
||||
export class TestSource extends AbstractSource {
|
||||
handle(plays: PlayObject[]) {
|
||||
this.scrobble(plays);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
import { loggerTest, loggerDebug } from "@foxxmd/logging";
|
||||
import chai, { assert, expect } from 'chai';
|
||||
import asPromised from 'chai-as-promised';
|
||||
import EventEmitter from "events";
|
||||
import { after, before, describe, it } from 'mocha';
|
||||
import pEvent from "p-event";
|
||||
import { PlayObject } from "../../../core/Atomic.js";
|
||||
import { generatePlay } from "../utils/PlayTestUtils.js";
|
||||
import { TestSource } from "./TestSource.js";
|
||||
|
||||
chai.use(asPromised);
|
||||
|
||||
|
||||
const emitter = new EventEmitter();
|
||||
const generateSource = () => {
|
||||
return new TestSource('spotify', 'test', {}, {localUrl: new URL('https://example.com'), configDir: 'fake', logger: loggerTest}, emitter);
|
||||
}
|
||||
let source: TestSource = generateSource();
|
||||
|
||||
describe('Sources use transform plays correctly', function () {
|
||||
|
||||
beforeEach(function() {
|
||||
source = generateSource();
|
||||
});
|
||||
|
||||
it('Transforms play on preCompare', function() {
|
||||
source.config.options = {
|
||||
playTransform: {
|
||||
preCompare: {
|
||||
title: [
|
||||
{
|
||||
search: 'cool',
|
||||
replace: 'fun'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
source.buildTransformRules();
|
||||
const newScrobble = generatePlay({
|
||||
track: 'my cool track'
|
||||
});
|
||||
const discovered = source.discover([newScrobble])
|
||||
expect(discovered.length).eq(1);
|
||||
expect(discovered[0].data.track).is.eq('my fun track');
|
||||
});
|
||||
|
||||
it('Transforms play on postCompare', async function() {
|
||||
source.config.options = {
|
||||
playTransform: {
|
||||
postCompare: {
|
||||
title: [
|
||||
{
|
||||
search: 'cool',
|
||||
replace: 'fun'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
source.buildTransformRules();
|
||||
const newScrobble = generatePlay({
|
||||
track: 'my cool track'
|
||||
});
|
||||
const discovered = source.discover([newScrobble])
|
||||
expect(discovered.length).eq(1);
|
||||
expect(discovered[0].data.track).is.eq('my cool track');
|
||||
|
||||
const pAwaiter = pEvent(source.emitter, 'discoveredToScrobble') as Promise<{data: [PlayObject] }>;
|
||||
source.handle(discovered);
|
||||
const e = await pAwaiter;
|
||||
expect(e.data.length).is.eq(1);
|
||||
expect(e.data[0].data.track).is.eq('my fun track');
|
||||
});
|
||||
|
||||
it('Transforms play existing comparison', function() {
|
||||
source.config.options = {
|
||||
playTransform: {
|
||||
compare: {
|
||||
existing: {
|
||||
title: [
|
||||
{
|
||||
search: 'hugely cool and very different track',
|
||||
replace: 'fun'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
source.buildTransformRules();
|
||||
const newScrobble = generatePlay({
|
||||
track: 'my hugely cool and very different track title',
|
||||
});
|
||||
const discovered = source.discover([newScrobble])
|
||||
expect(discovered.length).eq(1);
|
||||
expect(discovered[0].data.track).is.eq('my hugely cool and very different track title');
|
||||
|
||||
expect(source.discover([newScrobble]).length).is.eq(1);
|
||||
});
|
||||
|
||||
it('Transforms play candidate comparison', function() {
|
||||
source.config.options = {
|
||||
playTransform: {
|
||||
compare: {
|
||||
candidate: {
|
||||
title: [
|
||||
{
|
||||
search: 'hugely cool and very different track',
|
||||
replace: 'fun'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
source.buildTransformRules();
|
||||
const newScrobble = generatePlay({
|
||||
track: 'my hugely cool and very different track title',
|
||||
});
|
||||
const discovered = source.discover([newScrobble])
|
||||
expect(discovered.length).eq(1);
|
||||
expect(discovered[0].data.track).is.eq('my hugely cool and very different track title');
|
||||
|
||||
expect(source.discover([newScrobble]).length).is.eq(1);
|
||||
});
|
||||
})
|
||||
@@ -81,10 +81,10 @@ export const generatePlay = (data: ObjectPlayData = {}, meta: PlayMeta = {}): Pl
|
||||
return {
|
||||
data: {
|
||||
track: faker.music.songName(),
|
||||
artists: faker.helpers.multiple(faker.person.fullName, {count: {min: 1, max: 2}}),
|
||||
artists: faker.helpers.multiple(faker.music.artist, {count: {min: 1, max: 3}}),
|
||||
duration: faker.number.int({min: 30, max: 300}),
|
||||
playDate: dayjs().subtract(faker.number.int({min: 1, max: 800})),
|
||||
album: faker.music.songName(),
|
||||
album: faker.music.album(),
|
||||
...data
|
||||
},
|
||||
meta: {
|
||||
|
||||
+64
-2
@@ -1,4 +1,5 @@
|
||||
import { Logger } from '@foxxmd/logging';
|
||||
import { SearchAndReplaceRegExp } from "@foxxmd/regex-buddy-core";
|
||||
import backoffStrategies from '@kenyip/backoff-strategies';
|
||||
import address from "address";
|
||||
import * as AjvNS from 'ajv';
|
||||
@@ -22,11 +23,11 @@ import {
|
||||
NO_USER,
|
||||
numberFormatOptions,
|
||||
PlayerStateData,
|
||||
PlayPlatformId,
|
||||
PlayPlatformId, PlayTransformParts,
|
||||
ProgressAwarePlayObject,
|
||||
RegExResult,
|
||||
RemoteIdentityParts,
|
||||
ScrobbleThresholdResult,
|
||||
ScrobbleThresholdResult, SearchAndReplaceTerm,
|
||||
} from "./common/infrastructure/Atomic.js";
|
||||
|
||||
//const { default: Ajv } = AjvNS;
|
||||
@@ -790,3 +791,64 @@ export const joinedUrl = (url: URL, ...paths: string[]): URL => {
|
||||
finalUrl.pathname = joinPath(url.pathname, ...(paths.filter(x => x.trim() !== '')));
|
||||
return finalUrl;
|
||||
}
|
||||
|
||||
export const configValToSearchReplace = (val: string | undefined | object): SearchAndReplaceRegExp | undefined => {
|
||||
if (val === undefined || val === null) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof val === 'string') {
|
||||
return {
|
||||
search: val,
|
||||
replace: ''
|
||||
}
|
||||
}
|
||||
if (isSearchAndReplace(val)) {
|
||||
return val as SearchAndReplaceRegExp;
|
||||
}
|
||||
throw new Error(`Value must be a string or an object containing 'search: string' and 'replace: 'string'. Given: ${val}`);
|
||||
}
|
||||
|
||||
export const isSearchAndReplace = (val: object): val is SearchAndReplaceRegExp => {
|
||||
return typeof val === 'object'
|
||||
&& ('search' in val && typeof val.search === 'string')
|
||||
&& ('replace' in val && typeof val.replace === 'string');
|
||||
}
|
||||
|
||||
export const configPartsToStrongParts = (val: PlayTransformParts<SearchAndReplaceTerm> | undefined): PlayTransformParts<SearchAndReplaceRegExp> => {
|
||||
if (val === undefined) {
|
||||
return {}
|
||||
}
|
||||
const {
|
||||
title: titleConfig,
|
||||
artists: artistConfig,
|
||||
album: albumConfig
|
||||
} = val;
|
||||
let title,
|
||||
artists,
|
||||
album;
|
||||
|
||||
if (titleConfig !== undefined) {
|
||||
if (!Array.isArray(titleConfig)) {
|
||||
throw new Error('title must be an array');
|
||||
}
|
||||
title = titleConfig.map(configValToSearchReplace);
|
||||
}
|
||||
if (artistConfig !== undefined) {
|
||||
if (!Array.isArray(artistConfig)) {
|
||||
throw new Error('arist must be an array');
|
||||
}
|
||||
artists = artistConfig.map(configValToSearchReplace);
|
||||
}
|
||||
if (albumConfig !== undefined) {
|
||||
if (!Array.isArray(albumConfig)) {
|
||||
throw new Error('albumConfig must be an array');
|
||||
}
|
||||
album = albumConfig.map(configValToSearchReplace);
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
artists,
|
||||
album
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import net from 'node:net';
|
||||
|
||||
export interface PortReachableOpts {
|
||||
host: string,
|
||||
timeout?: number
|
||||
}
|
||||
/**
|
||||
* Copied from https://github.com/sindresorhus/is-port-reachable with error reporting
|
||||
* */
|
||||
export const isPortReachable = async (port: number, opts: PortReachableOpts) => {
|
||||
const {host, timeout = 1000} = opts;
|
||||
|
||||
const promise = new Promise(((resolve, reject) => {
|
||||
const socket = new net.Socket();
|
||||
|
||||
const onError = (e) => {
|
||||
socket.destroy();
|
||||
reject(e);
|
||||
};
|
||||
const onTimeout = () => {
|
||||
socket.destroy();
|
||||
reject(new Error(`Connection timed out after ${timeout}ms`));
|
||||
}
|
||||
|
||||
socket.setTimeout(timeout);
|
||||
socket.once('error', onError);
|
||||
socket.once('timeout', onTimeout);
|
||||
|
||||
socket.connect(port, host, () => {
|
||||
socket.end();
|
||||
resolve(true);
|
||||
});
|
||||
}));
|
||||
|
||||
try {
|
||||
await promise;
|
||||
return true;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,33 @@
|
||||
import React, {Fragment} from 'react';
|
||||
import React, { Fragment, useMemo } from 'react';
|
||||
import PlayDisplay from "../components/PlayDisplay";
|
||||
import {recentIncludes} from "../../core/Atomic";
|
||||
import {useSearchParams} from "react-router-dom";
|
||||
import {useGetRecentQuery} from "./recentDucks";
|
||||
import { recentIncludes } from "../../core/Atomic";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import { useGetRecentQuery } from "./recentDucks";
|
||||
import Tooltip from "../components/Tooltip";
|
||||
import {faQuestionCircle} from "@fortawesome/free-solid-svg-icons";
|
||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||
import {data} from "autoprefixer";
|
||||
import { faQuestionCircle } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
|
||||
const displayOpts = {
|
||||
include: recentIncludes,
|
||||
includeWeb: true
|
||||
}
|
||||
|
||||
const apiTip = <Fragment>
|
||||
const apiTipContent = <Fragment>
|
||||
<div>Data that is directly returned by the Source API.</div>
|
||||
<div>If you do not see your recent plays in this data it is likely the Source's data is lagging behind your actual activity.</div>
|
||||
</Fragment>
|
||||
<div>If you do not see your recent plays in this data it is likely the Source's data is lagging behind your
|
||||
actual activity.
|
||||
</div>
|
||||
<div className="mt-2"></div>
|
||||
</Fragment>;
|
||||
|
||||
const tsTip = <div className="mt-2">
|
||||
<div>
|
||||
<code>(C)</code> - Scrobble timestamped when listen was <strong>completed</strong>
|
||||
</div>
|
||||
<div>
|
||||
<code>(S)</code> - Scrobble timestamped when listen was <strong>started</strong>
|
||||
</div>
|
||||
</div>;
|
||||
|
||||
const recent = () => {
|
||||
let [searchParams, setSearchParams] = useSearchParams();
|
||||
@@ -25,17 +36,32 @@ const recent = () => {
|
||||
error,
|
||||
isLoading,
|
||||
isSuccess
|
||||
} = useGetRecentQuery({name: searchParams.get('name'), type: searchParams.get('type'), upstream: searchParams.get('upstream')});
|
||||
} = useGetRecentQuery({
|
||||
name: searchParams.get('name'),
|
||||
type: searchParams.get('type'),
|
||||
upstream: searchParams.get('upstream')
|
||||
});
|
||||
|
||||
const isUpstream = searchParams.get('upstream') === '1';
|
||||
|
||||
const tipContents = useMemo(() => {
|
||||
return <Fragment>
|
||||
{isUpstream ? apiTipContent : null}
|
||||
{tsTip}
|
||||
</Fragment>
|
||||
}, [isUpstream]);
|
||||
|
||||
return (
|
||||
<div className="grid">
|
||||
<div className="shadow-md rounded bg-gray-500 text-white">
|
||||
<div className="p-3 font-semibold bg-gray-700 text-white">
|
||||
<h2>Recently Played{isUpstream ? ' from Source API' : null}{isUpstream ? <Tooltip message={apiTip}
|
||||
classNames={['ml-2']}
|
||||
style={{display: 'inline-flex', width: '35%'}}><FontAwesomeIcon color="white" icon={faQuestionCircle}/></Tooltip> : null}
|
||||
<h2>Recently Played{isUpstream ? ' from Source API' : null}<Tooltip message={tipContents}
|
||||
classNames={['ml-2']}
|
||||
style={{
|
||||
display: 'inline-flex',
|
||||
width: '35%'
|
||||
}}><FontAwesomeIcon
|
||||
color="white" icon={faQuestionCircle}/></Tooltip>
|
||||
</h2>
|
||||
</div>
|
||||
<div className="p-5">
|
||||
|
||||
+12
-9
@@ -31,13 +31,14 @@ export interface ClientStatusData {
|
||||
initialized: boolean;
|
||||
}
|
||||
|
||||
export type PlayObjectIncludeTypes = 'time' | 'artist' | 'track' | 'timeFromNow' | 'trackId' | 'comment';
|
||||
export const recentIncludes: PlayObjectIncludeTypes[] = ['time', 'timeFromNow', 'track', 'artist', 'comment'];
|
||||
export type PlayObjectIncludeTypes = 'album' | 'time' | 'artist' | 'track' | 'timeFromNow' | 'trackId' | 'comment';
|
||||
export const recentIncludes: PlayObjectIncludeTypes[] = ['time', 'timeFromNow', 'track', 'album', 'artist', 'comment'];
|
||||
|
||||
export interface TrackStringOptions<T = string> {
|
||||
include?: PlayObjectIncludeTypes[]
|
||||
transformers?: {
|
||||
artists?: (a: string[]) => T | string
|
||||
album?: (t: string,data: AmbPlayObject, hasExistingParts?: boolean) => T | string
|
||||
track?: (t: string,data: AmbPlayObject, hasExistingParts?: boolean) => T | string
|
||||
time?: (t: Dayjs, i?: ScrobbleTsSOC) => T | string
|
||||
timeFromNow?: (t: Dayjs) => T | string
|
||||
@@ -57,6 +58,14 @@ export interface ListenRangeData {
|
||||
end: ListenProgress
|
||||
}
|
||||
|
||||
export interface BrainzMeta {
|
||||
artist?: string[]
|
||||
albumArtist?: string
|
||||
album?: string
|
||||
track?: string
|
||||
releaseGroup?: string
|
||||
}
|
||||
|
||||
export interface TrackData {
|
||||
artists?: string[]
|
||||
albumArtists?: string[]
|
||||
@@ -68,13 +77,7 @@ export interface TrackData {
|
||||
duration?: number
|
||||
|
||||
meta?: {
|
||||
brainz?: {
|
||||
artist?: string[]
|
||||
albumArtist?: string
|
||||
album?: string
|
||||
track?: string
|
||||
releaseGroup?: string
|
||||
}
|
||||
brainz?: BrainzMeta
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,12 +33,14 @@ export const truncateStringToLength = (length: any, truncStr = '...') => (val: a
|
||||
export const defaultTrackTransformer = (input: any, data: AmbPlayObject, hasExistingParts: boolean = false) => hasExistingParts ? `- ${input}` : input;
|
||||
export const defaultReducer = (acc, curr) => `${acc} ${curr}`;
|
||||
export const defaultArtistFunc = (a: string[]) => a.join(' / ');
|
||||
export const defaultAlbumFunc = (input: any, data: AmbPlayObject, hasExistingParts: boolean = false) => hasExistingParts ? `--- ${input}` : input;
|
||||
export const defaultTimeFunc = (t: Dayjs | undefined, i?: ScrobbleTsSOC) => t === undefined ? '@ N/A' : `@ ${t.local().format()} ${i === undefined ? '' : (i === SCROBBLE_TS_SOC_START ? '(S)' : '(C)')}`;
|
||||
export const defaultTimeFromNowFunc = (t: Dayjs | undefined) => t === undefined ? undefined : `(${t.local().fromNow()})`;
|
||||
export const defaultCommentFunc = (c: string | undefined) => c === undefined ? undefined : `(${c})`;
|
||||
export const defaultBuildTrackStringTransformers = {
|
||||
artists: defaultArtistFunc,
|
||||
track: defaultTrackTransformer,
|
||||
album: defaultAlbumFunc,
|
||||
time: defaultTimeFunc,
|
||||
timeFromNow: defaultTimeFromNowFunc,
|
||||
comment: defaultCommentFunc
|
||||
@@ -48,6 +50,7 @@ export const buildTrackString = <T = string>(playObj: AmbPlayObject, options: Tr
|
||||
include = ['time', 'artist', 'track'],
|
||||
transformers: {
|
||||
artists: artistsFunc = defaultBuildTrackStringTransformers.artists,
|
||||
album: albumFunc = defaultBuildTrackStringTransformers.album,
|
||||
track: trackFunc = defaultBuildTrackStringTransformers.track,
|
||||
time: timeFunc = defaultBuildTrackStringTransformers.time,
|
||||
timeFromNow = defaultBuildTrackStringTransformers.timeFromNow,
|
||||
@@ -89,6 +92,9 @@ export const buildTrackString = <T = string>(playObj: AmbPlayObject, options: Tr
|
||||
if (include.includes('track')) {
|
||||
strParts.push(trackFunc(track, playObj, strParts.length > 0));
|
||||
}
|
||||
if (include.includes('album')) {
|
||||
strParts.push(albumFunc(album, playObj, strParts.length > 0));
|
||||
}
|
||||
if (include.includes('time')) {
|
||||
strParts.push(timeFunc(pd, usedTsSOC));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user