Skip to content

Commit

Permalink
Disable RealMAX
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Jan 22, 2025
1 parent c6d9e0c commit d04a065
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 91 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,17 @@ Scrobbles and sets currently playing for [**ListenBrainz**](https://listenbrainz

## RealMAX

Install Url:
Tidal has quietly removed their api endpoint for looking up tracks by ISRC. This plugin no longer works due to this change, please disable it if you have it installed.

~~Install Url:~~

```
https://inrixia.github.io/neptune-plugins/RealMAX
```

Tidal oftern has multiple versions of the same song at different qualities.
~~Tidal oftern has multiple versions of the same song at different qualities.
With RealMAX when playing a song if there is a version available at a higher quality it will automatically be added as the next song in the queue and skipped to.
This ensures you are **always listening to the best quality of a song**
This ensures you are **always listening to the best quality of a song**~~

## Volume Scroll

Expand Down
160 changes: 81 additions & 79 deletions plugins/RealMAX/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { settings } from "./Settings";

export { Settings } from "./Settings";

alert("RealMAX - Tidal has quietly removed their api endpoint for looking up tracks by ISRC. This plugin no longer works due to this change, please disable it.");

const unloadIntercept = intercept(
"playbackControls/MEDIA_PRODUCT_TRANSITION",
debounce(async () => {
Expand All @@ -36,85 +38,85 @@ const unloadIntercept = intercept(
}, 125)
);

ContextMenu.onOpen(async (contextSource, contextMenu, trackItems) => {
document.getElementById("realMax-button")?.remove();
if (trackItems.length === 0 || !settings.displayMaxContextButton) return;
// ContextMenu.onOpen(async (contextSource, contextMenu, trackItems) => {
// document.getElementById("realMax-button")?.remove();
// if (trackItems.length === 0 || !settings.displayMaxContextButton) return;

let sourceName = trackItems[0].title;
if (contextSource.type === "PLAYLIST") sourceName = store.getState().content.playlists.find((playlist) => playlist.uuid === contextSource.playlistId)?.title ?? sourceName;
else if (contextSource.type === "ALBUM") sourceName = (await AlbumCache.get(+contextSource.albumId))?.title ?? sourceName;
sourceName = `${sourceName} - RealMAX`;
// let sourceName = trackItems[0].title;
// if (contextSource.type === "PLAYLIST") sourceName = store.getState().content.playlists.find((playlist) => playlist.uuid === contextSource.playlistId)?.title ?? sourceName;
// else if (contextSource.type === "ALBUM") sourceName = (await AlbumCache.get(+contextSource.albumId))?.title ?? sourceName;
// sourceName = `${sourceName} - RealMAX`;

const maxButton = document.createElement("button");
maxButton.type = "button";
maxButton.role = "menuitem";
maxButton.textContent = trackItems.length > 1 ? `RealMAX - Process ${trackItems.length} tracks` : "RealMAX - Process track";
maxButton.id = "realMax-button";
maxButton.className = "context-button"; // Set class name for styling
contextMenu.appendChild(maxButton);
maxButton.addEventListener("click", async () => {
maxButton.remove();
const trackIds: number[] = [];
let maxIdsFound = 0;
for (const index in trackItems) {
const trackItem = trackItems[index];
const trackId = trackItem.id!;
if (trackId === undefined) continue;
const maxItem = await MaxTrack[settings.considerNewestRelease ? "getLatestMaxTrack" : "getMaxTrack"](trackId).catch(
trace.msg.err.withContext(`Skipping adding ${trackItem.title} to ${sourceName}`)
);
if (maxItem === false || maxItem === undefined) continue;
if (maxItem?.id !== undefined) {
if ((await MediaItemCache.ensure(trackId)) !== undefined) {
trace.msg.log(`Found Max quality for ${maxItem.title} in ${sourceName}! ${index}/${trackItems.length - 1} done.`);
trackIds.push(+maxItem.id);
maxIdsFound++;
continue;
}
trace.msg.log(`Found Max quality for ${maxItem.title} in ${sourceName}, but track is unavailable... Skipping! ${index}/${trackItems.length - 1} done.`);
trackIds.push(trackId);
continue;
}
trace.msg.log(`${sourceName} - ${index}/${trackItems.length - 1} done. `);
trackIds.push(trackId);
}
const [{ playlist }] = await interceptPromise(
() =>
actions.folders.createPlaylist({
description: "Automatically generated by RealMAX",
folderId: "root",
fromPlaylist: undefined,
isPublic: false,
title: sourceName,
// @ts-expect-error This works lol
ids: trackIds.length > 450 ? undefined : trackIds,
}),
["content/LOAD_PLAYLIST_SUCCESS"],
["content/LOAD_PLAYLIST_FAIL"]
);
if (trackIds.length > 500) {
for (const trackIdsChunk of chunkArray(trackIds, 450)) {
await interceptPromise(
() =>
actions.content.addMediaItemsToPlaylist({
addToIndex: -1,
mediaItemIdsToAdd: trackIdsChunk,
onDupes: "ADD",
playlistUUID: playlist.uuid!,
}),
["content/ADD_MEDIA_ITEMS_TO_PLAYLIST_SUCCESS"],
["content/ADD_MEDIA_ITEMS_TO_PLAYLIST_FAIL"]
);
}
}
if (playlist?.uuid === undefined) {
return trace.msg.err(`Failed to create playlist "${sourceName}"`);
}
trace.msg.err(`Successfully created RealMAX playlist "${sourceName}" - Found ${maxIdsFound} RealMAX replacements!`);
});
});
// const maxButton = document.createElement("button");
// maxButton.type = "button";
// maxButton.role = "menuitem";
// maxButton.textContent = trackItems.length > 1 ? `RealMAX - Process ${trackItems.length} tracks` : "RealMAX - Process track";
// maxButton.id = "realMax-button";
// maxButton.className = "context-button"; // Set class name for styling
// contextMenu.appendChild(maxButton);
// maxButton.addEventListener("click", async () => {
// maxButton.remove();
// const trackIds: number[] = [];
// let maxIdsFound = 0;
// for (const index in trackItems) {
// const trackItem = trackItems[index];
// const trackId = trackItem.id!;
// if (trackId === undefined) continue;
// const maxItem = await MaxTrack[settings.considerNewestRelease ? "getLatestMaxTrack" : "getMaxTrack"](trackId).catch(
// trace.msg.err.withContext(`Skipping adding ${trackItem.title} to ${sourceName}`)
// );
// if (maxItem === false || maxItem === undefined) continue;
// if (maxItem?.id !== undefined) {
// if ((await MediaItemCache.ensure(trackId)) !== undefined) {
// trace.msg.log(`Found Max quality for ${maxItem.title} in ${sourceName}! ${index}/${trackItems.length - 1} done.`);
// trackIds.push(+maxItem.id);
// maxIdsFound++;
// continue;
// }
// trace.msg.log(`Found Max quality for ${maxItem.title} in ${sourceName}, but track is unavailable... Skipping! ${index}/${trackItems.length - 1} done.`);
// trackIds.push(trackId);
// continue;
// }
// trace.msg.log(`${sourceName} - ${index}/${trackItems.length - 1} done. `);
// trackIds.push(trackId);
// }
// const [{ playlist }] = await interceptPromise(
// () =>
// actions.folders.createPlaylist({
// description: "Automatically generated by RealMAX",
// folderId: "root",
// fromPlaylist: undefined,
// isPublic: false,
// title: sourceName,
// // @ts-expect-error This works lol
// ids: trackIds.length > 450 ? undefined : trackIds,
// }),
// ["content/LOAD_PLAYLIST_SUCCESS"],
// ["content/LOAD_PLAYLIST_FAIL"]
// );
// if (trackIds.length > 500) {
// for (const trackIdsChunk of chunkArray(trackIds, 450)) {
// await interceptPromise(
// () =>
// actions.content.addMediaItemsToPlaylist({
// addToIndex: -1,
// mediaItemIdsToAdd: trackIdsChunk,
// onDupes: "ADD",
// playlistUUID: playlist.uuid!,
// }),
// ["content/ADD_MEDIA_ITEMS_TO_PLAYLIST_SUCCESS"],
// ["content/ADD_MEDIA_ITEMS_TO_PLAYLIST_FAIL"]
// );
// }
// }
// if (playlist?.uuid === undefined) {
// return trace.msg.err(`Failed to create playlist "${sourceName}"`);
// }
// trace.msg.err(`Successfully created RealMAX playlist "${sourceName}" - Found ${maxIdsFound} RealMAX replacements!`);
// });
// });

export const onUnload = () => {
unloadIntercept();
safeUnload();
};
// export const onUnload = () => {
// unloadIntercept();
// safeUnload();
// };
8 changes: 4 additions & 4 deletions plugins/Shazam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ const handleDrop = async (event: DragEvent) => {
continue;
}
let trackToAdd;
for await (trackToAdd of MaxTrack.getTracksFromISRC(isrc)) {
// Break on first HiRes track. Otherwise trackToAdd will just be the final track found.
if (MaxTrack.hasHiRes(trackToAdd)) break;
}
// for await (trackToAdd of MaxTrack.getTracksFromISRC(isrc)) {
// // Break on first HiRes track. Otherwise trackToAdd will just be the final track found.
// if (MaxTrack.hasHiRes(trackToAdd)) break;
// }
if (trackToAdd !== undefined) {
trace.msg.log(`Adding ${prefix}...`);
return await addToPlaylist(playlistUUID, [trackToAdd.id!.toString()]);
Expand Down
10 changes: 5 additions & 5 deletions plugins/SongDownloader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ ContextMenu.onOpen(async (contextSource, contextMenu, trackItems) => {

const downloadTrack = async (trackItem: TrackItem, updateMethods: ButtonMethods, folderPath?: string) => {
let trackId = trackItem.id!;
if (settings.useRealMAX && settings.desiredDownloadQuality === AudioQuality.HiRes) {
updateMethods.set("Checking RealMAX for better quality...");
const maxTrack = await MaxTrack.getMaxTrack(trackId);
if (maxTrack !== false) trackId = +maxTrack.id!;
}
// if (settings.useRealMAX && settings.desiredDownloadQuality === AudioQuality.HiRes) {
// updateMethods.set("Checking RealMAX for better quality...");
// const maxTrack = await MaxTrack.getMaxTrack(trackId);
// if (maxTrack !== false) trackId = +maxTrack.id!;
// }

updateMethods.set("Fetching playback info & tags...");
const playbackInfo = PlaybackInfoCache.ensure(trackId, settings.desiredDownloadQuality);
Expand Down

0 comments on commit d04a065

Please sign in to comment.