-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtv.example.ts
More file actions
71 lines (60 loc) · 2.77 KB
/
tv.example.ts
File metadata and controls
71 lines (60 loc) · 2.77 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
import { TMDB, type TvShow, type TvCredits, type TvImages } from "@vo1x/tmdb";
/**
* TV Show example demonstrating type-safe access to TV series data
* Shows the differences between TV and Movie data structures
*/
async function main() {
const tmdb = new TMDB({ apiKey: process.env.TMDB_TOKEN! });
const seriesId = 1399; // Game of Thrones
// TV show details with full typing
const tvShow: TvShow = await tmdb.tv.get(seriesId, {
language: "en-US",
});
console.log(`📺 [TV Show] "${tvShow.name}" (${tvShow.firstAirDate})`);
console.log(` Status: ${tvShow.status}`);
console.log(` Seasons: ${tvShow.numberOfSeasons}, Episodes: ${tvShow.numberOfEpisodes}`);
console.log(` Rating: ⭐ ${tvShow.voteAverage}/10 (${tvShow.voteCount} votes)`);
console.log(` Genres: ${tvShow.genres?.map((g) => g.name).join(", ") ?? "None"}`);
console.log(` Networks: ${tvShow.networks?.map((n) => n.name).join(", ") ?? "None"}`);
// Show episode information if available
if (tvShow.lastEpisodeToAir) {
const lastEp = tvShow.lastEpisodeToAir;
console.log(
` Last Episode: S${lastEp.seasonNumber}E${lastEp.episodeNumber} "${lastEp.name}" (${lastEp.airDate})`
);
}
// Credits with typed cast/crew
const tvCredits: TvCredits = await tmdb.tv.credits(seriesId, { language: "en-US" });
console.log(`\n👥 [Cast] ${tvCredits.cast?.length ?? 0} cast members`);
tvCredits.cast?.slice(0, 5).forEach((actor, i) => {
const episodeCount = "total_episode_count" in actor ? actor.total_episode_count : "N/A";
console.log(` ${i + 1}. ${actor.name} as ${actor.character} (${episodeCount} episodes)`);
});
// Show creators/executive producers
console.log(`\n🎬 [Crew] Key crew members:`);
tvCredits.crew
?.filter((person) => person.job === "Executive Producer" || person.job === "Creator")
.slice(0, 3)
.forEach((person) => {
console.log(` ${person.name} - ${person.job}`);
});
// Images and related content
const images: TvImages = await tmdb.tv.images(seriesId, { includeImageLanguage: "en,null" });
console.log(
`\n📸 [Images] Posters: ${images.posters?.length ?? 0}, Backdrops: ${images.backdrops?.length ?? 0}`
);
// Recommendations & Similar shows
const recommendations = await tmdb.tv.recommendations(seriesId, { page: 1 });
const similarShows = await tmdb.tv.similar(seriesId, { page: 1 });
console.log(`\n🔗 [Related Content]`);
console.log(` Recommendations: ${recommendations.totalResults}`);
console.log(` Similar shows: ${similarShows.totalResults}`);
// Show top recommendation
const topRec = recommendations.results?.[0];
if (topRec) {
console.log(
` Top recommendation: "${topRec.name}" (${topRec.firstAirDate}) ⭐ ${topRec.voteAverage}`
);
}
}
main().catch(console.error);