112 lines
2.9 KiB
PHP
112 lines
2.9 KiB
PHP
<?php
|
|
|
|
include "common.php";
|
|
|
|
$mal = \Animarr\Request::getURL("https://myanimelist.net/topanime.php?type=airing");
|
|
$adb = \Animarr\Request::getURL("https://anidb.net/perl-bin/animedb.pl?show=animelist&type.tvseries=1&orderby.rating=0.2&orderby.name=1.1&noalias=1&h=1&airing=1");
|
|
|
|
$top = [];
|
|
|
|
|
|
$dom = new \DOMDocument();
|
|
@$dom->loadHTML($mal);
|
|
|
|
$xpath = new \DOMXPath($dom);
|
|
$entries = $xpath->query("//tr[contains(concat(' ', normalize-space(@class), ' '), ' ranking-list ')]");
|
|
foreach($entries as $entry){
|
|
$name = trim((string) $entry->getElementsByTagName("td")->item(1)->getElementsByTagName("div")->item(0)->getElementsByTagName("div")->item(2)->getElementsByTagName("a")->item(0)->textContent);
|
|
$score = (float) trim((string) $entry->getElementsByTagName("td")->item(2)->textContent);
|
|
|
|
$match = $aniDB->matchTitle($name);
|
|
if($match === null){
|
|
$link = "add.php?showName=". urlencode($name);
|
|
$id = $name;
|
|
}else{
|
|
$name = $match["title"];
|
|
$link = "add.php?aid=". $match["aid"];
|
|
|
|
if($database->isTracking($match["aid"])){
|
|
$link = "";
|
|
}
|
|
$id = $match["aid"];
|
|
}
|
|
|
|
if(isset($top[$id])){
|
|
$top[$id]["scores"][] = $score;
|
|
}else{
|
|
$top[$id] = [
|
|
"name" => $name,
|
|
"link" => $link,
|
|
"scores" => [$score],
|
|
];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$dom = new \DOMDocument();
|
|
@$dom->loadHTML($adb);
|
|
|
|
|
|
foreach($dom->getElementById("animelist")->getElementsByTagName("tr") as $entry){
|
|
if($entry === null or $entry->getAttribute("class") == "header"){
|
|
continue;
|
|
}
|
|
$name = trim((string) $entry->getElementsByTagName("td")->item(2)->getElementsByTagName("a")->item(0)->textContent);
|
|
$score = trim((string) $entry->getElementsByTagName("td")->item(6)->textContent);
|
|
$score = substr($score, 0, strpos($score, " ("));
|
|
|
|
$match = $aniDB->matchTitle($name);
|
|
if($match === null){
|
|
$link = "add.php?showName=". urlencode($name);
|
|
$id = $name;
|
|
}else{
|
|
$name = $match["title"];
|
|
$link = "add.php?aid=". $match["aid"];
|
|
|
|
if($database->isTracking($match["aid"])){
|
|
$link = "";
|
|
}
|
|
$id = $match["aid"];
|
|
}
|
|
|
|
if(isset($top[$id])){
|
|
$top[$id]["scores"][] = $score;
|
|
}else{
|
|
$top[$id] = [
|
|
"name" => $name,
|
|
"link" => $link,
|
|
"scores" => [$score],
|
|
];
|
|
}
|
|
}
|
|
|
|
uasort($top, function($a, $b){
|
|
$scorea = array_sum($a["scores"]) / count($a["scores"]);
|
|
$scoreb = array_sum($b["scores"]) / count($b["scores"]);
|
|
|
|
if($scorea === $scoreb){
|
|
return 0;
|
|
}
|
|
|
|
return ($scorea > $scoreb) ? -1 : 1;
|
|
});
|
|
|
|
printHeader("Top Airing");
|
|
|
|
echo "<h1>Top Airing</h1>";
|
|
|
|
echo "<table class=\"table table-striped table-hover\">";
|
|
|
|
|
|
echo "<tr><th>Show Name</th><th>Score</th><th>Actions</th></tr>";
|
|
|
|
foreach($top as $id => $data){
|
|
$action = $data["link"] != "" ? "<a href=\"".$data["link"]."\"><span class=\"glyphicon glyphicon-plus\"></span></a>" : "<i>Tracked</i>";
|
|
echo "<tr><td>".$data["name"]."</td><td>".round(array_sum($data["scores"]) / count($data["scores"]), 2)."</td><td>$action</td></tr>";
|
|
}
|
|
|
|
echo "</table>";
|
|
|
|
printFooter();
|