package cc.fascinated.bat.service; import info.movito.themoviedbapi.TmdbApi; import info.movito.themoviedbapi.model.core.Movie; import info.movito.themoviedbapi.model.core.MovieResultsPage; import info.movito.themoviedbapi.model.core.TvSeries; import info.movito.themoviedbapi.model.core.TvSeriesResultsPage; import lombok.Getter; import lombok.SneakyThrows; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.List; /** * @author Nick (okNick) */ @Service @Getter @Log4j2(topic = "TMDB Service") public class TMDBService { /** * The API key. */ private final String apiKey; /** * The TMDB API instance. */ private final TmdbApi tmdbApi; public TMDBService(@Value("${tmdb.api-key}") String apiKey) { this.apiKey = apiKey; this.tmdbApi = new TmdbApi(apiKey); } /** * Lookup movies based on the provided query and options. * * @param query The query to search for * @param includeAdult Whether to include adult content * @param language The language to search in * @param primaryReleaseYear The primary release year to filter by * @param region The region to search in * @param year The year to filter by * @return The list of movies found with the provided query and options */ @SneakyThrows public List lookupMovies(String query, boolean includeAdult, String language, String primaryReleaseYear, String region, String year) { MovieResultsPage movies = tmdbApi.getSearch().searchMovie(query, includeAdult, language, primaryReleaseYear, 1, region, year); if (movies.getTotalResults() == 0) { return null; } return movies.getResults(); } /** * Lookup series based on the provided query and options. * * @param query The query to search for * @param includeAdult Whether to include adult content * @param language The language to search in * @param firstAirDateYear The first air date year to filter by * @param year The year to filter by * @return The list of series found with the provided query and options */ @SneakyThrows public List lookupSeries(String query, boolean includeAdult, String language, int firstAirDateYear, int year) { TvSeriesResultsPage series = tmdbApi.getSearch().searchTv(query, firstAirDateYear, includeAdult, language, 1, year); if (series.getTotalResults() == 0) { return null; } return series.getResults(); } }