Exemplo n.º 1
0
 public function fetchChapter()
 {
     $dom = Utils::getDom($this->novel->url);
     $dds = $dom->find('dl', 0)->find('dd');
     $end = count($dds);
     $chapterIndex = $end + 1;
     $newed = false;
     foreach (range($end, 3, -3) as $i) {
         foreach (range(2, 0) as $j) {
             $chapterIndex--;
             $index = $i - $j - 1;
             $a = $dds[$index]->find('a', 0);
             if ($a == null) {
                 continue;
             }
             if (Chapter::where('index', '=', $chapterIndex)->count() != 0) {
                 $newed = true;
                 break;
             }
             $name = $a->text();
             $url = $this->novel->url . $a->getAttribute('href');
             $chapter = new Chapter();
             $chapter->name = $name;
             $chapter->index = $chapterIndex;
             $chapter->state = 'detected';
             $chapter->url = $url;
             $chapter->novel_id = $this->novel->id;
             $chapter->save();
         }
         if ($newed) {
             break;
         }
     }
     $this->novel->lastDetect = Carbon::now()->toDateTimeString();
     $this->novel->save();
 }