mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-04-20 11:42:28 +02:00
feat: The ListenBrainz integration has been extended with a configurable (5 seconds by default) delay in song reporting
This commit is contained in:
parent
cbb22ba688
commit
68f76a9e63
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -6,8 +6,10 @@
|
|||||||
"Flatpak",
|
"Flatpak",
|
||||||
"geqnfr",
|
"geqnfr",
|
||||||
"hifi",
|
"hifi",
|
||||||
|
"libnotify",
|
||||||
"listenbrainz",
|
"listenbrainz",
|
||||||
"playpause",
|
"playpause",
|
||||||
|
"prs",
|
||||||
"rescrobbler",
|
"rescrobbler",
|
||||||
"scrobble",
|
"scrobble",
|
||||||
"scrobbling",
|
"scrobbling",
|
||||||
|
@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Added settings to customize the Discord rich presence information
|
- Added settings to customize the Discord rich presence information
|
||||||
- Discord settings are now also collapsible like the ListenBrainz ones are
|
- Discord settings are now also collapsible like the ListenBrainz ones are
|
||||||
- Restyled settings menu to include version number and useful links on the about page
|
- Restyled settings menu to include version number and useful links on the about page
|
||||||
|
- The ListenBrainz integration has been extended with a configurable (5 seconds by default) delay in song reporting so that it doesn't spam the API when you are cycling through songs.
|
||||||
|
|
||||||
## [5.6.0]
|
## [5.6.0]
|
||||||
|
|
||||||
|
@ -51,10 +51,11 @@ The web version of [listen.tidal.com](https://listen.tidal.com) running in elect
|
|||||||
- Songwhip.com integration (hotkey `ctrl + w`)
|
- Songwhip.com integration (hotkey `ctrl + w`)
|
||||||
- Discord RPC integration (showing "now listening", "Browsing", etc)
|
- Discord RPC integration (showing "now listening", "Browsing", etc)
|
||||||
- MPRIS integration
|
- MPRIS integration
|
||||||
|
- UI + Json config (`~/.config/tidal-hifi/`, or `~/.var/app/com.mastermindzh.tidal-hifi/` for Flatpak)
|
||||||
|
|
||||||
## Contributions
|
## Contributions
|
||||||
|
|
||||||
To contribute you can use the standard GitHub features (issues, prs, etc) or join the discord server to talk with like-minded individuals.
|
To contribute you can use the standard GitHub features (issues, prs, etc.) or join the discord server to talk with like-minded individuals.
|
||||||
|
|
||||||
-  [Join the Discord server](https://discord.gg/yhNwf4v4He)
|
-  [Join the Discord server](https://discord.gg/yhNwf4v4He)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tidal-hifi",
|
"name": "tidal-hifi",
|
||||||
"version": "5.6.0",
|
"version": "5.7.0",
|
||||||
"description": "Tidal on Electron with widevine(hifi) support",
|
"description": "Tidal on Electron with widevine(hifi) support",
|
||||||
"main": "ts-dist/main.js",
|
"main": "ts-dist/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -29,6 +29,7 @@ export const settings = {
|
|||||||
enabled: "ListenBrainz.enabled",
|
enabled: "ListenBrainz.enabled",
|
||||||
api: "ListenBrainz.api",
|
api: "ListenBrainz.api",
|
||||||
token: "ListenBrainz.token",
|
token: "ListenBrainz.token",
|
||||||
|
delay: "ListenBrainz.delay",
|
||||||
},
|
},
|
||||||
flags: {
|
flags: {
|
||||||
root: "flags",
|
root: "flags",
|
||||||
|
@ -44,6 +44,7 @@ let adBlock: HTMLInputElement,
|
|||||||
enableListenBrainz: HTMLInputElement,
|
enableListenBrainz: HTMLInputElement,
|
||||||
ListenBrainzAPI: HTMLInputElement,
|
ListenBrainzAPI: HTMLInputElement,
|
||||||
ListenBrainzToken: HTMLInputElement,
|
ListenBrainzToken: HTMLInputElement,
|
||||||
|
listenbrainz_delay: HTMLInputElement,
|
||||||
enableWaylandSupport: HTMLInputElement,
|
enableWaylandSupport: HTMLInputElement,
|
||||||
discord_details_prefix: HTMLInputElement,
|
discord_details_prefix: HTMLInputElement,
|
||||||
discord_button_text: HTMLInputElement;
|
discord_button_text: HTMLInputElement;
|
||||||
@ -75,6 +76,7 @@ function handleFileUploads() {
|
|||||||
const fileMessage = document.getElementById("file-message");
|
const fileMessage = document.getElementById("file-message");
|
||||||
fileMessage.innerText = "or drag and drop files here";
|
fileMessage.innerText = "or drag and drop files here";
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
document.getElementById("theme-files").addEventListener("change", function (e: any) {
|
document.getElementById("theme-files").addEventListener("change", function (e: any) {
|
||||||
Array.from(e.target.files).forEach((file: File) => {
|
Array.from(e.target.files).forEach((file: File) => {
|
||||||
const destination = `${app.getPath("userData")}/themes/${file.name}`;
|
const destination = `${app.getPath("userData")}/themes/${file.name}`;
|
||||||
@ -128,6 +130,7 @@ function refreshSettings() {
|
|||||||
enableListenBrainz.checked = settingsStore.get(settings.ListenBrainz.enabled);
|
enableListenBrainz.checked = settingsStore.get(settings.ListenBrainz.enabled);
|
||||||
ListenBrainzAPI.value = settingsStore.get(settings.ListenBrainz.api);
|
ListenBrainzAPI.value = settingsStore.get(settings.ListenBrainz.api);
|
||||||
ListenBrainzToken.value = settingsStore.get(settings.ListenBrainz.token);
|
ListenBrainzToken.value = settingsStore.get(settings.ListenBrainz.token);
|
||||||
|
listenbrainz_delay.value = settingsStore.get(settings.ListenBrainz.delay);
|
||||||
discord_details_prefix.value = settingsStore.get(settings.discord.detailsPrefix);
|
discord_details_prefix.value = settingsStore.get(settings.discord.detailsPrefix);
|
||||||
discord_button_text.value = settingsStore.get(settings.discord.buttonText);
|
discord_button_text.value = settingsStore.get(settings.discord.buttonText);
|
||||||
|
|
||||||
@ -240,6 +243,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||||||
ListenBrainzAPI = get("ListenBrainzAPI");
|
ListenBrainzAPI = get("ListenBrainzAPI");
|
||||||
ListenBrainzToken = get("ListenBrainzToken");
|
ListenBrainzToken = get("ListenBrainzToken");
|
||||||
discord_details_prefix = get("discord_details_prefix");
|
discord_details_prefix = get("discord_details_prefix");
|
||||||
|
listenbrainz_delay = get("listenbrainz_delay");
|
||||||
discord_button_text = get("discord_button_text");
|
discord_button_text = get("discord_button_text");
|
||||||
|
|
||||||
refreshSettings();
|
refreshSettings();
|
||||||
@ -269,8 +273,9 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||||||
settings.ListenBrainz.enabled,
|
settings.ListenBrainz.enabled,
|
||||||
switchesWithSettings.listenBrainz
|
switchesWithSettings.listenBrainz
|
||||||
);
|
);
|
||||||
addTextAreaListener(ListenBrainzAPI, settings.ListenBrainz.api);
|
addInputListener(ListenBrainzAPI, settings.ListenBrainz.api);
|
||||||
addTextAreaListener(ListenBrainzToken, settings.ListenBrainz.token);
|
addInputListener(ListenBrainzToken, settings.ListenBrainz.token);
|
||||||
|
addInputListener(listenbrainz_delay, settings.ListenBrainz.delay);
|
||||||
addInputListener(discord_details_prefix, settings.discord.detailsPrefix);
|
addInputListener(discord_details_prefix, settings.discord.detailsPrefix);
|
||||||
addInputListener(discord_button_text, settings.discord.buttonText);
|
addInputListener(discord_button_text, settings.discord.buttonText);
|
||||||
});
|
});
|
||||||
|
@ -250,16 +250,22 @@
|
|||||||
<div class="group__description">
|
<div class="group__description">
|
||||||
<h4>ListenBrainz API Url</h4>
|
<h4>ListenBrainz API Url</h4>
|
||||||
<p>There are multiple instances for ListenBrainz you can set the corresponding API url below.</p>
|
<p>There are multiple instances for ListenBrainz you can set the corresponding API url below.</p>
|
||||||
|
<input id="ListenBrainzAPI" type="text" class="text-input" name="ListenBrainzAPI" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<textarea id="ListenBrainzAPI" class="textarea" cols="1" rows="1" spellcheck="false"></textarea>
|
|
||||||
<div class="group__option">
|
<div class="group__option">
|
||||||
<div class="group__description">
|
<div class="group__description">
|
||||||
<h4>ListenBrainz User Token</h4>
|
<h4>ListenBrainz User Token</h4>
|
||||||
<p>Provide the user token you can get from the settings page.</p>
|
<p>Provide the user token you can get from the settings page.</p>
|
||||||
|
<input id="ListenBrainzToken" type="text" class="text-input" name="ListenBrainzToken" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<textarea id="ListenBrainzToken" class="textarea" cols="1" rows="1" spellcheck="false"></textarea>
|
</div>
|
||||||
|
<div class="group__description">
|
||||||
|
<h4>ScrobbleDelay</h4>
|
||||||
|
<p>The delay (in ms) to send a song to ListenBrainz. Prevents spamming the API when you fast forward
|
||||||
|
immediately</p>
|
||||||
|
<input id="listenbrainz_delay" type="number" class="text-input" name="listenbrainz_delay" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
@ -24,6 +24,8 @@ const appName = "TIDAL Hi-Fi";
|
|||||||
let currentSong = "";
|
let currentSong = "";
|
||||||
let player: Player;
|
let player: Player;
|
||||||
let currentPlayStatus = MediaStatus.paused;
|
let currentPlayStatus = MediaStatus.paused;
|
||||||
|
let currentListenBrainzDelayId: ReturnType<typeof setTimeout>;
|
||||||
|
let scrobbleWaitingForDelay = false;
|
||||||
|
|
||||||
const elements = {
|
const elements = {
|
||||||
play: '*[data-test="play"]',
|
play: '*[data-test="play"]',
|
||||||
@ -395,6 +397,9 @@ function updateMpris(options: Options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the listenbrainz service with new data based on a few conditions
|
||||||
|
*/
|
||||||
function updateListenBrainz(options: Options) {
|
function updateListenBrainz(options: Options) {
|
||||||
if (settingsStore.get(settings.ListenBrainz.enabled)) {
|
if (settingsStore.get(settings.ListenBrainz.enabled)) {
|
||||||
const oldData = ListenBrainzStore.get(ListenBrainzConstants.oldData) as StoreData;
|
const oldData = ListenBrainzStore.get(ListenBrainzConstants.oldData) as StoreData;
|
||||||
@ -402,12 +407,22 @@ function updateListenBrainz(options: Options) {
|
|||||||
(!oldData && options.status === MediaStatus.playing) ||
|
(!oldData && options.status === MediaStatus.playing) ||
|
||||||
(oldData && oldData.title !== options.title)
|
(oldData && oldData.title !== options.title)
|
||||||
) {
|
) {
|
||||||
|
if (!scrobbleWaitingForDelay) {
|
||||||
|
scrobbleWaitingForDelay = true;
|
||||||
|
clearTimeout(currentListenBrainzDelayId);
|
||||||
|
currentListenBrainzDelayId = setTimeout(
|
||||||
|
() => {
|
||||||
ListenBrainz.scrobble(
|
ListenBrainz.scrobble(
|
||||||
options.title,
|
options.title,
|
||||||
options.artists,
|
options.artists,
|
||||||
options.status,
|
options.status,
|
||||||
convertDuration(options.duration)
|
convertDuration(options.duration)
|
||||||
);
|
);
|
||||||
|
scrobbleWaitingForDelay = false;
|
||||||
|
},
|
||||||
|
settingsStore.get(settings.ListenBrainz.delay) ?? 0
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ export const settingsStore = new Store({
|
|||||||
enabled: false,
|
enabled: false,
|
||||||
api: "https://api.listenbrainz.org",
|
api: "https://api.listenbrainz.org",
|
||||||
token: "",
|
token: "",
|
||||||
|
delay: 5000,
|
||||||
},
|
},
|
||||||
flags: {
|
flags: {
|
||||||
disableHardwareMediaKeys: false,
|
disableHardwareMediaKeys: false,
|
||||||
@ -53,6 +54,13 @@ export const settingsStore = new Store({
|
|||||||
migrationStore.get("disableHardwareMediaKeys") ?? false
|
migrationStore.get("disableHardwareMediaKeys") ?? false
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
"5.7.0": (migrationStore) => {
|
||||||
|
console.log("running migrations for 5.7.0");
|
||||||
|
migrationStore.set(
|
||||||
|
settings.ListenBrainz.delay,
|
||||||
|
migrationStore.get(settings.ListenBrainz.delay) ?? 5000
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user