Merge branch 'master' of github.com:prithugoswami/tmdb-desktop-client
Prashant Jha prashant.kumarjha63@gmail.com
Wed, 01 May 2019 11:22:35 +0530
8 files changed,
75 insertions(+),
89 deletions(-)
M
README.md
→
README.md
@@ -2,3 +2,16 @@ # Simple TMDb Desktop Client
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
A
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"; +}
A
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); + } +} +
A
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"); + } +} +
D
test.java
@@ -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); - } - - } -}
D
testUI.java
@@ -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); - - } -} -
D
tmdb.java
@@ -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); - } - } -} - -