Ejemplo n.º 1
0
 private function logDownload($logLink, $link, $fileName = "", $fileSize = 0, Serie $Serie = null, $renamed = false)
 {
     $F = new Factory("JDownload");
     $F->sA("JDownloadURL", $logLink);
     $F->sA("JDownloadFilename", $link);
     $F->sA("JDownloadRenameto", $fileName);
     $F->sA("JDownloadJDID", $this->getID());
     $F->sA("JDownloadSerieID", $Serie != null ? $Serie->getID() : 0);
     if ($renamed) {
         $F->sA("JDownloadRenamed", time());
     }
     $E = $F->exists(true);
     if ($E === false) {
         $F->sA("JDownloadDate", time());
         $F->sA("JDownloadFilesize", $fileSize);
         $id = $F->store();
     } else {
         $E->changeA("JDownloadDate", time());
         $E->changeA("JDownloadFilesize", $fileSize);
         $E->saveMe();
         $id = $E->getID();
     }
     return $id;
 }
Ejemplo n.º 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;
     }
 }