Untitled

mail@pastecode.io avatar
unknown
php
2 years ago
3.0 kB
1
Indexable
Never
function info($url)
    {    
        //$url = "https://fecomic.com/comic/toi-da-tro-thanh-con-gai-nuoi-cua-nam-chinh-576";
        
        $curl_respone = $this->curl($url);

        if ($curl_respone) {
            $crawler = new Crawler($curl_respone);
            $manga = $crawler->filter('.site-content');
            if ($manga->count() <= 0) {
                return die('Có lỗi khi lấy dữ liệu!');
            }

            $outerHtml = $manga->eq(0)->outerHtml();


            $data['name'] = mb_convert_case(trim($manga->filter('.post-title h1')->text()), MB_CASE_TITLE, "UTF-8");

            if(strpos('Bảo vệ', $data['name'])){
                return null;
            }

            $data['other_name'] = mb_convert_case(trim(remove_html(explode_by("Tên gọi khác </h5>\n</div>", '</div>', $outerHtml))), MB_CASE_TITLE, "UTF-8");
            $data['other_name'] = $data['other_name'] === 'Đang Cập Nhật' ? NULL : $data['other_name'];

            $data['cover'] = str_replace(' ', '%20', trim($crawler->filter('.summary_image img')->eq(0)->attr('data-src')));

            $data['description'] = $crawler->filter('#summary')->text();

            $data['status'] = trim($manga->filter('.post-status')->text());
            $data['status'] = slugGenerator($data['status']) == 'dang-cap-nhat' ? 'on-going' : 'completed';

            $data['taxonomy']['source'][] = $url;

            $data['taxonomy']['authors'] = $manga->filter('.author-content a')->each(function (Crawler $node) {
                $authors =  trim($node->text());

                if($authors === 'Fecomic'){
                    return null;
                }

                return $authors;
            });

            $data['taxonomy']['genres'] = $manga->filter('.summary_content .genres a')->each(function (Crawler $node) {
                return $this->change_category($node->text());
            });

            $data['taxonomy']['translation'] = $manga->filter('.artist-content a')->each(function (Crawler $node) {
                return trim($node->text());
            });

            $data['list_chapter'] = $crawler->filter('.listing-chapters_wrap ul li a')->each(function (Crawler $node) {
                if($node->count() <= 0){
                    return null;
                }
                $chapter['name'] = mb_convert_case(trim($node->text()), MB_CASE_TITLE, "UTF-8");

                if (preg_match('#(chapter|chương|chap)(.[\d.]+)#is', $chapter['name'], $name) && !empty($name[2])) {
                    $chapter['name'] = 'Chapter '. trim($name[2]);
                }

                $chapter['url'] = trim($node->attr('href'));

                return $chapter;
            });

            $data['list_chapter'] = array_reverse(array_filter($data['list_chapter']));

            return $data;
        }


        exit("Xãy ra lỗi khi curl");
    }