aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprithugoswami <prithugoswami524@gmail.com>2019-04-30 23:57:20 +0530
committerprithugoswami <prithugoswami524@gmail.com>2019-04-30 23:57:20 +0530
commite242e75e4c085076f9f55401e4e0d523d9b6969d (patch)
treeada2a54a8856aa60ec87708d0fd8671f4a5e1117
parent0cc74df861e68ba5695766c635a6f0058bf90966 (diff)
downloadtmdb-desktop-client-e242e75e4c085076f9f55401e4e0d523d9b6969d.tar.gz
tmdb-desktop-client-e242e75e4c085076f9f55401e4e0d523d9b6969d.zip
add `Movie` and `Constants` class
-rw-r--r--src/com/oocpro/tmdbdesktop/Constants.java6
-rw-r--r--src/com/oocpro/tmdbdesktop/Main.java13
-rw-r--r--src/com/oocpro/tmdbdesktop/Tmdb/Movie.java47
3 files changed, 66 insertions, 0 deletions
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..d612e0d
--- /dev/null
+++ b/src/com/oocpro/tmdbdesktop/Main.java
@@ -0,0 +1,13 @@
+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);
+ System.out.println(ring.genres);
+ }
+}
+
diff --git a/src/com/oocpro/tmdbdesktop/Tmdb/Movie.java b/src/com/oocpro/tmdbdesktop/Tmdb/Movie.java
new file mode 100644
index 0000000..f1eb198
--- /dev/null
+++ b/src/com/oocpro/tmdbdesktop/Tmdb/Movie.java
@@ -0,0 +1,47 @@
+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");
+ }
+
+ // String s_url=a_url+"search/movie?api_key="+api_key+"&query=%s";
+ // String url=String.format(s_url,"CARS");
+ // URL us1 = new URL(url);
+ // InputStream sres = (InputStream)us1.getContent();
+ // JSONArray ja = new JSONArray(new JSONTokener(sres));
+ // System.out.println(ja.toString(4));
+}
+