예제 #1
0
 function newEpisodes()
 {
     $html = "<h1>Demnächst</h1>";
     $AC = anyC::get("Folge");
     $AC->addAssocV3("UNIX_TIMESTAMP(STR_TO_DATE(airDate, '%Y-%m-%d')) + 120", ">=", mktime(0, 0, 1));
     $AC->addAssocV3("UNIX_TIMESTAMP(STR_TO_DATE(airDate, '%Y-%m-%d'))", "<=", time() + 3600 * 24 * 6);
     $AC->addAssocV3("RSSFilterID", ">", "0");
     $AC->addJoinV3("Serie", "SerieID", "=", "SerieID");
     $AC->addOrderV3("UNIX_TIMESTAMP(STR_TO_DATE(airDate, '%Y-%m-%d 18:00'))", "ASC");
     $i = 0;
     $lastAD = null;
     while ($S = $AC->getNextEntry()) {
         if ($lastAD != $S->A("airDate")) {
             if ($lastAD !== null) {
                 $html .= "</div>";
             }
             $date = strtotime($S->A("airDate"));
             $html .= "<div class=\"comingUp\" style=\"box-sizing:border-box;" . ($i % 2 == 0 ? "background-color: #F2F2F2;" : "") . "padding:10px;display:inline-block;width:calc(100% / 7);vertical-align:top;\"><h2 style=\"margin-top:0;padding-top:0;\">" . mb_substr(Util::CLWeekdayName(date("w", $date)), 0, 2) . ", " . Util::CLDateParser($date) . "</h2>";
             $i++;
         }
         $html .= $S->A("name") . " <span style=\"color:grey;\">S" . ($S->A("season") < 10 ? "0" : "") . $S->A("season") . "E" . ($S->A("episode") < 10 ? "0" : "") . $S->A("episode") . "</span><br>";
         $lastAD = $S->A("airDate");
     }
     $html .= "</div>" . OnEvent::script("g.sameHeight('.comingUp');");
     $html .= "<h1>Neue Folgen</h1>";
     $AC = anyC::get("JDownload");
     $AC->addAssocV3("JDownloadDate", ">", time() - 3600 * 24 * 7);
     $AC->addOrderV3("JDownloadDate", "DESC");
     $AC->addAssocV3("JDownloadSerieID", "!=", "0");
     $AC->addJoinV3("Serie", "JDownloadSerieID", "=", "SerieID");
     while ($D = $AC->getNextEntry()) {
         if ($D->A("JDownloadSerieID") != "0" and $D->A("cover") != "" and trim($D->A("coverThumb")) == "") {
             $S = new Serie($D->A("JDownloadSerieID"));
             $S->changeA("coverThumb", DBImageGUI::stringifyDataS("image/png", DBImageGUI::getData($S->A("cover")), 150, 220));
             $S->saveMe(true, false);
             $D->changeA("coverThumb", $S->A("coverThumb"));
         }
         preg_match("/S([0-9]+)E([0-9]+)/", $D->A("JDownloadRenameto"), $matches);
         $ACF = anyC::get("Folge", "SerieID", $D->A("SerieID"));
         $ACF->addAssocV3("season", "=", $matches[1]);
         $ACF->addAssocV3("episode", "=", $matches[2]);
         $ACF->setLimitV3(1);
         $F = $ACF->getNextEntry();
         $B = new Button("Abspielen", "play", "touch");
         $B->onclick("parent.UPnP.search('" . Util::makeFilename(str_replace(" ", ".", $D->A("JDownloadRenameto"))) . "');");
         $html .= "\n\t\t\t<div style=\"display:inline-block;width:33%;margin-bottom:2%;vertical-align:top;\">\n\t\t\t\t<div style=\"margin-right:20px;float:left;width:150px;\">\n\t\t\t\t\t<img style=\"width:150px;height:220px;margin-bottom:5px;\" src=\"./index.php?D=trinityDB/Serien&M=getCover&P0=" . $D->A("SerieID") . "\" />\n\t\t\t\t\t\t{$B}\n\t\t\t\t</div>\n\t\t\t\t<h2 style=\"margin-top:0px;padding-top:0px;\">" . $D->A("JDownloadRenameto") . "</h2>\n\t\t\t\t<p style=\"color:grey;\">" . ($F != null ? $F->A("description") : "Keine Beschreibung") . " <small>" . Util::CLDateParser($D->A("JDownloadDate")) . "</small></p>\n\t\t\t</div>";
     }
     return $html;
 }
