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 toJson($content, $programId)
- {
- $find = 'MoreView.init(' . $programId . ', ';
- $start = strpos($content, $find);
- if ($start === false) {
- throw new Exception("Can't find json data start point.");
- }
- $start += strlen($find);
- $end = strpos($content, ']);', $start);
- if ($end === false) {
- throw new Exception("Can't find json data end point.");
- }
- $moreView = substr($content, $start, $end - $start + 1);
- return json_decode($moreView, true);
- }
- function getJson($content, $programId)
- {
- $data = toJson($content, $programId);
- $result = [];
- $normal_episodes = 0;
- $special_eposodes = 0;
- $old_name = '';
- for ($i = count($data); $i != 0; ) {
- --$i;
- $item = $data[$i];
- $name = trim($item['name']);
- if (empty($name) or $name == $old_name) {
- $seasons = '0';
- $episodes = (string)(++$special_eposodes);
- } else {
- $seasons = '1';
- $episodes = (string)(++$normal_episodes);
- }
- $old_name = $name;
- $title = trim($item['title']);
- $replace_search = ["\r\n", "\n\n", '<br>', '<BR>', '!|'];
- $summary = trim(str_replace($replace_search, "\n", $item['introduceDescription']));
- $lines = [];
- foreach (explode("\n", $summary) as $line) {
- $line = trim($line);
- if (empty($line)) {
- continue;
- }
- $lines[] = $line;
- }
- $summary = implode("\n", $lines);
- $originallyAvailableAt = null;
- foreach ($item['channels'] as $channel) {
- if (array_key_exists('broadcastDate', $channel) and strlen($channel['broadcastDate']) == 8) {
- $originallyAvailableAt = $channel['broadcastDate'];
- break;
- }
- }
- $rating = (float)$item['rate'];
- $result[] = [
- 'seasons' => $seasons,
- 'episodes' => $episodes,
- 'title' => $title,
- 'summary' => $summary,
- 'originally_available_at' => $originallyAvailableAt,
- 'rating' => $rating,
- ];
- }
- return $result;
- }
- function main($programId)
- {
- try {
- $content = curl('https://movie.daum.net/tv/episode?tvProgramId=' . $programId);
- $json = [
- 'data' => getJson($content, $programId),
- ];
- } 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