src/com/oocpro/tmdbdesktop/tmdb/Search.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.oocpro.tmdbdesktop.tmdb; import com.oocpro.tmdbdesktop.Constants; import java.net.URL; import java.net.MalformedURLException; import java.io.*; import org.json.*; import javax.swing.*; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Search{ public static List<Integer> IDs; public Search(String MOVIE_NAME)throws IOException,MalformedURLException{ //CONSTRUCTOR TO INITIALISE MOVIE ID String s_url=Constants.BASEURL+"/search/movie?api_key="+Constants.API_KEY+"&language=en-US&query=%s"; //General URL format for finding a movie String url=String.format(s_url,MOVIE_NAME); //Adding the query System.out.println("URL = "+url); URL us1 = new URL(url); //Creating url object InputStream sres = (InputStream)us1.getContent(); //Storing the stream of data we get from the url JSONObject ja = new JSONObject(new JSONTokener(sres)); IDs = new ArrayList<Integer>(); Iterator IDS_itr = ja.getJSONArray("results").iterator(); //Iterating through all the results generated by the query and //getting the IDs of each result while(IDS_itr.hasNext()){ JSONObject id = (JSONObject)IDS_itr.next(); IDs.add(id.getInt("id")); } //System.out.println(IDs.get(1) + " "); //System.out.println(ja.toString(1)); //System.out.println(ja.getNames(ja)); //System.out.println(" "+ja.getInt("total_pages")); } //public static void main(String args[])throws IOException{ // Search sc = new Search(); //} }