forked from shafat-96/animeworld
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnaruto.cjs
More file actions
78 lines (70 loc) · 2.68 KB
/
naruto.cjs
File metadata and controls
78 lines (70 loc) · 2.68 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
const fetch = require('node-fetch'); // For Node.js (CommonJS)
const TMDB_API_KEY = '61e2290429798c561450eb56b26de19b';
const BASE_URL = 'https://api.themoviedb.org/3';
const SHOW_ID = 31910; // TMDB ID for "Naruto"
// Function to fetch season details
async function fetchSeasonDetails(seasonNumber) {
try {
const response = await fetch(
`${BASE_URL}/tv/${SHOW_ID}/season/${seasonNumber}?api_key=${TMDB_API_KEY}`
);
if (!response.ok) {
console.error(`Failed to fetch season ${seasonNumber}: ${response.status}`);
return null;
}
const data = await response.json();
return data;
} catch (error) {
console.error(`Error fetching season ${seasonNumber}:`, error.message);
return null;
}
}
// Function to fetch show details and seasons
async function fetchNarutoSeasons() {
try {
// Fetch TV show details
const showResponse = await fetch(
`${BASE_URL}/tv/${SHOW_ID}?api_key=${TMDB_API_KEY}`
);
if (!showResponse.ok) {
throw new Error(`Failed to fetch show details: ${showResponse.status}`);
}
const showData = await showResponse.json();
const showName = showData.name;
const numberOfSeasons = showData.number_of_seasons;
console.log(`Show: ${showName}`);
console.log(`Total Seasons: ${numberOfSeasons}`);
// Fetch each season
const seasons = [];
let cumulativeEpisodeCount = 0; // Track total episodes for continuous ranges
for (let seasonNumber = 0; seasonNumber <= numberOfSeasons; seasonNumber++) { // Include season 0 (Specials)
const seasonData = await fetchSeasonDetails(seasonNumber);
if (seasonData) {
const episodeCount = seasonData.episodes.length;
const startEpisode = cumulativeEpisodeCount + 1;
const endEpisode = cumulativeEpisodeCount + episodeCount;
seasons.push({
season_number: seasonData.season_number,
name: seasonData.name || `Season ${seasonNumber}`,
episode_count: episodeCount,
episode_range: episodeCount > 0 ? `${startEpisode} to ${endEpisode}` : 'No episodes'
});
cumulativeEpisodeCount += episodeCount; // Update cumulative count
}
}
// Output season details
seasons.forEach(season => {
console.log(`Season ${season.season_number}: ${season.name}`);
console.log(` Episode Count: ${season.episode_count}`);
console.log(` Episode Range: ${season.episode_range}`);
});
// Display total episodes
console.log(`Total Episodes Across All Seasons: ${cumulativeEpisodeCount}`);
return seasons;
} catch (error) {
console.error('Error fetching Naruto seasons:', error.message);
return [];
}
}
// Execute the function
fetchNarutoSeasons();