use of com.furyviewer.service.dto.TheMovieDB.Season.SeasonTmdbDTO in project FuryViewer by TheDoctor-95.
the class SeriesTmdbDTOService method importEpisode.
/**
* Convierte la informacion de un episode de TMDB al formato de Furyviewer.
* @param seriesName String | Titulo de la series a buscar.
* @param episodeNum int | Numero del episode a buscar.
* @param season Season | Season a la que pertenece el episode.
* @throws IOException En caso de que no se pueda hacer la peticion a la api se lanza la execpcion.
*/
public void importEpisode(String seriesName, int episodeNum, com.furyviewer.domain.Season season) throws IOException {
int seriesId = getIdTmdbSeries(seriesName);
SeasonTmdbDTO se;
Call<SeasonTmdbDTO> callSeason = apiTMDB.getSeason(seriesId, season.getNumber(), apikey);
Response<SeasonTmdbDTO> response = callSeason.execute();
if (response.isSuccessful()) {
se = response.body();
Episode ep = new Episode();
ep.setNumber(episodeNum);
episodeNum = episodeNum - 1;
if (se.getEpisodes().get(episodeNum).getName() != null) {
ep.setName(se.getEpisodes().get(episodeNum).getName());
}
double duration = getDurationEpisode(seriesId);
if (duration != -1) {
ep.setDuration(duration);
}
if (se.getEpisodes().get(episodeNum).getAirDate() != null) {
ep.setReleaseDate(dateConversorService.releaseDateOMDBSeason(se.getEpisodes().get(episodeNum).getAirDate()));
}
String imdbId = getImdbId(seriesId, season.getNumber(), episodeNum);
if (imdbId != null) {
ep.setImdbId(imdbId);
}
ep.setSeason(season);
if (se.getEpisodes().get(episodeNum).getOverview() != null) {
ep.setDescription(stringApiCorrectorService.eraserEvilBytes(se.getEpisodes().get(episodeNum).getOverview()));
}
if (se.getEpisodes().get(episodeNum).getCrew() != null) {
for (Crew crew : se.getEpisodes().get(episodeNum).getCrew()) {
if (crew.getJob().equalsIgnoreCase("Director")) {
ep.setDirector(artistService.importDirector(crew.getName()));
} else if (crew.getJob().equalsIgnoreCase("Writer")) {
ep.setScriptwriter(artistService.importScripwriter(crew.getName()));
}
}
}
ep = episodeRepository.save(ep);
importActors(seriesId, ep);
System.out.println("==================\nImportado..." + seriesName + " " + season.getNumber() + "x" + episodeNum + "\n==================");
} else {
throw new IOException(response.message());
}
}
Aggregations