all repos — tmdb-desktop-client @ dbb011e0d83f3ec60650896845fae941b0885d48

A simple tmdb desktop client written in Java

src/com/oocpro/tmdbdesktop/tmdb/Search.java

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{
        static String MOVIE_NAME;
        public List<Integer> IDs;
            public Search()throws IOException,MalformedURLException{                                          //CONSTRUCTOR TO INITIALISE MOVIE ID
                System.out.println("ENTER MOVIE NAME TO SEARCH ");
                BufferedReader mnm = new BufferedReader(new InputStreamReader(System.in));
                MOVIE_NAME = mnm.readLine();
                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 + " ");
                //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();
        }
    }