tunzo-player 1.0.30 → 1.0.32

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.
@@ -1,11 +1,18 @@
1
1
  export declare class TunzoPlayerAPI {
2
+ private baseUrl;
2
3
  /**
3
- * Search for songs using the saavn.dev API
4
+ * Register/Update the base API URL
5
+ * @param url The new base URL to use for API calls
6
+ */
7
+ registerApiUrl(url: string): void;
8
+ /**
9
+ * Search for songs using the API
4
10
  * @param query Search keyword (e.g., artist name, song name)
5
11
  * @param limit Number of results to return (default: 250)
6
12
  * @returns Array of song result objects
7
13
  */
8
14
  searchSongs(query: string, limit?: number): Promise<any[]>;
15
+ suggesstedSongs(id: string, limit?: number): Promise<any[]>;
9
16
  /**
10
17
  * Search for playlists
11
18
  * @param query Search keyword
@@ -11,8 +11,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TunzoPlayerAPI = void 0;
13
13
  class TunzoPlayerAPI {
14
+ constructor() {
15
+ this.baseUrl = "https://saavn.sumit.co/api";
16
+ }
14
17
  /**
15
- * Search for songs using the saavn.dev API
18
+ * Register/Update the base API URL
19
+ * @param url The new base URL to use for API calls
20
+ */
21
+ registerApiUrl(url) {
22
+ this.baseUrl = url;
23
+ }
24
+ /**
25
+ * Search for songs using the API
16
26
  * @param query Search keyword (e.g., artist name, song name)
17
27
  * @param limit Number of results to return (default: 250)
18
28
  * @returns Array of song result objects
@@ -21,7 +31,7 @@ class TunzoPlayerAPI {
21
31
  return __awaiter(this, arguments, void 0, function* (query, limit = 250) {
22
32
  var _a;
23
33
  try {
24
- const response = yield fetch(`https://saavn.sumit.co/api/search/songs?query=${encodeURIComponent(query)}&limit=${limit}`);
34
+ const response = yield fetch(`${this.baseUrl}/search/songs?query=${encodeURIComponent(query)}&limit=${limit}`);
25
35
  if (!response.ok) {
26
36
  throw new Error(`HTTP error! status: ${response.status}`);
27
37
  }
@@ -34,6 +44,23 @@ class TunzoPlayerAPI {
34
44
  }
35
45
  });
36
46
  }
47
+ suggesstedSongs(id_1) {
48
+ return __awaiter(this, arguments, void 0, function* (id, limit = 100) {
49
+ var _a;
50
+ try {
51
+ const response = yield fetch(`${this.baseUrl}/songs/${id}/suggestions?limit=${limit}`);
52
+ if (!response.ok) {
53
+ throw new Error(`HTTP error! status: ${response.status}`);
54
+ }
55
+ const json = yield response.json();
56
+ return ((_a = json === null || json === void 0 ? void 0 : json.data) === null || _a === void 0 ? void 0 : _a.results) || [];
57
+ }
58
+ catch (error) {
59
+ console.error("TunzoPlayerAPI Error (suggesstedSongs):", error);
60
+ return [];
61
+ }
62
+ });
63
+ }
37
64
  /**
38
65
  * Search for playlists
39
66
  * @param query Search keyword
@@ -43,7 +70,7 @@ class TunzoPlayerAPI {
43
70
  return __awaiter(this, arguments, void 0, function* (query, limit = 1000) {
44
71
  var _a;
45
72
  try {
46
- const response = yield fetch(`https://saavn.sumit.co/api/search/playlists?query=${encodeURIComponent(query)}&limit=${limit}`);
73
+ const response = yield fetch(`${this.baseUrl}/search/playlists?query=${encodeURIComponent(query)}&limit=${limit}`);
47
74
  if (!response.ok) {
48
75
  throw new Error(`HTTP error! status: ${response.status}`);
49
76
  }
@@ -65,7 +92,7 @@ class TunzoPlayerAPI {
65
92
  getPlaylistDetails(id_1) {
66
93
  return __awaiter(this, arguments, void 0, function* (id, link = "", limit = 1000) {
67
94
  try {
68
- let url = `https://saavn.sumit.co/api/playlists?id=${id}&limit=${limit}`;
95
+ let url = `${this.baseUrl}/playlists?id=${id}&limit=${limit}`;
69
96
  if (link) {
70
97
  url += `&link=${encodeURIComponent(link)}`;
71
98
  }
@@ -91,7 +118,7 @@ class TunzoPlayerAPI {
91
118
  return __awaiter(this, arguments, void 0, function* (query, limit = 1000) {
92
119
  var _a;
93
120
  try {
94
- const response = yield fetch(`https://saavn.sumit.co/api/search/albums?query=${encodeURIComponent(query)}&limit=${limit}`);
121
+ const response = yield fetch(`${this.baseUrl}/search/albums?query=${encodeURIComponent(query)}&limit=${limit}`);
95
122
  if (!response.ok) {
96
123
  throw new Error(`HTTP error! status: ${response.status}`);
97
124
  }
@@ -112,7 +139,7 @@ class TunzoPlayerAPI {
112
139
  getAlbumDetails(id_1) {
113
140
  return __awaiter(this, arguments, void 0, function* (id, link = "") {
114
141
  try {
115
- let url = `https://saavn.sumit.co/api/albums?id=${id}`;
142
+ let url = `${this.baseUrl}/albums?id=${id}`;
116
143
  if (link) {
117
144
  url += `&link=${encodeURIComponent(link)}`;
118
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tunzo-player",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "A music playback service for Angular and Ionic apps with native audio control support.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +1,16 @@
1
1
  export class TunzoPlayerAPI {
2
+ private baseUrl: string = "https://saavn.sumit.co/api";
3
+
4
+ /**
5
+ * Register/Update the base API URL
6
+ * @param url The new base URL to use for API calls
7
+ */
8
+ registerApiUrl(url: string): void {
9
+ this.baseUrl = url;
10
+ }
11
+
2
12
  /**
3
- * Search for songs using the saavn.dev API
13
+ * Search for songs using the API
4
14
  * @param query Search keyword (e.g., artist name, song name)
5
15
  * @param limit Number of results to return (default: 250)
6
16
  * @returns Array of song result objects
@@ -8,7 +18,7 @@ export class TunzoPlayerAPI {
8
18
  async searchSongs(query: string, limit: number = 250): Promise<any[]> {
9
19
  try {
10
20
  const response = await fetch(
11
- `https://saavn.sumit.co/api/search/songs?query=${encodeURIComponent(query)}&limit=${limit}`
21
+ `${this.baseUrl}/search/songs?query=${encodeURIComponent(query)}&limit=${limit}`
12
22
  );
13
23
 
14
24
  if (!response.ok) {
@@ -23,6 +33,24 @@ export class TunzoPlayerAPI {
23
33
  }
24
34
  }
25
35
 
36
+ async suggesstedSongs(id: string, limit: number = 100): Promise<any[]> {
37
+ try {
38
+ const response = await fetch(
39
+ `${this.baseUrl}/songs/${id}/suggestions?limit=${limit}`
40
+ );
41
+
42
+ if (!response.ok) {
43
+ throw new Error(`HTTP error! status: ${response.status}`);
44
+ }
45
+
46
+ const json = await response.json();
47
+ return json?.data?.results || [];
48
+ } catch (error) {
49
+ console.error("TunzoPlayerAPI Error (suggesstedSongs):", error);
50
+ return [];
51
+ }
52
+ }
53
+
26
54
  /**
27
55
  * Search for playlists
28
56
  * @param query Search keyword
@@ -31,7 +59,7 @@ export class TunzoPlayerAPI {
31
59
  async searchPlaylists(query: string, limit: number = 1000): Promise<any[]> {
32
60
  try {
33
61
  const response = await fetch(
34
- `https://saavn.sumit.co/api/search/playlists?query=${encodeURIComponent(query)}&limit=${limit}`
62
+ `${this.baseUrl}/search/playlists?query=${encodeURIComponent(query)}&limit=${limit}`
35
63
  );
36
64
 
37
65
  if (!response.ok) {
@@ -54,7 +82,7 @@ export class TunzoPlayerAPI {
54
82
  */
55
83
  async getPlaylistDetails(id: string, link: string = "", limit: number = 1000): Promise<any> {
56
84
  try {
57
- let url = `https://saavn.sumit.co/api/playlists?id=${id}&limit=${limit}`;
85
+ let url = `${this.baseUrl}/playlists?id=${id}&limit=${limit}`;
58
86
  if (link) {
59
87
  url += `&link=${encodeURIComponent(link)}`;
60
88
  }
@@ -81,7 +109,7 @@ export class TunzoPlayerAPI {
81
109
  async searchAlbums(query: string, limit: number = 1000): Promise<any[]> {
82
110
  try {
83
111
  const response = await fetch(
84
- `https://saavn.sumit.co/api/search/albums?query=${encodeURIComponent(query)}&limit=${limit}`
112
+ `${this.baseUrl}/search/albums?query=${encodeURIComponent(query)}&limit=${limit}`
85
113
  );
86
114
 
87
115
  if (!response.ok) {
@@ -103,7 +131,7 @@ export class TunzoPlayerAPI {
103
131
  */
104
132
  async getAlbumDetails(id: string, link: string = ""): Promise<any> {
105
133
  try {
106
- let url = `https://saavn.sumit.co/api/albums?id=${id}`;
134
+ let url = `${this.baseUrl}/albums?id=${id}`;
107
135
  if (link) {
108
136
  url += `&link=${encodeURIComponent(link)}`;
109
137
  }