@uimaxbai/am-lyrics 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/AmLyrics.d.ts.map +1 -1
- package/dist/src/am-lyrics.js +78 -60
- package/dist/src/am-lyrics.js.map +1 -1
- package/dist/src/react.js +78 -60
- package/dist/src/react.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/AmLyrics.ts +86 -64
package/dist/src/react.js
CHANGED
|
@@ -322,7 +322,7 @@ class GoogleService {
|
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
|
|
325
|
-
const VERSION = '1.2.
|
|
325
|
+
const VERSION = '1.2.1';
|
|
326
326
|
const INSTRUMENTAL_THRESHOLD_MS = 7000; // Show dots for gaps >= 7s
|
|
327
327
|
const FETCH_TIMEOUT_MS = 8000; // Timeout for all lyrics fetch requests
|
|
328
328
|
const SEEK_THRESHOLD_MS = 500;
|
|
@@ -545,7 +545,7 @@ let AmLyrics$1 = class AmLyrics extends i {
|
|
|
545
545
|
if (resolvedMetadata?.metadata && !isMusicIdOnlyRequest) {
|
|
546
546
|
const title = resolvedMetadata.metadata.title?.trim() || '';
|
|
547
547
|
const artist = resolvedMetadata.metadata.artist?.trim() || '';
|
|
548
|
-
const youLyResults = await AmLyrics.fetchLyricsFromYouLyPlus(title, artist, resolvedMetadata.metadata);
|
|
548
|
+
const youLyResults = await AmLyrics.fetchLyricsFromYouLyPlus(title, artist, resolvedMetadata.catalogIsrc, resolvedMetadata.metadata);
|
|
549
549
|
if (youLyResults && youLyResults.length > 0) {
|
|
550
550
|
collectedSources.push(...youLyResults);
|
|
551
551
|
}
|
|
@@ -883,7 +883,7 @@ let AmLyrics$1 = class AmLyrics extends i {
|
|
|
883
883
|
}
|
|
884
884
|
return null;
|
|
885
885
|
}
|
|
886
|
-
static async fetchLyricsFromYouLyPlus(title, artist, metadata = {}) {
|
|
886
|
+
static async fetchLyricsFromYouLyPlus(title, artist, isrc, metadata = {}) {
|
|
887
887
|
if (!title || !artist)
|
|
888
888
|
return [];
|
|
889
889
|
const params = new URLSearchParams({ title, artist });
|
|
@@ -927,75 +927,93 @@ let AmLyrics$1 = class AmLyrics extends i {
|
|
|
927
927
|
return 20;
|
|
928
928
|
};
|
|
929
929
|
const allResults = [];
|
|
930
|
-
// Try cache API first
|
|
930
|
+
// Try BiniLyrics cache API first
|
|
931
931
|
try {
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
932
|
+
let cacheData = null;
|
|
933
|
+
// First attempt: Prefer ISRC search if available
|
|
934
|
+
if (isrc) {
|
|
935
|
+
try {
|
|
936
|
+
const isrcUrl = `https://lyrics-api.binimum.org/?isrc=${encodeURIComponent(isrc)}`;
|
|
937
|
+
const isrcRes = await fetchWithTimeout(isrcUrl);
|
|
938
|
+
if (isrcRes.ok) {
|
|
939
|
+
const data = await isrcRes.json();
|
|
940
|
+
if (data.results && data.results.length > 0) {
|
|
941
|
+
cacheData = data;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
catch (isrcErr) {
|
|
946
|
+
// Fall through to title/artist search
|
|
947
|
+
}
|
|
938
948
|
}
|
|
939
|
-
if
|
|
940
|
-
|
|
949
|
+
// Second attempt: Fallback to title and artist search if ISRC search failed or was not available
|
|
950
|
+
if (!cacheData) {
|
|
951
|
+
const cacheParams = new URLSearchParams({
|
|
952
|
+
track: title,
|
|
953
|
+
artist,
|
|
954
|
+
});
|
|
955
|
+
if (metadata.album) {
|
|
956
|
+
cacheParams.append('album', metadata.album);
|
|
957
|
+
}
|
|
958
|
+
if (metadata.durationMs && metadata.durationMs > 0) {
|
|
959
|
+
cacheParams.append('duration', Math.round(metadata.durationMs / 1000).toString());
|
|
960
|
+
}
|
|
961
|
+
const cacheUrl = `https://lyrics-api.binimum.org/?${cacheParams.toString()}`;
|
|
962
|
+
const cacheRes = await fetchWithTimeout(cacheUrl);
|
|
963
|
+
if (cacheRes.ok) {
|
|
964
|
+
cacheData = await cacheRes.json();
|
|
965
|
+
}
|
|
941
966
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
967
|
+
if (cacheData && cacheData.results && cacheData.results.length > 0) {
|
|
968
|
+
const result = cacheData.results[0];
|
|
969
|
+
if (result.timing_type === 'word' && result.lyricsUrl) {
|
|
970
|
+
const ttmlRes = await fetchWithTimeout(result.lyricsUrl);
|
|
971
|
+
if (ttmlRes.ok) {
|
|
972
|
+
const ttmlText = await ttmlRes.text();
|
|
973
|
+
const lines = AmLyrics.parseTTML(ttmlText);
|
|
974
|
+
if (lines && lines.length > 0) {
|
|
975
|
+
allResults.push({ lines, source: 'BiniLyrics' });
|
|
976
|
+
return allResults;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
else {
|
|
981
|
+
// Not word type, try fetching any word synced lyrics from lyricsplus
|
|
982
|
+
const fallbackParams = new URLSearchParams(params);
|
|
983
|
+
const fallbackUrl = `https://lyricsplus.binimum.org/v2/lyrics/get?${fallbackParams.toString()}`;
|
|
984
|
+
try {
|
|
985
|
+
const fallbackRes = await fetchWithTimeout(fallbackUrl);
|
|
986
|
+
if (fallbackRes.ok) {
|
|
987
|
+
const payload = await fallbackRes.json();
|
|
988
|
+
const lines = AmLyrics.convertKPoeLyrics(payload);
|
|
989
|
+
const hasWordSync = lines?.some((line) => line.text && Array.isArray(line.text) && line.text.length > 1);
|
|
990
|
+
if (lines && lines.length > 0 && hasWordSync) {
|
|
991
|
+
const sourceLabel = payload?.metadata?.source ||
|
|
992
|
+
payload?.metadata?.provider ||
|
|
993
|
+
'LyricsPlus (KPoe)';
|
|
994
|
+
allResults.push({ lines, source: sourceLabel });
|
|
995
|
+
return allResults;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
catch (fallbackError) {
|
|
1000
|
+
// Ignore fallback fetch error
|
|
1001
|
+
}
|
|
1002
|
+
// If fallback fails or has no word sync, fall back to bini lyrics
|
|
1003
|
+
if (result.lyricsUrl) {
|
|
949
1004
|
const ttmlRes = await fetchWithTimeout(result.lyricsUrl);
|
|
950
1005
|
if (ttmlRes.ok) {
|
|
951
1006
|
const ttmlText = await ttmlRes.text();
|
|
952
1007
|
const lines = AmLyrics.parseTTML(ttmlText);
|
|
953
1008
|
if (lines && lines.length > 0) {
|
|
954
|
-
allResults.push({
|
|
1009
|
+
allResults.push({
|
|
1010
|
+
lines,
|
|
1011
|
+
source: 'BiniLyrics',
|
|
1012
|
+
});
|
|
955
1013
|
return allResults;
|
|
956
1014
|
}
|
|
957
1015
|
}
|
|
958
1016
|
}
|
|
959
|
-
else {
|
|
960
|
-
// Not word type, try fetching any word synced lyrics from lyricsplus
|
|
961
|
-
const fallbackParams = new URLSearchParams(params);
|
|
962
|
-
const fallbackUrl = `https://lyricsplus.binimum.org/v2/lyrics/get?${fallbackParams.toString()}`;
|
|
963
|
-
try {
|
|
964
|
-
const fallbackRes = await fetchWithTimeout(fallbackUrl);
|
|
965
|
-
if (fallbackRes.ok) {
|
|
966
|
-
const payload = await fallbackRes.json();
|
|
967
|
-
const lines = AmLyrics.convertKPoeLyrics(payload);
|
|
968
|
-
const hasWordSync = lines?.some((line) => line.text &&
|
|
969
|
-
Array.isArray(line.text) &&
|
|
970
|
-
line.text.length > 1);
|
|
971
|
-
if (lines && lines.length > 0 && hasWordSync) {
|
|
972
|
-
const sourceLabel = payload?.metadata?.source ||
|
|
973
|
-
payload?.metadata?.provider ||
|
|
974
|
-
'LyricsPlus (KPoe)';
|
|
975
|
-
allResults.push({ lines, source: sourceLabel });
|
|
976
|
-
return allResults;
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
catch (fallbackError) {
|
|
981
|
-
// Ignore fallback fetch error
|
|
982
|
-
}
|
|
983
|
-
// If fallback fails or has no word sync, fall back to bini lyrics
|
|
984
|
-
if (result.lyricsUrl) {
|
|
985
|
-
const ttmlRes = await fetchWithTimeout(result.lyricsUrl);
|
|
986
|
-
if (ttmlRes.ok) {
|
|
987
|
-
const ttmlText = await ttmlRes.text();
|
|
988
|
-
const lines = AmLyrics.parseTTML(ttmlText);
|
|
989
|
-
if (lines && lines.length > 0) {
|
|
990
|
-
allResults.push({
|
|
991
|
-
lines,
|
|
992
|
-
source: 'BiniLyrics',
|
|
993
|
-
});
|
|
994
|
-
return allResults;
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
1017
|
}
|
|
1000
1018
|
}
|
|
1001
1019
|
}
|