-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.html
145 lines (137 loc) · 8.22 KB
/
api.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html>
<head>
<title>PlexRecs</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<style>
#code {
width: 100%;
height: 90vh;
}
</style>
</head>
<body>
<textarea id="code"></textarea>
<script>
var xmlhttp = new XMLHttpRequest();
var url = "movies.json";
var myArr;
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
myArr = JSON.parse(xmlhttp.responseText);
catlist(myArr);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
var json = "";
function catlist(arr) {
var out = "";
i = 0;
j = 0;
function request(i, j) {
if(!arr.categories[i].movies[j].name == ""){
if (arr.categories[i].movies[j].poster == "") {
var nospaces = arr.categories[i].movies[j].name.replace(/\s+/g, '_');
var nodashes = nospaces.replace('-', '_');
arr.categories[i].movies[j].poster = nodashes.replace(/\W/g, '').toLowerCase() + '.jpg';
console.log("poster for " + arr.categories[i].movies[j].name + " in category '" + arr.categories[i].name + "' set to " + arr.categories[i].movies[j].poster);
}
if (!arr.categories[i].movies[j].link.startsWith('tt')){
jQuery.ajax({
url: 'https://crossorigin.me/http://www.imdb.com/xml/find?json=1&nr=1&tt=on&q=' + arr.categories[i].movies[j].name,
dataType: 'json'
}).done(function (result) {
console.log(i);
console.log(j);
if(!arr.categories[i].movies[j].year || arr.categories[i].movies[j].year == ''){
if(result.title_popular) {
arr.categories[i].movies[j].year = parseInt(result.title_popular[0].title_description.substring(0, 4));
console.log("year for " + arr.categories[i].movies[j].name + " in category '" + arr.categories[i].name + "' set to " + arr.categories[i].movies[j].year);
} else if(result.title_exact) {
arr.categories[i].movies[j].year = parseInt(result.title_exact[0].title_description.substring(0, 4));
console.log("year for " + arr.categories[i].movies[j].name + " in category '" + arr.categories[i].name + "' set to " + arr.categories[i].movies[j].year);
}
}
if(result.title_popular) {
if (arr.categories[i].movies[j].year == result.title_popular[0].title_description.substring(0, 4)){
arr.categories[i].movies[j].link = result.title_popular[0].id;
} else {
arr.categories[i].movies[j].link = "COULD_NOT_FIND_CORRECT_IMDB_ID_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
}
} else if(result.title_exact) {
if(arr.categories[i].movies[j].year == result.title_exact[0].title_description.substring(0, 4)){
arr.categories[i].movies[j].link = result.title_exact[0].id;
} else {
arr.categories[i].movies[j].link = "COULD_NOT_FIND_CORRECT_IMDB_ID_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
}
} else if(result.title_approx) {
if(arr.categories[i].movies[j].year == result.title_approx[0].title_description.substring(0, 4)){
arr.categories[i].movies[j].link = result.title_approx[0].id;
} else {
arr.categories[i].movies[j].link = "COULD_NOT_FIND_CORRECT_IMDB_ID_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
}
} else {
arr.categories[i].movies[j].link = "COULD_NOT_FIND_CORRECT_IMDB_ID_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
}
if(i == arr.categories.length - 1 && j == arr.categories[i].movies.length - 1){
//window.open("data:text/json," + encodeURIComponent(JSON.stringify(arr, null, 4)), "_blank");
$('#code').text(JSON.stringify(arr, null, 4));
$('#code').select();
//console.log(JSON.stringify(arr, null, 4));
} else {
if(j == arr.categories[i].movies.length - 1) {
i++;
j = 0;
request(i, j);
} else {
j++;
request(i, j);
}
}
}).fail(function (err) {
$('#code').text(JSON.stringify(arr, null, 4));
$('#code').select();
//window.open("data:text/json," + encodeURIComponent(JSON.stringify(arr, null, 4)), "_blank");
//console.log(JSON.stringify(arr, null, 4));
});
} else {
if(i == arr.categories.length - 1 && j == arr.categories[i].movies.length - 1){
$('#code').text(JSON.stringify(arr, null, 4));
$('#code').select();
//window.open("data:text/json," + encodeURIComponent(JSON.stringify(arr, null, 4)), "_blank");
//console.log(JSON.stringify(arr, null, 4));
} else {
if(j == arr.categories[i].movies.length - 1) {
i++;
j = 0;
request(i, j);
} else {
j++;
request(i, j);
}
}
}
} else {
if(i == arr.categories.length - 1 && j == arr.categories[i].movies.length - 1){
$('#code').text(JSON.stringify(arr, null, 4));
$('#code').select();
//window.open("data:text/json," + encodeURIComponent(JSON.stringify(arr, null, 4)), "_blank");
//console.log(JSON.stringify(arr, null, 4));
} else {
if(j == arr.categories[i].movies.length - 1) {
i++;
j = 0;
request(i, j);
} else {
j++;
request(i, j);
}
}
}
}
request(i, j);
}
</script>
</body>
</html>