-
Notifications
You must be signed in to change notification settings - Fork 3
/
anime-details.php
113 lines (78 loc) · 3.14 KB
/
anime-details.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
<?php
use voku\helper\HtmlDomParser;
require_once 'composer/vendor/autoload.php';
require_once 'config.php';
require_once 'functions.php';
if (!isset($_REQUEST['id'])) {
sendErrorResponse("No anime id is provided..");
}
$anime_id = trim($_REQUEST['id']);
if($anime_id == "") {
sendErrorResponse("Invalid anime id.");
}
$gogo_request_url = $gogourl . "/category/" . $anime_id;
$html = getHtmlFromUrl($gogo_request_url);
$dom = HtmlDomParser::str_get_html($html);
$episodes = array();
$anime_info_body = $dom->findOne('.anime_info_body');
$thumbnail = $anime_info_body->findOne("img")->getAttribute("src");
$anime_name = $anime_info_body->findOne("h1")->text();
$plot = $anime_info_body->findOne(".description")->text();
$anime_type ="";
$genres = "";
$release_date = "";
$status = "";
$other_names = "";
$types = $anime_info_body->findMulti(".type");
foreach ($types as $type) {
if (strpos(strtolower($type->text()), "type:") !== false) {
$anime_type = trim(str_replace("Type:", "", $type->text()));
}
if (strpos(strtolower($type->text()), "genre:") !== false) {
$genres = trim(str_replace("genre:", "", strtolower($type->text())));
}
if (strpos(strtolower($type->text()), "released:") !== false) {
$release_date = trim(str_replace("released:", "", strtolower($type->text())));
}
if (strpos(strtolower($type->text()), "status:") !== false) {
$status = trim(str_replace("status:", "", strtolower($type->text())));
}
if (strpos(strtolower($type->text()), "other name:") !== false) {
$other_names = trim(str_replace("Other name:", "", $type->text()));
}
}
$li_tags = $dom->findOne("#episode_page")->findMulti("li");
if (count($li_tags) > 0) {
$last_li = $li_tags[count($li_tags) -1];
$last_episode_num = $last_li->findOne("a")->getAttribute("ep_end");
$movie_id = $dom->findOne("#movie_id")->getAttribute("value");
$gogo_ajax_episodes_url = $gogo_ajax_url . "/load-list-episode?default_ep=0&ep_start=0&ep_end=" . $last_episode_num . "&alias=" . $anime_id . "&id=" . $movie_id;
$episodes_page_html = getHtmlFromUrl($gogo_ajax_episodes_url);
$ep_dom = HtmlDomParser::str_get_html($episodes_page_html);
$a_tags = $ep_dom->findMulti("a");
foreach ($a_tags as $a) {
$episode_id = trim($a->getAttribute("href"));
if ($episode_id[0] === '/') {
$episode_id = substr($episode_id, 1);
}
$episode_number = trim(str_replace("\"", "", str_replace("ep", "", strtolower($a->findOne(".name")->text()))));
$episodes[] = array(
"episodeId" => $episode_id,
"episodeNum" => $episode_number
);
}
$anime_info = array(
"animeTitle" => $anime_name,
"animeImg" => $thumbnail,
"type" => $anime_type,
"releasedDate" => $release_date,
"status" => ucwords($status),
"genres" => $genres,
"synopsis" => $plot,
"otherNames" => $other_names,
"totalEpisodes" => count($episodes),
"episodesList" => array_reverse($episodes)
);
header('Content-Type: application/json');
echo json_encode($anime_info);
}