src/com/oocpro/tmdbdesktop/tmdb/Movie.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.oocpro.tmdbdesktop.tmdb; import com.oocpro.tmdbdesktop.Constants; import java.awt.image.BufferedImage; import java.io.InputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.imageio.ImageIO; 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 BufferedImage poster; 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)); String poster_url = Constants.IURL500 + movie.getString("poster_path"); poster = ImageIO.read(new URL(poster_url)); genres = new ArrayList<String>(); Iterator genres_itr = movie.getJSONArray("genres").iterator(); // iterate through each genre and add it's `name` to the `genres` list 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"); } }