-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathapi.php
128 lines (110 loc) · 3.37 KB
/
api.php
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
<?php
header("Access-Control-Allow-Origin: *");
if (isset($_GET['type']) && $_GET['type'] == 'request') {
$search = $_GET['query'];
if ($search) {
$entity = ($_GET['entity']) ? $_GET['entity'] : 'tvSeason';
$country = ($_GET['country']) ? $_GET['country'] : 'us';
$width = 600;
$height = 600;
$shortFilm = false;
if ($entity == 'shortFilm') {
$shortFilm = true;
$entity = 'movie';
}
$url = 'https://itunes.apple.com/search?term='.urlencode($search).'&country='.$country.'&entity='.$entity;
if ($shortFilm) {
$url .= '&attribute=shortFilmTerm';
$entity = 'shortFilm';
}
if ($_GET['entity'] == 'id' || $_GET['entity'] == 'idAlbum') {
$url = 'https://itunes.apple.com/lookup?id='.urlencode($search).'&country='.$_GET['country'];
}
$url .= '&limit=25';
echo json_encode(["url" => $url]);
exit;
}
}
if (isset($_POST['type']) && $_POST['type'] == 'data') {
$output = array();
$json = json_decode($_POST['json']);
$entity = ($_POST['entity']) ? $_POST['entity'] : 'tvSeason';
foreach ($json->results as $result) {
if (($_POST['entity'] == 'id' && $result->kind != 'feature-movie') && ($_POST['entity'] == 'id' && $result->wrapperType != 'collection')) {
continue;
}
if ($_POST['entity'] == 'idAlbum' && $result->collectionType != 'Album') {
continue;
}
$width = 600;
$height = 600;
$data = array();
$data['url'] = str_replace('100x100', '600x600', $result->artworkUrl100);
$hires = str_replace('100x100bb', '100000x100000-999', $result->artworkUrl100);
$parts = parse_url($hires);
$hires = 'https://is5-ssl.mzstatic.com'.$parts['path'];
$data['hires'] = $hires;
$data['title'] = ($entity == 'movie') ? $result->trackName : $result->collectionName;
if ($_POST['entity'] == 'album' || $_POST['entity'] == 'idAlbum') {
$parts = explode('/image/thumb/', $hires);
if (count($parts) == 2) {
$parts = explode('/', $parts[1]);
array_pop($parts);
$data['uncompressed'] = 'https://a5.mzstatic.com/us/r1000/0/'.implode('/', $parts);
}
}
switch ($entity) {
case 'musicVideo':
$data['title'] = $result->trackName.' (by '.$result->artistName.')';
$data['url'] = $hires;
$width = 640;
$height = 464;
break;
case 'tvSeason':
$data['title'] = $result->collectionName;
break;
case 'movie':
case 'id':
case 'shortFilm':
$data['title'] = $result->trackName;
if (!$data['title']) {
$data['title'] = $result->collectionName;
}
$width = 400;
break;
case 'ebook':
$data['title'] = $result->trackName.' (by '.$result->artistName.')';
$width = 400;
break;
case 'album':
case 'idAlbum':
$data['title'] = $result->collectionName.' (by '.$result->artistName.')';
break;
case 'audiobook':
$data['title'] = $result->collectionName.' (by '.$result->artistName.')';
break;
case 'podcast':
$data['title'] = $result->collectionName.' (by '.$result->artistName.')';
break;
case 'software':
case 'iPadSoftware':
case 'macSoftware':
$data['url'] = str_replace('512x512bb', '1024x1024bb', $result->artworkUrl512);
$data['appstore'] = $result->trackViewUrl;
$data['title'] = $result->trackName;
$width = 512;
$height = 512;
break;
default:
break;
}
if ($data['title']) {
$data['width'] = $width;
$data['height'] = $height;
$output[] = $data;
}
}
echo json_encode($output);
exit;
}
?>