|
|
@@ -0,0 +1,218 @@
|
|
|
+package com.cyksj.web.controller.tmdb;
|
|
|
+
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.cyksj.common.util.Jsons;
|
|
|
+import com.cyksj.dto.Result;
|
|
|
+import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.model.request.tmdb.DiscoverParams;
|
|
|
+import com.cyksj.model.response.tmdb.Trending;
|
|
|
+import com.cyksj.model.response.tmdb.WatchProviders;
|
|
|
+import com.cyksj.model.response.tmdb.WatchProvidersRegions;
|
|
|
+import com.cyksj.util.TmdbUtil;
|
|
|
+import info.movito.themoviedbapi.TmdbApi;
|
|
|
+import info.movito.themoviedbapi.TmdbSearch;
|
|
|
+import info.movito.themoviedbapi.TvResultsPage;
|
|
|
+import info.movito.themoviedbapi.model.Genre;
|
|
|
+import info.movito.themoviedbapi.model.MovieDb;
|
|
|
+import info.movito.themoviedbapi.model.core.MovieResultsPage;
|
|
|
+import info.movito.themoviedbapi.model.core.ResultsPage;
|
|
|
+import info.movito.themoviedbapi.model.tv.TvSeries;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author chan
|
|
|
+ * @date 2023/1/4 10:48 AM
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/tmdb")
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class TmdbController {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 搜索
|
|
|
+ */
|
|
|
+ @GetMapping("/search")
|
|
|
+ public Result<TmdbSearch.MultiListResultsPage> search(String keywords, Integer page){
|
|
|
+ TmdbApi tmdbApi = TmdbUtil.getInstance();
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(tmdbApi.getSearch().searchMulti(keywords,"zh-CN",page));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 趋势
|
|
|
+ * timeWindows day 日趋势 week 周趋势
|
|
|
+ */
|
|
|
+ @GetMapping("/trending")
|
|
|
+ public Result<ResultsPage<Trending>>trending(String timeWindows){
|
|
|
+ String all = HttpUtil.get(String.format("https://api.themoviedb.org/3/trending/%s/%s" + "?api_key=" + TmdbUtil.apiKey + "&language=zh-CN", "all", timeWindows));
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(JSONUtil.parseObj(all).toBean(ResultsPage.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 首页tv热门
|
|
|
+ */
|
|
|
+ @GetMapping("/tv/popular")
|
|
|
+ public Result<TvResultsPage>tvPopular(Integer page){
|
|
|
+ TvResultsPage popular = TmdbUtil.getInstance().getTvSeries().getPopular("zh-CN", page);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(popular);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 首页电影热门
|
|
|
+ */
|
|
|
+ @GetMapping("/movie/popular")
|
|
|
+ public Result<MovieResultsPage>moviePopular(Integer page){
|
|
|
+ MovieResultsPage popularMovies = TmdbUtil.getInstance().getMovies().getPopularMovies("zh-CN", page);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(popularMovies);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 首页tv高分
|
|
|
+ */
|
|
|
+ @GetMapping("/tv/top")
|
|
|
+ public Result<TvResultsPage>tvTop(Integer page){
|
|
|
+ TvResultsPage popular = TmdbUtil.getInstance().getTvSeries().getTopRated("zh-CN", page);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(popular);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 首页电影高分
|
|
|
+ */
|
|
|
+ @GetMapping("/movie/top")
|
|
|
+ public Result<MovieResultsPage>movieTop(Integer page){
|
|
|
+ MovieResultsPage popularMovies = TmdbUtil.getInstance().getMovies().getTopRatedMovies("zh-CN", page);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(popularMovies);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 地区列表
|
|
|
+ */
|
|
|
+ @GetMapping("/watch/providers/regions")
|
|
|
+ public Result<ResultsPage<WatchProvidersRegions>>watchProvidersRegions(){
|
|
|
+ ResultsPage<WatchProvidersRegions> regions = JSONUtil.parseObj(HttpUtil.get("https://api.themoviedb.org/3/watch/providers/regions" + "?api_key=" + TmdbUtil.apiKey + "&language=zh-CN")).toBean(ResultsPage.class);
|
|
|
+
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(regions);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 可观看供应商
|
|
|
+ * watch_region 地区
|
|
|
+ */
|
|
|
+ @GetMapping("/watch/providers/movie")
|
|
|
+ public Result<ResultsPage<WatchProviders>> watchProvidersMovie(String watch_region){
|
|
|
+ String url = "https://api.themoviedb.org/3/watch/providers/movie" + "?api_key=" + TmdbUtil.apiKey + "&language=zh-CN";
|
|
|
+ if (StringUtils.isNotBlank(watch_region)) {
|
|
|
+ url += "&watch_region=" + watch_region;
|
|
|
+ }
|
|
|
+ ResultsPage<WatchProviders> regions = JSONUtil.parseObj(HttpUtil.get(url)).toBean(ResultsPage.class);
|
|
|
+
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(regions);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 可观看供应商
|
|
|
+ * watch_region 地区
|
|
|
+ */
|
|
|
+ @GetMapping("/watch/providers/tv")
|
|
|
+ public Result<ResultsPage<WatchProviders>>watchProvidersTv(String watch_region){
|
|
|
+ String url = "https://api.themoviedb.org/3/watch/providers/tv" + "?api_key=" + TmdbUtil.apiKey + "&language=zh-CN";
|
|
|
+ if (StringUtils.isNotBlank(watch_region)) {
|
|
|
+ url += "&watch_region=" + watch_region;
|
|
|
+ }
|
|
|
+ ResultsPage<WatchProviders> regions = JSONUtil.parseObj(
|
|
|
+ HttpUtil.get(url))
|
|
|
+ .toBean(ResultsPage.class);
|
|
|
+
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(regions);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发现tv
|
|
|
+ */
|
|
|
+ @GetMapping("/tv/discover")
|
|
|
+ public Result<TvResultsPage>tvDiscover(Integer page, DiscoverParams discoverParams) throws Exception {
|
|
|
+ Map<String, Object> map = Jsons.toMap(JSONUtil.toJsonStr(discoverParams));
|
|
|
+ map.put("page",page);
|
|
|
+ map.put("api_key",TmdbUtil.apiKey);
|
|
|
+ map.put("language","zh-CN");
|
|
|
+ TvResultsPage resultsPage = JSONUtil.parseObj(HttpUtil.get("https://api.themoviedb.org/3/discover/tv?" + HttpUtil.toParams(map))).toBean(TvResultsPage.class);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(resultsPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发现电影
|
|
|
+ */
|
|
|
+ @GetMapping("/movie/discover")
|
|
|
+ public Result<MovieResultsPage>movieDiscover(Integer page, DiscoverParams discoverParams){
|
|
|
+ Map<String, Object> map = Jsons.toMap(discoverParams);
|
|
|
+ map.put("page",page);
|
|
|
+ map.put("api_key",TmdbUtil.apiKey);
|
|
|
+ map.put("language","zh-CN");
|
|
|
+ MovieResultsPage popularMovies = JSONUtil.parseObj(HttpUtil.get("https://api.themoviedb.org/3/discover/movie?" + HttpUtil.toParams(map))).toBean(MovieResultsPage.class);
|
|
|
+
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(popularMovies);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 电影标签
|
|
|
+ */
|
|
|
+ @GetMapping("/genre/movie/list")
|
|
|
+ public Result<List<Genre>> genreList(){
|
|
|
+ List<Genre> genreList = TmdbUtil.getInstance().getGenre().getGenreList("zh-CN");
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(genreList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * tv标签
|
|
|
+ */
|
|
|
+ @GetMapping("/genre/tv/list")
|
|
|
+ public Result<List<Genre>> tvGenreList(){
|
|
|
+ List<Genre> genreList = JSONUtil.parseObj(HttpUtil.get("https://api.themoviedb.org/3/genre/tv/list" + "?api_key=" + TmdbUtil.apiKey + "&language=zh-CN")).getJSONArray("genres").toList(Genre.class);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(genreList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 电影详情
|
|
|
+ */
|
|
|
+ @GetMapping("/movie/{movie_id}")
|
|
|
+ public Result<MovieDb> movieDetail(@PathVariable Integer movie_id){
|
|
|
+ MovieDb movie = TmdbUtil.getInstance().getMovies().getMovie(movie_id, "zh-CN");
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(movie);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * tv详情
|
|
|
+ */
|
|
|
+ @GetMapping("/tv/{tv_id}")
|
|
|
+ public Result<TvSeries> tvDetail(@PathVariable Integer tv_id){
|
|
|
+ TvSeries series = TmdbUtil.getInstance().getTvSeries().getSeries(tv_id, "zh-CN");
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(series);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 电影可观看供应商
|
|
|
+ */
|
|
|
+ @GetMapping("/movie/{movie_id}/watch/providers")
|
|
|
+ public Result<Map<String,Object>> movieProviders(@PathVariable String movie_id){
|
|
|
+ Map<String,Object> result = JSONUtil.parseObj(HttpUtil.get("https://api.themoviedb.org/3/movie/" + movie_id+ "/watch/providers" + "?api_key=" + TmdbUtil.apiKey + "&language=zh-CN")).getBean("results",Map.class);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * tv可观看供应商
|
|
|
+ */
|
|
|
+ @GetMapping("/tv/{tv_id}/watch/providers")
|
|
|
+ public Result<Map<String,Object>> tvProviders(@PathVariable String tv_id) {
|
|
|
+ Map<String,Object> result = JSONUtil.parseObj(HttpUtil.get("https://api.themoviedb.org/3/tv/" + tv_id+ "/watch/providers" + "?api_key=" + TmdbUtil.apiKey + "&language=zh-CN")).getBean("results",Map.class);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(result);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|