Spaces:
Sleeping
Sleeping
Create jiosaavn.js
Browse files- server/jiosaavn.js +22 -0
server/jiosaavn.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import axios from 'axios';
|
| 2 |
+
|
| 3 |
+
// Update to your deployed endpoint base
|
| 4 |
+
const BASE = 'https://jio-saavn-api-eta.vercel.app';
|
| 5 |
+
|
| 6 |
+
export async function searchSongs(query) {
|
| 7 |
+
const url = `${BASE}/song/?query=${encodeURIComponent(query)}`;
|
| 8 |
+
const { data } = await axios.get(url, { timeout: 10000 });
|
| 9 |
+
// Shape depends on your API. Normalize to { id, title, artists, image, url? }
|
| 10 |
+
return data;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
// If your API provides a method to resolve to a direct stream URL,
|
| 14 |
+
// implement it here. If stream URLs are in search results, you may not need this.
|
| 15 |
+
export async function resolveStreamUrl(song) {
|
| 16 |
+
// Example passthrough; adapt to your API’s shape.
|
| 17 |
+
if (song.url) return song.url;
|
| 18 |
+
// Else attempt another endpoint if available
|
| 19 |
+
// const { data } = await axios.get(`${BASE}/resolve?id=${song.id}`);
|
| 20 |
+
// return data.streamUrl;
|
| 21 |
+
throw new Error('No stream URL available for this song item');
|
| 22 |
+
}
|