Ejemplo n.º 1
0
 /**
  * @return list($threadLink, $threadId);
  */
 public function findThread($boardId, Season $season)
 {
     $this->logger->writeln('Suche Thread für ' . $season . ' in board: ' . $boardId);
     $this->req = new URLRequest('http://www.subcentral.de/index.php?page=Board&boardID=' . $boardId, $this->cookieJar);
     $html = $this->req->init()->process();
     /* wir holen uns den richtigen Thread aus den "wichtigen Themen" */
     $dom = xml::doc($html);
     $res = xml::query($dom, '#stickiesStatus table td.columnTopic div.topic p');
     $stickies = array();
     // das sind nicht alle wegen break!
     foreach ($res as $topicP) {
         $topicP = xml::doc($topicP);
         $topicA = A::first(xml::query($topicP, 'a'));
         $title = (string) $topicA->nodeValue;
         $stickies[] = $title;
         $prefix = xml::query($topicP, 'span.prefix strong');
         if (count($prefix) == 1 && $prefix[0]->nodeValue == '[Subs]' && Preg::match($title, '/(Staffel\\s*' . $season->getNum() . '|S0*' . $season->getNum() . ')/i') > 0) {
             $link = $topicA->getAttribute('href');
             $threadId = (int) Preg::qmatch($link, '/threadId=([0-9]+)/');
             break;
         }
     }
     if (!isset($link)) {
         $pe = new SubcentralException('Pfad nicht gefunden: "#stickiesStatus table td.columnTopic div.topic p a" in ' . $this->req->getURL() . ' ' . Code::varInfo($stickies));
         $e = new SubcentralException('Thread für Staffel: ' . $season->getNum() . ' für Serie: ' . $season->getTvShow()->getTitle() . ' nicht gefunden', 0, $pe);
         $this->logger->writeln($e->getMessage());
         $this->logger->writeln($pe->getMessage());
         throw $e;
     }
     $link = 'http://www.subcentral.de/' . $link;
     return array($link, $threadId);
 }
 public function organize()
 {
     $this->log('Starte DownloadsOrganizer...');
     $this->log('');
     $this->log(sprintf('Frage die Episoden von %s ab...', $this->client->getURL()));
     $episodes = $this->client->getEpisodes();
     $this->log(count($episodes) . ' Episode(n) gefunden');
     $this->logger->br();
     if (isset($this->client->getLastResponse()->errors) && ($er = $this->client->getLastResponse()->errors) && count($er) > 0) {
         foreach ($er as $episodeInfo => $errors) {
             $this->log('  Fehler bei: ' . $episodeInfo . ': ' . \Psc\A::join($errors, "\n    %s"));
         }
     }
     if (count($episodes) == 0) {
         $this->log('Keine Episoden zum überprüfen');
     }
     /* diese episoden haben jetzt bestimmte stati, die für den Client wichtig sind.
           scheduled, downloaded, etc.
           
           je nach Status verschieben wir die Folgen
           schauen, ob es sie schon gibt
           starten den Download
           oder ähnliches
        */
     foreach ($episodes as $episode) {
         // wir haben genau die zustände: SCHEDULED, DOWNLOADED, MOVED, WAIT_FOR_SUB
         $this->log('Bearbeite Episode: ' . $episode->getInfo() . ' Status: ' . $episode->getStatus());
         try {
             /* zu allererst schauen wir, ob wir die Episode schon im Zielverzeichnis haben */
             $exists = $this->exists($episode);
             if ($exists) {
                 $this->log(sprintf('  Episode existiert im Zielverzeichnis. Status -> WAIT_FOR_SUB'));
                 $episode->setStatus(Status::WAIT_FOR_SUB);
             }
             if ($episode->getStatus() === Status::SCHEDULED) {
                 // wir fügen es dem jdownloader hinzu
                 try {
                     $this->startEpisode($episode);
                     // kann hier nach auf DOWNLOADED gesetzt worden sein
                 } catch (NotDecryptedException $e) {
                     $this->log('  Links decrypten! (' . $e->getMessage() . ')');
                 }
             }
             // wir überprüfen, ob der Download möglicherweise schon fertig ist
             if ($episode->getStatus() === Status::DOWNLOADING) {
                 $this->checkDownload($episode);
             }
             if ($episode->getStatus() === Status::DOWNLOADED) {
                 // wir verschieben die Episode ins Zielverzeichnis
                 try {
                     $this->moveEpisode($episode);
                 } catch (NoEpisodeDirectoryException $e) {
                     $this->log('  Kein Downloadverzeichnis mit Dateien gefunden! Zum Neuladen auf Scheduled zurücksetzen. (' . $e->directory . ')');
                     $this->log('  neuer Status: downloading');
                     $episode->setStatus(Status::DOWNLOADING);
                 }
             }
             if ($episode->getStatus() === Status::MOVED || $episode->getStatus() === Status::WAIT_FOR_SUB) {
                 if ($this->downloadSub($episode)) {
                     $episode->setStatus(Status::FINISHED);
                     $this->log('  Alle Subs vorhanden => FINISHED');
                 } else {
                     $episode->setStatus(Status::WAIT_FOR_SUB);
                     // falls wir moved haben und dann höher setzen
                     $this->log('  Warte weiterhin auf fehlende Subs');
                 }
             }
             $this->client->updateEpisodeStatus($episode, $episode->getStatus());
             $this->client->updateEpisodeExtension($episode, $episode->getExtension());
         } catch (\Psc\Exception $e) {
             $this->log('  CRITICAL ERROR: ' . $e->getMessage() . ' ' . $e->getFile() . ':' . $e->getLine());
         }
         $this->log(NULL);
     }
     return $episodes;
 }
 protected function onNotSuccessfulTest(\Exception $e)
 {
     print \Psc\A::join($this->sjg->log, "\n  %s");
     throw $e;
 }
Ejemplo n.º 4
0
 public function createUrl(array $path, $locale)
 {
     $url = '/';
     $url .= \Psc\A::implode($path, '/', function ($node) use($locale) {
         return $node->getSlug($locale);
     });
     return $url;
 }
Ejemplo n.º 5
0
 protected function debugFlat($nodes)
 {
     return "\n" . \Psc\A::implode($nodes, "\n", function ($node) {
         return $node->title->de;
     });
 }