Spaces:
Running
Running
File size: 4,099 Bytes
cc2caf9 |
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
import { LoadBalancerAPI } from "./LoadBalancerAPI";
const lb = new LoadBalancerAPI("https://hans-den-load-balancer.hf.space");
export async function getRecentItems(limit = 5) {
const recentData = await lb.getRecent(limit);
console.debug("Raw recent data:", recentData);
const slides = [];
// Process movies and format them as slide objects
if (recentData.movies && Array.isArray(recentData.movies)) {
recentData.movies.forEach(movie => {
const [title, year, description, image, genres] = movie;
slides.push({
type: 'movie',
title,
genre: genres.map(g => g.name), // returns an array of genre names
image,
description,
year,
});
});
}
// Process series and format them as slide objects with type "tvshow"
if (recentData.series && Array.isArray(recentData.series)) {
recentData.series.forEach(series => {
const [title, year, description, image, genres] = series;
slides.push({
type: 'tvshow',
title,
genre: genres.map(g => g.name), // returns an array of genre names
image,
description,
year,
});
});
}
console.debug(slides);
return slides;
}
export async function getNewContents(limit = 5) {
const recentData = await lb.getRecent(limit);
console.debug("Raw recent data:", recentData);
const movies = [];
const tvshows = [];
// Process movies
if (Array.isArray(recentData.movies)) {
recentData.movies.forEach(([title, year, description, image, genres]) => {
movies.push({
title,
genre: genres.map(g => g.name),
image,
description,
year,
});
});
}
// Process TV shows
if (Array.isArray(recentData.series)) {
recentData.series.forEach(([title, year, description, image, genres]) => {
tvshows.push({
title,
genre: genres.map(g => g.name),
image,
description,
year,
});
});
}
console.debug({ movies, tvshows });
return { movies, tvshows };
}
export async function getAllMovies(){
const movies = await lb.getAllMovies();
console.debug(movies);
const formattedMovies = movies.map(title => ({
title: title.replace('films/', '')
}));
return formattedMovies;
}
export async function getAllTvShows() {
const tvshows = await lb.getAllSeriesShows();
// Transform the response to return TV show names with episode count
const formattedTvShows = Object.entries(tvshows).map(([title, episodes]) => ({
title,
episodeCount: episodes.length
}));
return formattedTvShows;
}
export async function getMovieLinkByTitle(title){
const response = await lb.getMovieByTitle(title);
console.debug(response);
return response;
}
export async function getEpisodeLinkByTitle(title, season, episode){
const response = await lb.getSeriesEpisode(title, season, episode);
console.debug(response);
return response;
}
export async function getMovieCard(title){
const movie = await lb.getMovieCard(title);
console.debug(movie);
return movie;
}
export async function getTvShowCard(title){
const tvshow = await lb.getSeriesCard(title);
console.debug(tvshow);
return tvshow;
}
export async function getMovieMetadata(title){
const movie = await lb.getMovieMetadataByTitle(title);
console.debug(movie);
return movie;
}
export async function getTvShowMetadata(title){
const tvshow = await lb.getSeriesMetadataByTitle(title);
console.debug(tvshow);
return tvshow;
}
export async function getSeasonMetadata(title, season){
const data = await lb.getSeasonMetadataByTitleAndSeason(title, season);
console.debug(data);
return data;
}
export async function getGenreCategories(mediaType){
const gc = await lb.getGenreCategories(mediaType);
console.debug(gc);
if (gc.genres)
return gc.genres;
else
return [];
}
export async function getGenresItems(genres, mediaType, limit = 10, page = 1){
const genresRes = await lb.getGenreItems(genres, mediaType, limit, page);
console.debug(genresRes);
return genresRes;
}
|