Skip to content

Commit

Permalink
Implement OMDBAPI for subsort
Browse files Browse the repository at this point in the history
  • Loading branch information
phdelodder committed Sep 24, 2015
1 parent 4f673d6 commit a235b70
Showing 1 changed file with 63 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import org.lodder.subtools.sublibrary.data.IMDB.IMDBAPI;
import org.lodder.subtools.sublibrary.data.IMDB.IMDBException;
import org.lodder.subtools.sublibrary.data.IMDB.IMDBSearchID;
import org.lodder.subtools.sublibrary.data.IMDB.IMDBSearchIDException;
import org.lodder.subtools.sublibrary.data.IMDB.model.IMDBDetails;
import org.lodder.subtools.sublibrary.data.OMDB.OMDBAPI;
import org.lodder.subtools.sublibrary.data.OMDB.OMDBException;
import org.lodder.subtools.sublibrary.data.OMDB.model.OMDBDetails;
import org.lodder.subtools.sublibrary.exception.ReleaseControlException;
import org.lodder.subtools.sublibrary.model.MovieRelease;
import org.lodder.subtools.sublibrary.model.Release;
Expand All @@ -15,46 +19,63 @@
import org.slf4j.LoggerFactory;

public class MovieFileControl extends VideoFileControl {
private final IMDBSearchID imdbSearchID;
private final IMDBAPI imdbapi;

private static final Logger LOGGER = LoggerFactory.getLogger(MovieFileControl.class);

public MovieFileControl(MovieRelease movieRelease, Manager manager) {
super(movieRelease);
imdbapi = new IMDBAPI(manager);
imdbSearchID = new IMDBSearchID(manager);
}

@Override
public Release process(List<MappingTvdbScene> dict) throws ReleaseControlException {
MovieRelease movieRelease = (MovieRelease) release;
if (movieRelease.getTitle().equals("")) {
throw new ReleaseControlException("Unable to extract/find title, check file", release);
} else {
int imdbid = -1;
try {
imdbid = imdbSearchID.getImdbId(movieRelease.getTitle(), movieRelease.getYear());
if (imdbid > 0) {
movieRelease.setImdbid(imdbid);
IMDBDetails imdbinfo;

imdbinfo = imdbapi.getIMDBMovieDetails(movieRelease.getImdbidAsString());
if (imdbinfo != null) {
movieRelease.setYear(imdbinfo.getYear());
movieRelease.setTitle(imdbinfo.getTitle());
} else {
LOGGER.error("Unable to get details from IMDB API, continue with filename info [{}]", release);
}

} else {
throw new ReleaseControlException("Movie not found on IMDB, check file", release);
}
} catch (IMDBException e) {
LOGGER.error("process: IMDBAPI Failed", e);
throw new ReleaseControlException("IMDBAPI Failed", release);
}
return movieRelease;
}
}
private final IMDBSearchID imdbSearchID;
private final IMDBAPI imdbapi;
private final OMDBAPI omdbapi;

private static final Logger LOGGER = LoggerFactory.getLogger(MovieFileControl.class);

public MovieFileControl(MovieRelease movieRelease, Manager manager) {
super(movieRelease);
imdbapi = new IMDBAPI(manager);
omdbapi = new OMDBAPI(manager);
imdbSearchID = new IMDBSearchID(manager);
}

@Override
public Release process(List<MappingTvdbScene> dict) throws ReleaseControlException {
MovieRelease movieRelease = (MovieRelease) release;
if (movieRelease.getTitle().equals("")) {
throw new ReleaseControlException("Unable to extract/find title, check file", release);
} else {
int imdbid = -1;
try {
imdbid = imdbSearchID.getImdbId(movieRelease.getTitle(), movieRelease.getYear());
} catch (IMDBSearchIDException e) {
throw new ReleaseControlException("IMDBASearchID Failed", release);
}
try {
if (imdbid > 0) {
movieRelease.setImdbid(imdbid);
IMDBDetails imdbinfo;

imdbinfo = imdbapi.getIMDBMovieDetails(movieRelease.getImdbidAsString());
if (imdbinfo != null) {
movieRelease.setYear(imdbinfo.getYear());
movieRelease.setTitle(imdbinfo.getTitle());
} else {
LOGGER.error("Unable to get details from IMDB API, continue with filename info {}", release);
}
} else {
throw new ReleaseControlException("Movie not found on IMDB, check file", release);
}
} catch (IMDBException e) {
LOGGER.error("OMDBAPI Failed {}, using OMDBAPI as fallback", release);
OMDBDetails omdbinfo;

try {
omdbinfo = omdbapi.getOMDBMovieDetails(movieRelease.getImdbidAsString());
if (omdbinfo != null) {
movieRelease.setYear(omdbinfo.getYear());
movieRelease.setTitle(omdbinfo.getTitle());
} else {
LOGGER.error("Unable to get details from OMDB API, continue with filename info {}", release);
}
} catch (OMDBException e1) {
throw new ReleaseControlException("OMDBAPI Failed", release);
}
}
return movieRelease;
}
}
}

0 comments on commit a235b70

Please sign in to comment.