Jonathan Perry
Jonathan Perry

Reputation: 3043

Getting episode info from OMDb API

I'm using the awesome OMDb API in my app, and I wanted to be able to search for episode info using this API.

So far I've been able to search for movies / episodes but I couldn't find a way to search for a specific episode. (I guess I could do this using the episode's IMDB id, but to find that I need to search OMDb, which I don't know how)

Does anyone know of a way to perform this task?

Upvotes: 4

Views: 5845

Answers (1)

grill
grill

Reputation: 1170

OMDb API supports episode search (as of 5/15/2015). In order to search for a specific episode of a show using Java, you'd want to do something like the following (the key params here are episode and season):

String url = "http://www.omdbapi.com/";
String charset = "UTF-8";
String title = "Game of Thrones";
String season = "5";
String episode "5";

String query = String.format("t=%s&season=%s&episode=%s", 
     URLEncoder.encode(title, charset), 
     URLEncoder.encode(season, charset),
     URLEncoder.encode(episode, charset),);

URLConnection connection = new URL(url + "?" + query).openConnection();
connection.setRequestProperty("Accept-Charset", charset);
InputStream response = connection.getInputStream();
// Do some stuff with the data

Take note that this method uses Java's URLConnection package. You can read more about it here, and read a super great tutorial here.

Upvotes: 6

Related Questions