OmdbJava is an Easy to use and Light weight Omdb API wrapper for Java
You can use Gradle or maven
- Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
implementation 'com.github.fero1xd:OmdbJava:1.0.3'
}
- Add the repository in pom.xml file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
- Add the dependency
<dependency>
<groupId>com.github.fero1xd</groupId>
<artifactId>OmdbJava</artifactId>
<version>1.0.3</version>
</dependency>
Use the Release Section
- Search a Movie with Title
import me.fero.OmdbJava;
import me.fero.exceptions.ResponseError;
import me.fero.objects.movie.Movie;
public class App {
public static void main(String[] args) {
// Get your API key from https://omdbapi.com/apikey.aspx
OmdbJava omdbJava = new OmdbJava("YOUR_API_KEY");
// Find movie with title (Synchronous)
try {
Movie movie = omdbJava.getMovieByTitle("Turning Red");
System.out.println(movie.getTitle());
System.out.println(movie.getPlot());
System.out.println(movie.getActors());
} catch (ResponseError e) {
e.printStackTrace();
}
}
}
- Find movie with Title (Asynchronous)
import me.fero.OmdbJava;
import me.fero.objects.Item;
import me.fero.objects.movie.Movie;
public class App {
public static void main(String[] args) {
// Get your API key from https://omdbapi.com/apikey.aspx
OmdbJava omdbJava = new OmdbJava("YOUR_API_KEY");
// Find movie with title (Asynchronous)
omdbJava.getMovieByTitle("Turning Red", (Movie movie) -> {
if(movie == null) return;
System.out.println(movie.getTitle());
System.out.println(movie.getPlot());
System.out.println(movie.getActors());
});
}
}
- With Api Key
- Get your API key from https://omdbapi.com/apikey.aspx
import me.fero.OmdbJava;
OmdbJava client = new OmdbJava("YOUR_API_KEY");
- Without API Key
import me.fero.OmdbJava;
OmdbJava client = new OmdbJava();
client.setApiKey("YOUR_API_KEY");
-
The Item class
-
Item class is the parent class for Movie And Series Class
Movie movie = client.getMovieByTitle("Turning Red");
System.out.println(movie.getTitle()); // The title of the movie
System.out.println(movie.getPlot()); // The Plot . Can be passed as a parameter . Eg Plot.SHORT
System.out.println(movie.getActors()); // Gets a list of actors
System.out.println(movie.getLanguages()); // Gets Available languages
System.out.println(movie.getDirector()); // Gets the director of the movie
System.out.println(movie.getRatings()); // Gets a List of Rating Object
// etc....
Iterator iterator = client.searchMovies("Happy new Year");
List<PartialItem> partialItems = new ArrayList<>();
while ((partialItems = iterator.getNextPage()) != null) {
// Loop over partial items or etc ..
}
iterator.getPage(); // Gets current page
iterator.getTotalResults(); // Total
Movie movie = client.getMovieById("tt2372222");
Series series = client.getSeriesById("id");
Series series = client.getSeriesByTitle("Squid Game", Plot.SHORT);
Series series = client.getSeriesByTitle("Money Heist", Plot.FULL); // Default
Type.MOVIE;
Type.SERIES;
Plot.FULL;
Plot.SHORT;