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 getPageData($url, &$result)
- {
- $content = curl($url);
- $json = json_decode($content, true);
- foreach ($json['data'] as $item) {
- $year = $item['prodYear'];
- $id = $item['movieId'];
- $title = strip_tags($item['titleKo']);
- $result[] = [
- 'year' => (string)$year,
- 'id' => (string)$id,
- 'title' => $title,
- ];
- }
- return $json;
- }
- function getJson($mediaName)
- {
- $result = [];
- $url = 'http://movie.daum.net/data/movie/search/v2/movie.json?size=20&start=1&searchText=' . urlencode($mediaName);
- $json = getPageData($url, $result);
- $last_page = $json['page']['last'];
- for ($page = 2; $page <= $last_page; ++$page) {
- $prev_page = $page - 1;
- $url = str_replace('&start=' . $prev_page, '&start=' . $page, $url);
- getPageData($url, $result);
- }
- return $result;
- }
- function main($mediaName)
- {
- try {
- $json = [
- 'data' => getJson($mediaName),
- ];
- } 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('name', $_GET) ? $_GET['name'] : '');
Add Comment
Please, Sign In to add comment