-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenName_namer.java
More file actions
55 lines (46 loc) · 1.86 KB
/
OpenName_namer.java
File metadata and controls
55 lines (46 loc) · 1.86 KB
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
53
54
55
import java.util.HashMap;
import java.net.*;
import java.io.UnsupportedEncodingException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
/**
* @author Noah Phillips
* @version 1.00
* @see https://github.com/phillipsnoah/OpenName
* The namer is what we use to parse JSON using Google's GSON, gather the metadata for that content, and store it.
* The namer can be used in a loop for batch editing as well.
*/
public class OpenName_namer {
HashMap<String, String> metaMap = new HashMap<String, String>();
String toSearch;
String url = "https://imdb-api.com/API/Search/";
String charset = "UTF-8";
String apiKey = "k_jsht09u1"; //"INSERT_IMDB_APIKEY_HERE";
public OpenName_namer(String titleName){
toSearch = titleName;
}
public static void Main(String[] args){
}
public void getRequest(){
try{
String query = String.format("apiKey=%s&toSearch=%s",
URLEncoder.encode(apiKey, charset),
URLEncoder.encode(toSearch, charset));
URLConnection connection = new URL(url + "?" + query).openConnection();
connection.setRequestProperty("Accept-Charset", charset);
InputStream response = connection.getInputStream();
// if we make it here, we got a response and no errors.
try (Scanner scanner = new Scanner(response)) {
String responseBody = scanner.useDelimiter("\\A").next();
System.out.println(responseBody);
}catch (Exception e) {
System.out.println("Ooops!" + e);
}
} catch (UnsupportedEncodingException Error) {
System.out.println("Error!: " + Error);
} catch (IOException e) {
System.out.println("Error!: " + e);
}
}
}