Animarr/web/show.php

183 lines
6.7 KiB
PHP
Executable file

<?php
include "common.php";
use Animarr\Release\Release;
use Animarr\Torrent\Torrent;
$aid = 0;
if(isset($_GET["aid"])){
$aid = intval($_GET["aid"]);
}
$info = $aniDB->getAnime($aid);
if($info === null){
header("Location: index.php");
die();
}
$data = $database->getTrackInfo($aid);
$xml = new \SimpleXMLElement($aniDB->getAnimeAPI($aid, true, (isset($_GET["refresh"]) and $_GET["refresh"] == true) ? true : false));
$imgUrl = "https://img7.anidb.net/pics/anime/" . strval($xml->picture);
printHeader($info["title"]);
echo "<table>";
echo "<tr><td><img src=\"$imgUrl\" width=240/></td><td style=\"padding-left: 20px;\">";
echo "<h1>".$info["title"]." <a href=\"https://anidb.net/perl-bin/animedb.pl?show=anime&aid=$aid\" target=\"_blank\">[anidb-$aid]</a></h1>";
echo "<h2>".strval($xml->type)." (".strval($xml->startdate)."), ".$data["episode_count"]."/".$xml->episodecount." episodes</h2>";
echo "<p><div class=\"btn-group\" role=\"group\">";
echo "<a href=\"groups.php?aid=$aid\" type=\"button\" class=\"btn btn-info\">
<span class=\"glyphicon glyphicon-user\" aria-hidden=\"true\"></span> Groups
</a>";
echo " <a href=\"list.php?aid=$aid&specials=1\" type=\"button\" class=\"btn btn-info\">
<span class=\"glyphicon glyphicon-plus\" aria-hidden=\"true\"></span> Specials
</a>";
echo " <a href=\"add.php?aid=$aid&simple=1\" type=\"button\" class=\"btn btn-default\">
<span class=\"glyphicon glyphicon-search\" aria-hidden=\"true\"></span> Force search
</a>";
echo " <a href=\"add.php?aid=$aid\" type=\"button\" class=\"btn btn-warning\">
<span class=\"glyphicon glyphicon-refresh\" aria-hidden=\"true\"></span> Force refresh
</a>";
echo " <a href=\"show.php?aid=$aid&refresh=1\" type=\"button\" class=\"btn btn-default\">
<span class=\"glyphicon glyphicon-refresh\" aria-hidden=\"true\"></span> Fetch metadata
</a>";
echo " <a href=\"titles.php?aid=$aid\" type=\"button\" class=\"btn btn-default\">
<span class=\"glyphicon glyphicon-tag\" aria-hidden=\"true\"></span> Titles
</a>";
echo "</div>";
echo " <a href=\"del.php?aid=$aid\" type=\"button\" class=\"btn btn-danger\">
<span class=\"glyphicon glyphicon-remove\" aria-hidden=\"true\"></span> Stop tracking
</a>";
echo "</p><p>";
echo "<pre>".$database->getTrackFolder($aid)."</pre>";
echo "</p>";
echo "</td></tr>";
echo "</table><br/><br/>";
echo "<table class=\"table table-striped table-hover\">";
echo "<tr><th>Episode #</th><th>Group</th><th>Source</th><th>Quality</th><th style='min-width: 60%;'>Name</th><th>Info</th><th>Date</th><th>Expected Date</th></tr>";
function getTimeDiff($diff){
$hour = 3600;
$day = $hour * 24;
$week = $day * 7;
$date = "";
if($diff >= $week){
$weeks = floor($diff / $week);
$date .= "{$weeks}w ";
$diff -= $weeks * $week;
}
if($diff >= $day){
$days = floor($diff / $day);
$date .= "{$days}d ";
$diff -= $days * $day;
}
if($diff >= $hour){
$hours = floor($diff / $hour);
$date .= "{$hours}h ";
$diff -= $hours * $hour;
}
$date .= floor($diff / 60) . "m ago";
return $date;
}
function getEpisode(\SimpleXMLElement $xml, $number, $type = 1){
if(isset($xml->episodes)){
foreach ($xml->episodes->episode as $ep){
if(strval($ep->epno->attributes()["type"]) == $type and strval($ep->epno) == $number){
$d = [
"episode" => strval($ep->epno),
"airs" => strval($ep->airdate),
"titles" => [],
"duration" => strval($ep->length),
];
foreach ($ep->title as $t){
$d["titles"][] = $tt = ["lang" => $lang = strval($t->attributes("http://www.w3.org/XML/1998/namespace")["lang"]), "title" => strval($t)];
if($lang === "en"){
$d["titles"]["main"] = $tt;
}else if($lang === "x-jat" and !isset($d["titles"]["main"])){
$d["titles"]["main"] = $tt;
}
}
if(!isset($d["titles"]["main"])){
$d["titles"]["main"] = reset($d["titles"]);
}
return $d;
}
}
}
return null;
}
$lastN = 0;
foreach($database->getTrackEpisodes($aid) as $release){
for($n = $lastN + 1; $n < $release->getNumber(); ++$n){
$ep = getEpisode($xml, $n);
echo "<tr><td>$n</td><td></td><td></td><td></td><td>MISSING - ".$ep["titles"]["main"]["title"]."</td><td></td><td></td><td>".$ep["airs"]."</td></tr>";
}
$ep = getEpisode($xml, $release->getNumber());
$group = $release->getGroup();
if($release->isTrusted()){
$group = "<span class=\"label label-success\">$group</span>";
}else{
$group = "<span class=\"label label-default\">$group</span>";
}
$source = $release->getSourceString();
if($release->getSource() === Release::SOURCE_BLURAY){
$source = "<span class=\"label label-primary\">$source</span>";
}elseif($release->getSource() === Release::SOURCE_DVD){
$source = "<span class=\"label label-success\">$source</span>";
}elseif($release->getSource() === Release::SOURCE_TV){
$source = "<span class=\"label label-info\">$source</span>";
}else{
$source = "<span class=\"label label-default\">$source</span>";
}
$quality = $release->getQualityString();
if($release->getQuality() === Release::QUALITY_1080){
$quality = "<span class=\"label label-primary\">$quality</span>";
}elseif($release->getQuality() === Release::QUALITY_720){
$quality = "<span class=\"label label-success\">$quality</span>";
}else{
$quality = "<span class=\"label label-default\">$quality</span>";
}
$diff = time() - $release->getUploadDate();
$date = getTimeDiff($diff);
$url = $release->getInfoLink();
$urlName = getURLName($url);
echo "<tr class=\"".($release->isBest() ? "info" : ($release->isTrusted() ? "success" : ""))."\"><td>".$release->getNumber()."</td><td>$group</td><td>$source</td><td>$quality</td><td>".$ep["titles"]["main"]["title"]."<br/><code>".$release->getOriginalTitle()."</code>&nbsp;<a href=\"release.php?release_id=".$release->getId()."&episode=".$release->getNumber()."\"><span class=\"glyphicon glyphicon-info-sign\"></span></a></td><td><a href=\"".$url."\" target=\"_blank\">".$urlName."</a></td><td>$date</td><td>".$ep["airs"]."</td></tr>";
$lastN = $release->getNumber();
}
for($n = $lastN + 1; $n <= (int) $xml->episodecount; ++$n){
$ep = getEpisode($xml, $n);
if($ep === null){
echo "<tr><td>$n</td><td></td><td></td><td></td><td>UNAIRED</td><td></td><td></td><td>-</td></tr>";
}else{
echo "<tr><td>$n</td><td></td><td></td><td></td><td>UNAIRED - ".$ep["titles"]["main"]["title"]."</td><td></td><td></td><td>".$ep["airs"]."</td></tr>";
}
}
echo "</table>";
printFooter();