forked from shafat-96/animeworld
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-client.js
More file actions
88 lines (77 loc) · 2.27 KB
/
api-client.js
File metadata and controls
88 lines (77 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* AnimeWorld India API Client
* A JavaScript client for interacting with the AnimeWorld India API
*/
class AnimeWorldAPI {
constructor(baseURL = 'http://localhost:3000') {
this.baseURL = baseURL;
}
/**
* Search for anime content
* @param {string} query - The search query
* @returns {Promise<Array>} - Array of search results
*/
async search(query) {
try {
const response = await fetch(`${this.baseURL}/api/search?query=${encodeURIComponent(query)}`);
if (!response.ok) {
throw new Error(`Search failed with status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('Error searching for anime:', error);
throw error;
}
}
/**
* Get series information and episode list
* @param {string} id - The series ID
* @returns {Promise<Object>} - Series data including episodes
*/
async getSeries(id) {
try {
const response = await fetch(`${this.baseURL}/api/series/${id}`);
if (!response.ok) {
throw new Error(`Failed to get series with status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error(`Error getting series ${id}:`, error);
throw error;
}
}
/**
* Get video player data for an episode
* @param {string} id - The episode ID
* @returns {Promise<Object>} - Player data including iframe source
*/
async getPlayer(id) {
try {
const response = await fetch(`${this.baseURL}/api/player/${id}`);
if (!response.ok) {
throw new Error(`Failed to get player with status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error(`Error getting player for episode ${id}:`, error);
throw error;
}
}
}
// Example usage:
// const api = new AnimeWorldAPI();
//
// // Search for anime
// api.search('jujutsu kaisen').then(results => {
// console.log('Search results:', results);
// });
//
// // Get series info
// api.getSeries('jujutsu-kaisen').then(seriesData => {
// console.log('Series data:', seriesData);
// });
//
// // Get player data
// api.getPlayer('jujutsu-kaisen-1x1').then(playerData => {
// console.log('Player data:', playerData);
// });