use of com.furyviewer.service.dto.TheMovieDB.Artist.CompleteArtistTmdbDTO in project FuryViewer by TheDoctor-95.
the class ArtistTmdbDTOService method getArtistComplete.
/**
* Metodo que se encarga de recuperar toda la informacion del artist de la api de TMDB.
* @param artistName String | Nombre del artista a buscar.
* @return CompleteArtistTmdbDTO | InformaciĆ³n en el formato proporcionado por la API.
* @throws IOException En caso de que no se pueda hacer la peticion a la api se lanza la excepcion.
*/
public CompleteArtistTmdbDTO getArtistComplete(String artistName) throws IOException {
CompleteArtistTmdbDTO artist = null;
int id = getArtistID(artistName);
if (id != -1) {
Call<CompleteArtistTmdbDTO> callArtist = apiTMDB.getFinalArtist(id, apikey);
Response<CompleteArtistTmdbDTO> response = callArtist.execute();
if (response.isSuccessful()) {
artist = response.body();
} else {
throw new IOException(response.message());
}
}
return artist;
}
use of com.furyviewer.service.dto.TheMovieDB.Artist.CompleteArtistTmdbDTO in project FuryViewer by TheDoctor-95.
the class ArtistTmdbDTOService method importArtist.
/**
* Convierte la informacion de un Artist de TMDB al formato de FuryViewer.
* @param artistName String | Nombre del artista a buscar.
* @param artistType ArtistType | Tipo del artista.
* @return Artist | Contiene la informacion de un artist en el formato FuryViewer.
*/
public Artist importArtist(String artistName, ArtistType artistType) {
Artist artist = new Artist();
artist.setName(artistName);
artist.addArtistType(artistType);
System.out.println("==================\nImportanto artista " + artistName + "\n==================");
// podemos realizar la peticiĆ³n a la api.
getArtist: for (int i = 0; i < 3; i++) {
try {
CompleteArtistTmdbDTO completeArtistTmdbDTO = getArtistComplete(artistName);
if (completeArtistTmdbDTO != null) {
if (completeArtistTmdbDTO.getBirthday() != null) {
artist.setBirthdate(dateConversorService.releaseDateOMDBSeason(completeArtistTmdbDTO.getBirthday().toString()));
}
if (completeArtistTmdbDTO.getDeathday() != null) {
if (completeArtistTmdbDTO.getDeathday().toString().split("-").length == 3) {
artist.setDeathdate(dateConversorService.releaseDateOMDBSeason(completeArtistTmdbDTO.getDeathday().toString()));
}
}
if (completeArtistTmdbDTO.getGender() != null) {
switch(completeArtistTmdbDTO.getGender()) {
case 0:
artist.setSex("Undefined");
break;
case 1:
artist.setSex("Female");
break;
case 2:
artist.setSex("Male");
break;
}
}
if (completeArtistTmdbDTO.getProfilePath() != null) {
artist.setImgUrl(pathImage + completeArtistTmdbDTO.getProfilePath());
}
if (completeArtistTmdbDTO.getImdbId() != null) {
artist.setImdb_id(completeArtistTmdbDTO.getImdbId());
}
if (completeArtistTmdbDTO.getPlaceOfBirth() != null) {
artist.setCountry(countryService.importCountry(completeArtistTmdbDTO.getPlaceOfBirth().toString()));
}
if (completeArtistTmdbDTO.getBiography() != null) {
artist.setBiography(stringApiCorrectorService.eraserEvilBytes(completeArtistTmdbDTO.getBiography()));
}
}
// Salimos del bucle
break getArtist;
} catch (IOException e) {
e.printStackTrace();
try {
System.out.println("Durmiendo el thread 5 segundos");
Thread.sleep(5000L);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
artist = artistRepository.save(artist);
System.out.println("==================\nArtista guardado " + artistName + "\n==================");
return artist;
}
Aggregations