akborana4 commited on
Commit
a875640
·
verified ·
1 Parent(s): 192db04

Update server/jiosaavn.js

Browse files
Files changed (1) hide show
  1. server/jiosaavn.js +39 -14
server/jiosaavn.js CHANGED
@@ -1,22 +1,47 @@
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
  }
 
1
  import axios from 'axios';
2
 
 
3
  const BASE = 'https://jio-saavn-api-eta.vercel.app';
4
 
5
+ const http = axios.create({
6
+ baseURL: BASE,
7
+ timeout: 12000
8
+ });
9
+
10
+ export async function searchUniversal(query) {
11
+ // /result/?query=
12
+ const { data } = await http.get(`/result/?query=${encodeURIComponent(query)}`);
13
+ return data;
14
+ }
15
+
16
+ export async function getSong(queryOrId) {
17
+ // Supports ?query= or ?id=
18
+ const path = String(queryOrId).startsWith('id:')
19
+ ? `/song/?id=${encodeURIComponent(queryOrId.slice(3))}`
20
+ : `/song/?query=${encodeURIComponent(queryOrId)}`;
21
+ const { data } = await http.get(path);
22
  return data;
23
  }
24
 
25
+ export async function getAlbum(queryOrId) {
26
+ const path = String(queryOrId).startsWith('id:')
27
+ ? `/album/?id=${encodeURIComponent(queryOrId.slice(3))}`
28
+ : `/album/?query=${encodeURIComponent(queryOrId)}`;
29
+ const { data } = await http.get(path);
30
+ return data;
31
+ }
32
+
33
+ export async function getPlaylist(queryOrId) {
34
+ const path = String(queryOrId).startsWith('id:')
35
+ ? `/playlist/?id=${encodeURIComponent(queryOrId.slice(3))}`
36
+ : `/playlist/?query=${encodeURIComponent(queryOrId)}`;
37
+ const { data } = await http.get(path);
38
+ return data;
39
+ }
40
+
41
+ export async function getLyrics(queryOrId) {
42
+ const path = String(queryOrId).startsWith('id:')
43
+ ? `/lyrics/?id=${encodeURIComponent(queryOrId.slice(3))}`
44
+ : `/lyrics/?query=${encodeURIComponent(queryOrId)}`;
45
+ const { data } = await http.get(path);
46
+ return data;
47
  }