Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lyrics-plus): add select language translation for Musixmatch provider #3288

Merged
merged 15 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions CustomApps/lyrics-plus/OptionsMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,16 @@ const TranslationMenu = react.memo(({ friendlyLanguage, hasTranslation }) => {

let modeOptions = {};

if (hasTranslation.musixmatch) {
sourceOptions = {
...sourceOptions,
musixmatchTranslation: "English (Musixmatch)",
};
}
if (hasTranslation.musixmatch) {
const selectedLanguage = CONFIG.visual["musixmatch-translation-language"];
const languageName = new Intl.DisplayNames([selectedLanguage], {
type: "language",
}).of(selectedLanguage);
sourceOptions = {
...sourceOptions,
musixmatchTranslation: `${languageName} (Musixmatch)`,
};
}

if (hasTranslation.netease) {
sourceOptions = {
Expand Down
48 changes: 29 additions & 19 deletions CustomApps/lyrics-plus/ProviderMusixmatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,33 +159,43 @@ const ProviderMusixmatch = (() => {
}

async function getTranslation(body) {
const track_id = body?.["matcher.track.get"]?.message?.body?.track?.track_id;
if (!track_id) return null;
const track_id =
body?.["matcher.track.get"]?.message?.body?.track?.track_id;
if (!track_id) return null;

const baseURL =
"https://apic-desktop.musixmatch.com/ws/1.1/crowd.track.translations.get?translation_fields_set=minimal&selected_language=en&comment_format=text&format=json&app_id=web-desktop-app-v1.0&";
const selectedLanguage =
CONFIG.visual["musixmatch-translation-language"] || "none";

rxri marked this conversation as resolved.
Show resolved Hide resolved
const params = {
track_id,
usertoken: CONFIG.providers.musixmatch.token,
};
if (selectedLanguage === "none") return null;

const finalURL =
baseURL +
Object.keys(params)
.map((key) => `${key}=${encodeURIComponent(params[key])}`)
.join("&");
const baseURL =
"https://apic-desktop.musixmatch.com/ws/1.1/crowd.track.translations.get?translation_fields_set=minimal&comment_format=text&format=json&app_id=web-desktop-app-v1.0&";

let result = await Spicetify.CosmosAsync.get(finalURL, null, headers);
const params = {
track_id,
selected_language: selectedLanguage,
usertoken: CONFIG.providers.musixmatch.token,
};

if (result.message.header.status_code !== 200) return null;
const finalURL =
baseURL +
Object.keys(params)
.map((key) => `${key}=${encodeURIComponent(params[key])}`)
.join("&");

result = result.message.body;
let result = await Spicetify.CosmosAsync.get(finalURL, null, headers);

if (!result.translations_list?.length) return null;
if (result.message.header.status_code !== 200) return null;

return result.translations_list.map(({ translation }) => ({ translation: translation.description, matchedLine: translation.matched_line }));
}
result = result.message.body;

if (!result.translations_list?.length) return null;

return result.translations_list.map(({ translation }) => ({
translation: translation.description,
matchedLine: translation.matched_line,
}));
}

return { findLyrics, getKaraoke, getSynced, getUnsynced, getTranslation };
})();
69 changes: 69 additions & 0 deletions CustomApps/lyrics-plus/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,72 @@ function openConfig() {
max: thresholdSizeLimit.max,
step: thresholdSizeLimit.step,
},
{
desc: "Musixmatch Translation Language.",
info: "Choose the language you want to translate the lyrics to. Changes will take effect after the next track.",
key: "musixmatch-translation-language",
type: ConfigSelection,
options: {
none: "None",
ianz56 marked this conversation as resolved.
Show resolved Hide resolved
en: "English",
af: "Afrikaans",
ar: "Arabic",
bg: "Bulgarian",
bn: "Bengali",
ca: "Catalan",
zh: "Chinese",
cs: "Czech",
da: "Danish",
de: "German",
el: "Greek",
es: "Spanish",
et: "Estonian",
fa: "Persian",
fi: "Finnish",
fr: "French",
gu: "Gujarati",
he: "Hebrew",
hi: "Hindi",
hr: "Croatian",
hu: "Hungarian",
id: "Indonesian",
is: "Icelandic",
it: "Italian",
pt: "Portuguese",
ja: "Japanese",
jv: "Javanese",
kn: "Kannada",
ko: "Korean",
lt: "Lithuanian",
lv: "Latvian",
ml: "Malayalam",
mr: "Marathi",
ms: "Malay",
nl: "Dutch",
no: "Norwegian",
pl: "Polish",
pt: "Portuguese",
ro: "Romanian",
ru: "Russian",
sk: "Slovak",
sl: "Slovenian",
sr: "Serbian",
su: "Sundanese",
sv: "Swedish",
ta: "Tamil",
te: "Telugu",
th: "Thai",
tr: "Turkish",
uk: "Ukrainian",
ur: "Urdu",
vi: "Vietnamese",
zu: "Zulu",
},
defaultValue:
localStorage.getItem(
`${APP_NAME}:visual:musixmatch-translation-language`
) || "none",
},
],
onChange: (name, value) => {
CONFIG.visual[name] = value;
Expand Down Expand Up @@ -684,3 +750,6 @@ function openConfig() {
isLarge: true,
});
}
CONFIG.visual["musixmatch-translation-language"] =
localStorage.getItem(`${APP_NAME}:visual:musixmatch-translation-language`) ||
"none";
ianz56 marked this conversation as resolved.
Show resolved Hide resolved
Loading