forked from Fascinated/Bat
Add support for TMDB movie + series lookup
This commit is contained in:
77
src/main/java/cc/fascinated/bat/service/TMDBService.java
Normal file
77
src/main/java/cc/fascinated/bat/service/TMDBService.java
Normal file
@ -0,0 +1,77 @@
|
||||
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<Movie> 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<TvSeries> 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user