diff --git a/bridges/ScribbleHubBridge.php b/bridges/ScribbleHubBridge.php index c904cd03..4fe43df3 100644 --- a/bridges/ScribbleHubBridge.php +++ b/bridges/ScribbleHubBridge.php @@ -54,24 +54,36 @@ class ScribbleHubBridge extends FeedExpander return []; } - if ($item_html = getSimpleHTMLDOMCached($item['uri'])) { - //Retrieve full description from page contents - $item['content'] = $item_html->find('#chp_raw', 0); + $item['comments'] = $item['uri'] . '#comments'; - //Retrieve image for thumbnail - $item_image = $item_html->find('.s_novel_img > img', 0)->src; - $item['enclosures'] = [$item_image]; - - //Restore lost categories - $item_story = html_entity_decode($item_html->find('.chp_byauthor > a', 0)->innertext); - $item_sid = $item_html->find('#mysid', 0)->value; - $item['categories'] = [$item_story, $item_sid]; - - //Generate UID - $item_pid = $item_html->find('#mypostid', 0)->value; - $item['uid'] = $item_sid . "/$item_pid"; + try { + $item_html = getSimpleHTMLDOMCached($item['uri']); + } catch (HttpException $e) { + // 403 Forbidden, This means we got anti-bot response + if ($e->getCode() === 403) { + return $item; + } + throw $e; } + $item_html = defaultLinkTo($item_html, self::URI); + + //Retrieve full description from page contents + $item['content'] = $item_html->find('#chp_raw', 0); + + //Retrieve image for thumbnail + $item_image = $item_html->find('.s_novel_img > img', 0)->src; + $item['enclosures'] = [$item_image]; + + //Restore lost categories + $item_story = html_entity_decode($item_html->find('.chp_byauthor > a', 0)->innertext); + $item_sid = $item_html->find('#mysid', 0)->value; + $item['categories'] = [$item_story, $item_sid]; + + //Generate UID + $item_pid = $item_html->find('#mypostid', 0)->value; + $item['uid'] = $item_sid . "/$item_pid"; + return $item; } @@ -80,11 +92,27 @@ class ScribbleHubBridge extends FeedExpander $name = parent::getName() . " $this->queriedContext"; switch ($this->queriedContext) { case 'Author': - $page = getSimpleHTMLDOMCached(self::URI . 'profile/' . $this->getInput('uid')); + try { + $page = getSimpleHTMLDOMCached(self::URI . 'profile/' . $this->getInput('uid')); + } catch (HttpException $e) { + // 403 Forbidden, This means we got anti-bot response + if ($e->getCode() === 403) { + return $name; + } + throw $e; + } $title = html_entity_decode($page->find('.p_m_username.fp_authorname', 0)->plaintext); break; case 'Series': - $page = getSimpleHTMLDOMCached(self::URI . 'series/' . $this->getInput('sid') . '/a'); + try { + $page = getSimpleHTMLDOMCached(self::URI . 'series/' . $this->getInput('sid') . '/a'); + } catch (HttpException $e) { + // 403 Forbidden, This means we got anti-bot response + if ($e->getCode() === 403) { + return $item; + } + throw $e; + } $title = html_entity_decode($page->find('.fic_title', 0)->plaintext); break; }