3

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?

Jonathan Perry
  • 2,685
  • 1
  • 38
  • 46

1 Answers1

6

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.

Community
  • 1
  • 1
grill
  • 1,140
  • 1
  • 11
  • 24
  • Cool! This really helps a lot. Much appreciated! – Jonathan Perry May 20 '15 at 06:08
  • Actually, the correct query for getting the info is something like this: `http://www.omdbapi.com/?t=Game%20of%20Thrones&Season=1&Episode=1` So you should modify your answer and change the "title" to "t" :) – Jonathan Perry May 20 '15 at 06:12
  • 1
    good catch. thanks. glad this helped! (I wish I had it about 4 months ago) – grill May 20 '15 at 06:13
  • Sorry it took so long to implement :) – bfritz Apr 13 '16 at 20:26
  • @bfritz Is there not any way to get episode details or list of episodes just by episode name? or do you need to have series title/id and season and episode number? i would have thought something like http://www.omdbapi.com/?apikey=***&s=The Contest&type=episode&y=1992 or http://www.omdbapi.com/?apikey=***&t=The Contest&type=episode&y=1992 might get a listing of episodes with that name – axa May 24 '18 at 19:21