@pulso/companion 0.1.6 → 0.1.7
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/index.js +30 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -78,7 +78,10 @@ async function spotifySearch(query) {
|
|
|
78
78
|
}
|
|
79
79
|
} catch {
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
let trackIds = await searchBraveForSpotifyTracks(query);
|
|
82
|
+
if (trackIds.length === 0) {
|
|
83
|
+
trackIds = await searchStartpageForSpotifyTracks(query);
|
|
84
|
+
}
|
|
82
85
|
if (trackIds.length === 0) return null;
|
|
83
86
|
const meta = await getTrackMetadata(trackIds[0]);
|
|
84
87
|
const result = {
|
|
@@ -113,6 +116,32 @@ async function searchBraveForSpotifyTracks(query) {
|
|
|
113
116
|
return [];
|
|
114
117
|
}
|
|
115
118
|
}
|
|
119
|
+
async function searchStartpageForSpotifyTracks(query) {
|
|
120
|
+
try {
|
|
121
|
+
const searchQuery = `${query} spotify open.spotify.com`;
|
|
122
|
+
const controller = new AbortController();
|
|
123
|
+
const timeout = setTimeout(() => controller.abort(), 8e3);
|
|
124
|
+
const res = await fetch("https://www.startpage.com/sp/search", {
|
|
125
|
+
method: "POST",
|
|
126
|
+
headers: {
|
|
127
|
+
"User-Agent": UA,
|
|
128
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
129
|
+
},
|
|
130
|
+
body: `query=${encodeURIComponent(searchQuery)}`,
|
|
131
|
+
signal: controller.signal
|
|
132
|
+
});
|
|
133
|
+
clearTimeout(timeout);
|
|
134
|
+
if (!res.ok) return [];
|
|
135
|
+
const html = await res.text();
|
|
136
|
+
const trackIds = /* @__PURE__ */ new Set();
|
|
137
|
+
for (const m of html.matchAll(/open\.spotify\.com(?:\/intl-[a-z]+)?\/track\/([a-zA-Z0-9]{22})/g)) {
|
|
138
|
+
trackIds.add(m[1]);
|
|
139
|
+
}
|
|
140
|
+
return [...trackIds];
|
|
141
|
+
} catch {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
116
145
|
async function getTrackMetadata(trackId) {
|
|
117
146
|
try {
|
|
118
147
|
const controller = new AbortController();
|