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 = [
- 'roles' => [],
- 'directors' => [],
- 'producers' => [],
- 'writers' => [],
- ];
- $roleCount = [];
- $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('castcrew', $item)) {
- continue;
- }
- $cast = $item['castcrew'];
- if (!array_key_exists('castcrewCastName', $cast)) {
- continue;
- }
- $roleName = $cast['castcrewCastName'];
- if (array_key_exists('nameKo', $item)) {
- $castName = $item['nameKo'];
- } else if (array_key_exists('nameEn', $item)) {
- $castName = $item['nameEn'];
- } else {
- continue;
- }
- if (array_key_exists('photo', $item)) {
- if (array_key_exists('fullname', $item['photo'])) {
- $photo = $item['photo']['fullname'];
- } else {
- $photo = null;
- }
- } else {
- $photo = null;
- }
- $data = [
- 'name' => $castName,
- 'role' => $roleName,
- 'photo' => $photo,
- ];
- if (mb_strpos($roleName, '감독') !== false or mb_strpos($roleName, '연출') !== false) {
- $result['directors'][] = $data;
- } elseif (mb_strpos($roleName, '제작') !== false) {
- $result['producers'][] = $data;
- } elseif (mb_strpos($roleName, '극본') !== false or mb_strpos($roleName, '각본') !== false) {
- $result['writers'][] = $data;
- } elseif (mb_strpos($roleName, '주연') !== false or mb_strpos($roleName, '조연') !== false or mb_strpos($roleName, '출연') !== false or mb_strpos($roleName, '진행') !== false) {
- if (!array_key_exists('castcrewTitleKo', $cast)) {
- continue;
- }
- $role = $cast['castcrewTitleKo'];
- if (array_key_exists($role, $roleCount)) {
- $roleCount[$role] += 1;
- $data['role'] = $role . ' ' . $roleCount[$role];
- } else {
- $roleCount[$role] = 1;
- $data['role'] = $role;
- }
- $result['roles'][] = $data;
- } else {
- if (!array_key_exists('others')) {
- $result['others'] = [];
- }
- $result['others'][] = $data;
- }
- }
- return $result;
- }
- function main($movieId)
- {
- try {
- $content = curl('http://movie.daum.net/data/movie/movie_info/cast_crew.json?pageNo=1&pageSize=100&movieId=' . $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);
Add Comment
Please, Sign In to add comment