aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrashant Jha <prashant.kumarjha63@gmail.com>2019-05-01 17:45:58 +0530
committerPrashant Jha <prashant.kumarjha63@gmail.com>2019-05-01 17:45:58 +0530
commitdbb011e0d83f3ec60650896845fae941b0885d48 (patch)
tree973ec8a343048f8869dfa899ff050cc00d56f06a
parentcce66ec64f052c81eefdaae865b1af737fa799b5 (diff)
downloadtmdb-desktop-client-dbb011e0d83f3ec60650896845fae941b0885d48.tar.gz
tmdb-desktop-client-dbb011e0d83f3ec60650896845fae941b0885d48.zip
Search class to return IDS of result movies
-rw-r--r--src/com/oocpro/tmdbdesktop/Main.java2
-rw-r--r--src/com/oocpro/tmdbdesktop/tmdb/Detail.java41
-rw-r--r--src/com/oocpro/tmdbdesktop/tmdb/Movie.java1
-rw-r--r--src/com/oocpro/tmdbdesktop/tmdb/Search.java74
4 files changed, 40 insertions, 78 deletions
diff --git a/src/com/oocpro/tmdbdesktop/Main.java b/src/com/oocpro/tmdbdesktop/Main.java
index 2fad6f4..58b008c 100644
--- a/src/com/oocpro/tmdbdesktop/Main.java
+++ b/src/com/oocpro/tmdbdesktop/Main.java
@@ -1,6 +1,6 @@
package com.oocpro.tmdbdesktop;
-import com.oocpro.tmdbdesktop.Tmdb.Movie;
+import com.oocpro.tmdbdesktop.tmdb.Movie;
import java.io.IOException;
public class Main{
diff --git a/src/com/oocpro/tmdbdesktop/tmdb/Detail.java b/src/com/oocpro/tmdbdesktop/tmdb/Detail.java
deleted file mode 100644
index 18d055c..0000000
--- a/src/com/oocpro/tmdbdesktop/tmdb/Detail.java
+++ /dev/null
@@ -1,41 +0,0 @@
- import java.net.URL;
- import java.net.MalformedURLException;
- import java.io.IOException;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.InputStream;
- import org.json.*;
- import javax.swing.*;
-
- public class Movie{
- static String api_key="b888b64c9155c26ade5659ea4dd60e64"; //TMDB API KEY
- static String a_url="https://api.themoviedb.org/3/"; //ROOT URL FOR TMDB API
- static String MOVIE_ID;
- Movie(String M_ID){ //CONSTRUCTOR TO INITIALISE MOVIE ID
- this.MOVIE_ID=M_ID;
- }
-
-
- public static void main(String [] args){
- try{
- System.out.println("ENTER MOVIE ID TO SEARCH ");
- BufferedReader mid=new BufferedReader(new InputStreamReader(System.in));
- String m_id= mid.readLine();
- Movie obj = new Movie(m_id);
- String s_url=a_url+"movie/"+MOVIE_ID+"?api_key="+api_key+"&language=en-US"; //General URL format for finding a movie
- URL us1 = new URL(s_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));
- //System.out.println(ja.toString(1));
- }
- catch(MalformedURLException e){
- System.out.println(e);
- }
- catch(IOException e){
- System.out.println(e);
- }
- }
- }
-
-
-
diff --git a/src/com/oocpro/tmdbdesktop/tmdb/Movie.java b/src/com/oocpro/tmdbdesktop/tmdb/Movie.java
index 33141bf..e76fcbb 100644
--- a/src/com/oocpro/tmdbdesktop/tmdb/Movie.java
+++ b/src/com/oocpro/tmdbdesktop/tmdb/Movie.java
@@ -23,6 +23,7 @@ public class Movie{
String geturl = MOVIEBASEURL+id+"?api_key="+Constants.API_KEY;
InputStream res = (InputStream)new URL(geturl).getContent();
JSONObject movie = new JSONObject(new JSONTokener(res));
+ System.out.println(movie.toString(1));
genres = new ArrayList<String>();
Iterator genres_itr = movie.getJSONArray("genres").iterator();
diff --git a/src/com/oocpro/tmdbdesktop/tmdb/Search.java b/src/com/oocpro/tmdbdesktop/tmdb/Search.java
index 6f45747..4caa3bd 100644
--- a/src/com/oocpro/tmdbdesktop/tmdb/Search.java
+++ b/src/com/oocpro/tmdbdesktop/tmdb/Search.java
@@ -1,46 +1,48 @@
+package com.oocpro.tmdbdesktop.tmdb;
+
+import com.oocpro.tmdbdesktop.Constants;
import java.net.URL;
import java.net.MalformedURLException;
-import java.io.IOException;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.InputStream;
+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 api_key="b888b64c9155c26ade5659ea4dd60e64"; //TMDB API KEY
- static String a_url="https://api.themoviedb.org/3/"; //ROOT URL FOR TMDB API
static String MOVIE_NAME;
- Search(String M_ID){ //CONSTRUCTOR TO INITIALISE MOVIE ID
- this.MOVIE_NAME=M_ID;
- }
-
-
- public static void main(String [] args){
- try{
- System.out.println("ENTER MOVIE NAME TO SEARCH ");
- BufferedReader mnm=new BufferedReader(new InputStreamReader(System.in));
- String m_name= mnm.readLine();
- Search obj = new Search(m_name);
- String s_url=a_url+"search/movie?api_key="+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));
- System.out.println(ja.toString(1));
- //System.out.println(ja.getNames(ja));
- //String[] ar;
- //ar=ja.getNames(ja);
- //for(int i=0;i<ar.length;i++)
- // System.out.println(ar[i]+" ");
- }
- catch(MalformedURLException e){
- System.out.println(e);
- }
- catch(IOException e){
- System.out.println(e);
+ 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();
}
}