aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrashant Jha <prashant.kumarjha63@gmail.com>2019-05-01 10:48:02 +0530
committerPrashant Jha <prashant.kumarjha63@gmail.com>2019-05-01 10:48:02 +0530
commitf0e24f2e30bcfec734462797e0836bd18b54cf3e (patch)
treeb84e4b8b950feb248ff82cf22a0c974880cf7dba
parenteaf34cc543a99fdb2ddbd59a9af1b3623f23a7bb (diff)
downloadtmdb-desktop-client-f0e24f2e30bcfec734462797e0836bd18b54cf3e.tar.gz
tmdb-desktop-client-f0e24f2e30bcfec734462797e0836bd18b54cf3e.zip
Search and Movie classes
-rw-r--r--Movie.java41
-rw-r--r--Search.java47
-rw-r--r--tmdb.java15
3 files changed, 95 insertions, 8 deletions
diff --git a/Movie.java b/Movie.java
new file mode 100644
index 0000000..18d055c
--- /dev/null
+++ b/Movie.java
@@ -0,0 +1,41 @@
+ 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/Search.java b/Search.java
new file mode 100644
index 0000000..6f45747
--- /dev/null
+++ b/Search.java
@@ -0,0 +1,47 @@
+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 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);
+ }
+ }
+ }
+
+
diff --git a/tmdb.java b/tmdb.java
index 4b745c7..a77c807 100644
--- a/tmdb.java
+++ b/tmdb.java
@@ -9,24 +9,24 @@ import javax.swing.*;
public class tmdb{
static String api_key="b888b64c9155c26ade5659ea4dd60e64"; //TMDB API KEY
- static String a_url="https://api.themoviedb.org/4/"; //ROOT URL FOR TMDB API
+ static String a_url="https://api.themoviedb.org/3/"; //ROOT URL FOR TMDB API
public static void main(String [] args){
try{
-
+
// }
// catch{
// {
// }
//}
-
+
//static void search(String mov){ //function for searching a movie
String s_url=a_url+"search/movie?api_key="+api_key+"&query=%s"; //General URL format for finding a movie
- String url=String.format(s_url,"CARS"); //Adding the query
+ String url=String.format(s_url,"sherlock"); //Adding the query
URL us1 = new URL(url); //Creating url object
InputStream sres = (InputStream)us1.getContent(); //Storing the stream of data we get from the url
- JSONArray ja = new JSONArray(new JSONTokener(sres));
- System.out.println(ja.toString(4));
+ JSONObject ja = new JSONObject(new JSONTokener(sres));
+ System.out.println(ja.toString(1));
}
catch(MalformedURLException e){
System.out.println(e);
@@ -34,8 +34,7 @@ public class tmdb{
catch(IOException e){
System.out.println(e);
}
-
-
}
}
+