forked from bendodson/itunes-artwork-finder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
itunes.js
284 lines (257 loc) · 7.29 KB
/
itunes.js
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
//<![CDATA[
var pathToAPI = 'https://services.thwaller.com/api/mb-itunes-api.php';
var countries = {
ae: 'United Arab Emirates',
ag: 'Antigua and Barbuda',
ai: 'Anguilla',
al: 'Albania',
am: 'Armenia',
ao: 'Angola',
ar: 'Argentina',
at: 'Austria',
au: 'Australia',
az: 'Azerbaijan',
bb: 'Barbados',
be: 'Belgium',
bf: 'Burkina-Faso',
bg: 'Bulgaria',
bh: 'Bahrain',
bj: 'Benin',
bm: 'Bermuda',
bn: 'Brunei Darussalam',
bo: 'Bolivia',
br: 'Brazil',
bs: 'Bahamas',
bt: 'Bhutan',
bw: 'Botswana',
by: 'Belarus',
bz: 'Belize',
ca: 'Canada',
cg: 'Democratic Republic of the Congo',
ch: 'Switzerland',
cl: 'Chile',
cn: 'China',
co: 'Colombia',
cr: 'Costa Rica',
cv: 'Cape Verde',
cy: 'Cyprus',
cz: 'Czech Republic',
de: 'Germany',
dk: 'Denmark',
dm: 'Dominica',
do: 'Dominican Republic',
dz: 'Algeria',
ec: 'Ecuador',
ee: 'Estonia',
eg: 'Egypt',
es: 'Spain',
fi: 'Finland',
fj: 'Fiji',
fm: 'Federated States of Micronesia',
fr: 'France',
gb: 'United Kingdom',
gd: 'Grenada',
gh: 'Ghana',
gm: 'Gambia',
gr: 'Greece',
gt: 'Guatemala',
gw: 'Guinea Bissau',
gy: 'Guyana',
hk: 'Hong Kong',
hn: 'Honduras',
hr: 'Croatia',
hu: 'Hungary',
id: 'Indonesia',
ie: 'Ireland',
il: 'Israel',
in: 'India',
is: 'Iceland',
it: 'Italy',
jm: 'Jamaica',
jo: 'Jordan',
jp: 'Japan',
ke: 'Kenya',
kg: 'Krygyzstan',
kh: 'Cambodia',
kn: 'Saint Kitts and Nevis',
kr: 'South Korea',
kw: 'Kuwait',
ky: 'Cayman Islands',
kz: 'Kazakhstan',
la: 'Laos',
lb: 'Lebanon',
lc: 'Saint Lucia',
lk: 'Sri Lanka',
lr: 'Liberia',
lt: 'Lithuania',
lu: 'Luxembourg',
lv: 'Latvia',
md: 'Moldova',
mg: 'Madagascar',
mk: 'Macedonia',
ml: 'Mali',
mn: 'Mongolia',
mo: 'Macau',
mr: 'Mauritania',
ms: 'Montserrat',
mt: 'Malta',
mu: 'Mauritius',
mw: 'Malawi',
mx: 'Mexico',
my: 'Malaysia',
mz: 'Mozambique',
na: 'Namibia',
ne: 'Niger',
ng: 'Nigeria',
ni: 'Nicaragua',
nl: 'Netherlands',
np: 'Nepal',
no: 'Norway',
nz: 'New Zealand',
om: 'Oman',
pa: 'Panama',
pe: 'Peru',
pg: 'Papua New Guinea',
ph: 'Philippines',
pk: 'Pakistan',
pl: 'Poland',
pt: 'Portugal',
pw: 'Palau',
py: 'Paraguay',
qa: 'Qatar',
ro: 'Romania',
ru: 'Russia',
sa: 'Saudi Arabia',
sb: 'Soloman Islands',
sc: 'Seychelles',
se: 'Sweden',
sg: 'Singapore',
si: 'Slovenia',
sk: 'Slovakia',
sl: 'Sierra Leone',
sn: 'Senegal',
sr: 'Suriname',
st: 'Sao Tome e Principe',
sv: 'El Salvador',
sz: 'Swaziland',
tc: 'Turks and Caicos Islands',
td: 'Chad',
th: 'Thailand',
tj: 'Tajikistan',
tm: 'Turkmenistan',
tn: 'Tunisia',
tr: 'Turkey',
tt: 'Republic of Trinidad and Tobago',
tw: 'Taiwan',
tz: 'Tanzania',
ua: 'Ukraine',
ug: 'Uganda',
us: 'United States of America',
uy: 'Uruguay',
uz: 'Uzbekistan',
vc: 'Saint Vincent and the Grenadines',
ve: 'Venezuela',
vg: 'British Virgin Islands',
vn: 'Vietnam',
ye: 'Yemen',
za: 'South Africa',
zw: 'Zimbabwe'
}
function getSearchParameters() {
var prmstr = window.location.search.substr(1);
return prmstr != null && prmstr != "" ? transformToAssocArray(prmstr) : {};
}
function transformToAssocArray( prmstr ) {
var params = {};
var prmarr = prmstr.split("&");
for ( var i = 0; i < prmarr.length; i++) {
var tmparr = prmarr[i].split("=");
params[tmparr[0]] = decodeURIComponent(tmparr[1]);
}
return params;
}
function performSearch() {
$('#results').html('');
$('#results').append('<h3>Searching...</h3>');
var query = $('#query').val();
if (!query.length) {
return false;
};
var entity = ($('#entity').val()) ? $('#entity').val() : 'tvSeason';
var country = ($('#country').val()) ? $('#country').val() : 'us';
$.ajax({
type: "GET",
crossDomain: true,
url: pathToAPI,
data: {query: query, entity: entity, country: country, type: 'request'},
dataType: 'json'
}).done(function(data) {
$.ajax({
type: "GET",
crossDomain: true,
url: data.url,
data: {},
dataType: 'jsonp'
}).done(function(data) {
console.log(data);
$.ajax({
type: "POST",
crossDomain: true,
url: pathToAPI,
data: {json: JSON.stringify(data), type: 'data', entity: entity},
dataType: 'json'
}).done(function(data) {
$('#results').html('');
if (data.error) {
$('#results').append('<h3>'+data.error+'</h3>');
} else {
if (!data.length) {
$('#results').append('<h3>No results found.</h3>');
} else {
for (var i = 0; i < data.length; i++) {
var result = data[i];
console.log(result.title);
var html = '<div><h3>'+result.title+'</h3>';
if (entity != 'software' && entity != 'iPadSoftware' && entity != 'macSoftware') {
html += '<p><a href="'+result.url+'" target="_blank">Standard Resolution</a> | <a href="'+result.hires+'" target="_blank">High Resolution</a> <em><small>'+result.warning+'</small></em></p>';
} else if (entity == 'software' || entity == 'iPadSoftware') {
html += '<p><a href="./app/?url='+encodeURIComponent(result.appstore)+'&country='+country+'" target="_blank">View screenshots / videos</a></p>';
}
html += '<a href="'+result.url+'" target="_blank"><img src="'+result.url+'" alt="iTunes Artwork for \''+result.title+'\'" width="'+result.width+'" height="'+result.height+'"></a>';
html += '</div>';
$('#results').append(html);
};
}
}
$('#results').append('<p>If the item you are searching for is not available on iTunes, this tool will not find it.</p>');
});
});
});
}
$(document).ready(function() {
var sortable = [];
for (var key in countries) {
sortable.push([key, countries[key]]);
}
sortable.sort(function(a, b) {
if(a[1] < b[1]) return 1;
if(a[1] > b[1]) return -1;
return 0;
});
for (var i = sortable.length - 1; i >= 0; i--) {
var array = sortable[i];
$('#country').append('<option value="'+array[0]+'">'+array[1]+'</option>');
};
var params = getSearchParameters();
if (params.entity && params.query && params.country) {
$('#query').val(params.query);
$('#entity').val(params.entity);
$('#country').val(params.country);
performSearch();
};
$('#iTunesSearch').submit(function() {
performSearch();
return false;
});
});
//]]>