From ffa3f9309f9f87b63dae58235597dbad467ba37d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 18 Nov 2019 19:00:08 +0300 Subject: [PATCH] af_comics: support buni webtoon episodes --- .../filters/af_comics_comicpress.php | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/plugins/af_comics/filters/af_comics_comicpress.php b/plugins/af_comics/filters/af_comics_comicpress.php index 19c335660..7755bcb1a 100755 --- a/plugins/af_comics/filters/af_comics_comicpress.php +++ b/plugins/af_comics/filters/af_comics_comicpress.php @@ -18,9 +18,8 @@ class Af_Comics_ComicPress extends Af_ComicFilter { // lol at people who block clients by user agent // oh noes my ad revenue Q_Q - $res = fetch_file_contents($article["link"], false, false, false, - false, false, 0, - "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"); + $res = fetch_file_contents(["url" => $article["link"], + "useragent" => "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"]); $doc = new DOMDocument(); @@ -30,10 +29,34 @@ class Af_Comics_ComicPress extends Af_ComicFilter { if ($basenode) { $article["content"] = $doc->saveHTML($basenode); + return true; + } + + // buni-specific + $webtoon_link = $xpath->query("//a[contains(@href,'www.webtoons.com')]")->item(0); + + if ($webtoon_link) { + + $res = fetch_file_contents(["url" => $webtoon_link->getAttribute("href"), + "useragent" => "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"]); + + if (@$doc->loadHTML($res)) { + $xpath = new DOMXPath($doc); + $basenode = $xpath->query('//div[@id="_viewerBox"]')->item(0); + + if ($basenode) { + $imgs = $xpath->query("//img[@data-url]", $basenode); + + foreach ($imgs as $img) { + $img->setAttribute("src", $img->getAttribute("data-url")); + } + + $article["content"] = $doc->saveHTML($basenode); + return true; + } + } } } - - return true; } return false;