aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrashant Jha <prashant.kumarjha63@gmail.com>2019-05-01 11:22:35 +0530
committerPrashant Jha <prashant.kumarjha63@gmail.com>2019-05-01 11:22:35 +0530
commit2ed0ab3a69850241b39e35280dd5cb84e397aecb (patch)
tree0f68dfcce3d613e11c5629274e57ade32e5a25c8
parentf0e24f2e30bcfec734462797e0836bd18b54cf3e (diff)
parent5c24e7c4818bfb63a90b045f28102230f56817c1 (diff)
downloadtmdb-desktop-client-2ed0ab3a69850241b39e35280dd5cb84e397aecb.tar.gz
tmdb-desktop-client-2ed0ab3a69850241b39e35280dd5cb84e397aecb.zip
Merge branch 'master' of github.com:prithugoswami/tmdb-desktop-client
-rw-r--r--.gitignore1
-rw-r--r--README.md13
-rw-r--r--src/com/oocpro/tmdbdesktop/Constants.java6
-rw-r--r--src/com/oocpro/tmdbdesktop/Main.java15
-rw-r--r--src/com/oocpro/tmdbdesktop/tmdb/Movie.java40
-rw-r--r--test.java32
-rw-r--r--testUI.java17
-rw-r--r--tmdb.java40
8 files changed, 75 insertions, 89 deletions
diff --git a/.gitignore b/.gitignore
index 6b468b6..2e18814 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
*.class
+/.test
diff --git a/README.md b/README.md
index 493ce9b..860fa44 100644
--- a/README.md
+++ b/README.md
@@ -2,3 +2,16 @@
A simple desktop client that allows users to search Movies and view information
about them.
+
+
+## Compile and Run
+
+**Note: from the root directory**
+
+Compile with:
+
+ javac -cp "src/:lib/*" src/com/oocpro/tmdbdesktop/Main.java
+
+Run:
+
+ java -cp "src/:lib/*" com.oocpro.tmdbdesktop.Main
diff --git a/src/com/oocpro/tmdbdesktop/Constants.java b/src/com/oocpro/tmdbdesktop/Constants.java
new file mode 100644
index 0000000..8b2a0ee
--- /dev/null
+++ b/src/com/oocpro/tmdbdesktop/Constants.java
@@ -0,0 +1,6 @@
+package com.oocpro.tmdbdesktop;
+
+public class Constants{
+ public static final String BASEURL="https://api.themoviedb.org/3";
+ public static final String API_KEY="b888b64c9155c26ade5659ea4dd60e64";
+}
diff --git a/src/com/oocpro/tmdbdesktop/Main.java b/src/com/oocpro/tmdbdesktop/Main.java
new file mode 100644
index 0000000..2fad6f4
--- /dev/null
+++ b/src/com/oocpro/tmdbdesktop/Main.java
@@ -0,0 +1,15 @@
+package com.oocpro.tmdbdesktop;
+
+import com.oocpro.tmdbdesktop.Tmdb.Movie;
+import java.io.IOException;
+
+public class Main{
+ public static void main (String [] args)throws IOException{
+ Movie ring = new Movie(565);
+ System.out.println(ring.title + " ("+ring.year+")");
+ System.out.println("Plotline: " + ring.plotline);
+ System.out.println("Genres: " + ring.genres);
+ System.out.println("Rating: " + ring.rating);
+ }
+}
+
diff --git a/src/com/oocpro/tmdbdesktop/tmdb/Movie.java b/src/com/oocpro/tmdbdesktop/tmdb/Movie.java
new file mode 100644
index 0000000..9bbf32d
--- /dev/null
+++ b/src/com/oocpro/tmdbdesktop/tmdb/Movie.java
@@ -0,0 +1,40 @@
+package com.oocpro.tmdbdesktop.Tmdb;
+
+import com.oocpro.tmdbdesktop.Constants;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.util.List;
+import java.util.Iterator;
+import java.util.ArrayList;
+import org.json.*;
+
+public class Movie{
+ final String MOVIEBASEURL = Constants.BASEURL+"/movie/";
+ public String title;
+ public String year;
+ public String plotline;
+ public List<String> genres;
+ public float rating;
+
+ public Movie(int id)throws IOException, MalformedURLException{
+ String geturl = MOVIEBASEURL+id+"?api_key="+Constants.API_KEY;
+ InputStream res = (InputStream)new URL(geturl).getContent();
+ JSONObject movie = new JSONObject(new JSONTokener(res));
+
+ JSONArray ja_genres = movie.getJSONArray("genres");
+ Iterator genres_itr = ja_genres.iterator();
+
+ genres = new ArrayList<String>();
+ while(genres_itr.hasNext()){
+ JSONObject jo = (JSONObject)genres_itr.next();
+ genres.add(jo.getString("name"));
+ }
+ title = movie.getString("title");
+ year = movie.getString("release_date").substring(0,4);
+ plotline = movie.getString("overview");
+ rating = (float)movie.getDouble("vote_average");
+ }
+}
+
diff --git a/test.java b/test.java
deleted file mode 100644
index 60bf4b2..0000000
--- a/test.java
+++ /dev/null
@@ -1,32 +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.*;
-
-
-class test{
- public static void main(String args[]){
- try{
- String word = "farrago";
- String req_url = (
- "https://googledictionaryapi.eu-gb.mybluemix.net/?define=%s&lang=en"
- );
- URL url = new URL(String.format(req_url, word));
- InputStream res = (InputStream)url.getContent();
- JSONArray ja = new JSONArray(new JSONTokener(res));
- System.out.println(ja.toString(4));
-
- }
- catch(MalformedURLException e){
- System.out.println(e);
- }
- catch(IOException e){
- System.out.println(e);
- }
-
- }
-}
diff --git a/testUI.java b/testUI.java
deleted file mode 100644
index 822225b..0000000
--- a/testUI.java
+++ /dev/null
@@ -1,17 +0,0 @@
-import javax.swing.*;
-
-public class testUI {
-
- public static void main(String [] args){
-
- JFrame f1=new JFrame();
- JButton b1=new JButton("BEGIN");
- b1.setBounds(230,200,100,40);
- f1.add(b1);
- f1.setSize(400,500);
- f1.setLayout(null);
- f1.setVisible(true);
-
- }
-}
-
diff --git a/tmdb.java b/tmdb.java
deleted file mode 100644
index a77c807..0000000
--- a/tmdb.java
+++ /dev/null
@@ -1,40 +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 tmdb{
- static String api_key="b888b64c9155c26ade5659ea4dd60e64"; //TMDB API KEY
- 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,"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
- 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);
- }
- }
-}
-
-