예제 #2
0
 public function download(Serie $S, $echo = false)
 {
     $tab = new HTMLTable(1);
     $mirrorPath = $this->getMirror();
     $tab->addRow("Retrieving mirror list... using {$mirrorPath}");
     $serverTime = $this->getServerTime();
     $tab->addRow("Retrieving server time... {$serverTime}");
     $S->changeA("lastupdate", $serverTime);
     if ($S->A("siteID") == 0) {
         $tab->addRow("Retrieving series information...");
         $data = file_get_contents("{$mirrorPath}/api/GetSeries.php?seriesname=" . urlencode($S->A("name")) . "&language=" . $S->A("sprache"));
         if ($data === false) {
             throw new Exception("No data from {$mirrorPath}/api/GetSeries.php?seriesname=" . urlencode($S->A("name")) . "&language=" . $S->A("sprache"));
         }
         #die("DATA: $data");
         $seriesInfo = new SimpleXMLElement($data, null, false);
         $seriesID = $seriesInfo->Series->seriesid;
         $S->changeA("siteID", $seriesID);
         #$S->changeA("description", $seriesInfo->Series->Overview);
     } else {
         $seriesID = $S->A("siteID");
     }
     $tempFile = Util::getTempFilename("SerieID" . $S->getID(), "zip");
     $tab->addRow("Downloading episodes information...");
     $SZip = "{$mirrorPath}/api/{$this->apiKey}/series/{$seriesID}/all/" . $S->A("sprache") . ".zip";
     if (!copy($SZip, $tempFile)) {
         Red::errorD("The download of {$SZip} failed!");
     }
     try {
         $zip = new ZipArchive();
         if ($zip->open($tempFile) === TRUE) {
             $zip->extractTo(dirname($tempFile) . "/SerieID" . $S->getID());
             $zip->close();
             $tab->addRow("Extracting data...");
         } else {
             throw new ClassNotFoundException("");
         }
     } catch (ClassNotFoundException $e) {
         if (!Util::isWindowsHost()) {
             $commandUnzip = "unzip -o {$tempFile} -d SerieID" . $S->getID();
         } else {
             $commandUnzip = Util::getRootPath() . "trinityDB/Serien/unzip.exe -o {$tempFile} -d SerieID" . $S->getID();
         }
         $tab->addRow("Extracting data...<br />{$commandUnzip}");
         $sc = new SystemCommand();
         $sc->setCommand("cd " . dirname($tempFile) . " && {$commandUnzip}");
         $sc->execute();
     }
     $e = 0;
     $u = 0;
     $file = dirname($tempFile) . "/SerieID" . $S->getID() . "/" . $S->A("sprache") . ".xml";
     if (!file_exists($file)) {
         Red::errorD("Could not find the expected file {$file}. Please check if it was properly extracted from {$tempFile}.");
     }
     $episodesList = new SimpleXMLElement(file_get_contents($file));
     $status = $episodesList->Series->Status;
     $S->changeA("description", $episodesList->Series->Overview);
     $S->changeA("status", $status);
     $S->changeA("genre", $episodesList->Series->Genre);
     foreach ($episodesList->Episode as $k => $v) {
         $AC = anyC::get("Folge", "SerieID", $S->getID());
         $AC->addAssocV3("season", "=", $v->SeasonNumber);
         $AC->addAssocV3("episode", "=", $v->EpisodeNumber);
         $AC->lCV3();
         if ($AC->numLoaded() > 1) {
             while ($F = $AC->getNextEntry()) {
                 $F->deleteMe();
             }
         }
         $F = new Factory("Folge");
         $F->sA("SerieID", $S->getID());
         $F->sA("season", $v->SeasonNumber);
         $F->sA("episode", $v->EpisodeNumber);
         if ($E = $F->exists(true)) {
             if ($v->lastupdated == $E->A("lastupdate")) {
                 continue;
             }
             $E->changeA("name", $v->EpisodeName);
             $E->changeA("airDate", $v->FirstAired);
             $E->changeA("lastupdate", $v->lastupdated);
             $E->changeA("description", $v->Overview);
             $E->saveMe(true, false);
             $u++;
             continue;
         }
         $F->sA("episodeID", $v->id);
         $F->sA("name", $v->EpisodeName);
         $F->sA("airDate", $v->FirstAired);
         $F->sA("lastupdate", $v->lastupdated);
         $F->sA("description", $v->Overview);
         $F->sA("wanted", "1");
         $F->store(true, false);
         $e++;
     }
     $tab->addRow("Loaded {$e} episodes");
     $tab->addRow("Updated {$u} episodes");
     if (mUserdata::getGlobalSettingValue("trinityDBdlCover", "0") == "1") {
         $bannerList = new SimpleXMLElement(dirname($tempFile) . "/SerieID" . $S->getID() . "/banners.xml", null, true);
         foreach ($bannerList as $banner) {
             if ($banner->BannerType . "" == "poster") {
                 #echo $banner->BannerPath."";
                 $cover = file_get_contents("http://www.thetvdb.com/banners/" . $banner->BannerPath);
                 $temp = Util::getTempFilename("cover", "jpg");
                 file_put_contents($temp, $cover);
                 if ($S->A("dir") != "" and file_exists($S->A("dir"))) {
                     file_put_contents($S->A("dir") . "/Folder.jpg", $cover);
                 }
                 $S->changeA("cover", DBImageGUI::stringifyS("image/jpg", $temp));
                 $S->changeA("coverThumb", DBImageGUI::stringifyS("image/png", $temp, 150, 220));
                 #$S->saveMe();
                 unlink($temp);
                 $tab->addRow("Downloaded cover");
                 break;
             }
         }
     }
     $S->saveMe(true, false);
     if ($echo) {
         echo $tab;
     }
 }