Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function curl($url)
- {
- $ua = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36';
- $curl = curl_init($url);
- curl_setopt($curl, CURLOPT_USERAGENT, $ua);
- curl_setopt($curl, CURLOPT_FAILONERROR, true);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- $output = curl_exec($curl);
- curl_close($curl);
- return $output;
- }
- function getJson($content)
- {
- $result = [
- 'posters' => [],
- 'arts' => [],
- 'others' => [],
- ];
- $json = json_decode($content, true);
- if (empty($json['data'])) {
- throw new Exception("Can't find json data.");
- }
- foreach ($json['data'] as $item) {
- if (!array_key_exists('photoCategory', $item)) {
- continue;
- }
- $photoCategory = (int)$item['photoCategory'];
- if (array_key_exists('fullname', $item)) {
- $photo = $item['fullname'];
- } else if (array_key_exists('thumbnail', $item)) {
- $photo = $item['thumbnail'];
- } else {
- continue;
- }
- if ($photoCategory == 1) {
- $result['posters'][] = $photo;
- } else if ($photoCategory == 2 or $photoCategory == 50) {
- $result['arts'][] = $photo;
- } else {
- $result['others'][] = $photo;
- }
- }
- return $result;
- }
- function main($movieId)
- {
- try {
- $content = curl('http://movie.daum.net/data/movie/photo/movie/list.json?pageNo=1&pageSize=100&id=' . $movieId);
- $json = [
- 'data' => getJson($content),
- ];
- } catch (Exception $e) {
- $json = [
- 'error' => (string)$e,
- ];
- }
- header('Content-Type: application/json');
- $result = json_encode($json, JSON_UNESCAPED_UNICODE);
- echo $result;
- }
- main(array_key_exists('id', $_GET) ? (int)$_GET['id'] : 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement