From b17a2c8162b23e878ba5c9b3f92a351743756c4b Mon Sep 17 00:00:00 2001 From: Dag Date: Fri, 22 Apr 2022 17:57:29 +0200 Subject: [PATCH] fix --- .gitignore | 1 + src/Finder.php | 2 +- src/finders/HackerNews.php | 27 +++++++++++++++++++++++++++ src/finders/Html.php | 28 +++++++++++++++++++++++----- src/finders/Instagram.php | 32 ++++++++++++++++++++++++++++++++ src/finders/Telegram.php | 4 ++-- 6 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 src/finders/HackerNews.php create mode 100644 src/finders/Instagram.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2659611 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +composer.lock diff --git a/src/Finder.php b/src/Finder.php index 3103faa..63788ae 100755 --- a/src/Finder.php +++ b/src/Finder.php @@ -11,7 +11,7 @@ abstract class Finder public const INDEX = 50; public const NAME = 'Generic name'; - public const DESCRIPTION = 'Generic description'; + public const DESCRIPTION = ''; public function findByUrl(Url $url): array { diff --git a/src/finders/HackerNews.php b/src/finders/HackerNews.php new file mode 100644 index 0000000..981a48f --- /dev/null +++ b/src/finders/HackerNews.php @@ -0,0 +1,27 @@ +finding('https://hnrss.org/frontpage')]; + } + if (preg_match('#^https?://news\.ycombinator\.com/newest$#', (string) $url)) { + return [$this->finding('https://hnrss.org/newest')]; + } + if (preg_match('#^https?://news\.ycombinator\.com/item\?id=(\d+)$#', (string) $url, $m)) { + return [$this->finding(sprintf('https://hnrss.org/item?id=%s', $m[1]))]; + } + + return []; + } +} \ No newline at end of file diff --git a/src/finders/Html.php b/src/finders/Html.php index d964db6..297485d 100755 --- a/src/finders/Html.php +++ b/src/finders/Html.php @@ -50,18 +50,36 @@ final class Html extends Finder $title = strtolower(trim($anchor->getAttribute('title'))); $nodeValue = strtolower(trim($anchor->nodeValue)); - // todo: use php8 shim for str_ends_with() - if (array_filter(['rss', 'feed', 'atom', 'rss feed'], fn($s) => $nodeValue === $s) || array_filter(['rss', 'feed', 'atom', 'atom feed'], fn($s) => $s === $title) || substr($href, -strlen('.rss')) === '.rss' || substr($href, -strlen('.xml')) === '.xml' || substr($href, -strlen('.atom')) === '.atom' || substr($href, -strlen('/rss')) === '/rss' - //|| strpos($href, 'feed:') === 0 test this one - || preg_match('#^https?://feeds\.feedburner\.com#', $href) ) { - $result[(string) $url->resolve($href)] = $this->finding($url->resolve($href)); + // many false positives here + try { + $result[(string)$url->resolve($href)] = $this->finding($url->resolve($href)); + } catch (UrlException $e) { + // pass + } + } + + // todo: use php8 shim for str_ends_with() + + if (preg_match('#^https?://feeds\.feedblitz\.com/#', $href)) { + // Works without &x=1 too when not using a browser + $result[$href] = $this->finding(sprintf('%s&x=1', $href)); + } + if (preg_match('#^https?://feeds\.feedburner\.com/#', $href)) { + $result[$href] = $this->finding(rtrim($href, '/feed')); + } + if (preg_match('#^https?://www\.feedio.co/@#', $href)) { + $result[$href] = $this->finding(sprintf('%s/feed', $href)); + } + if (preg_match('#^feed:#', $href)) { + // todo: fix + //$result[$href] = $this->finding($href); } } return $result; diff --git a/src/finders/Instagram.php b/src/finders/Instagram.php new file mode 100644 index 0000000..2920a3e --- /dev/null +++ b/src/finders/Instagram.php @@ -0,0 +1,32 @@ +providers = [ + 'https://bibliogram.pussthecat.org/u/%s/rss.xml', + 'https://bibliogram.1d4.us/u/%s/rss.xml', + 'https://bib.actionsack.com/u/%s/rss.xml', + ]; + } + + public function findByUrl(Url $url): array + { + $provider = $this->providers[array_rand($this->providers)]; + + if (preg_match('#^https?://(?:www\.)?instagram\.com/(\w+)#', (string) $url, $m)) { + return [$this->finding(sprintf($provider, $m[1]))]; + } + return []; + } + +} \ No newline at end of file diff --git a/src/finders/Telegram.php b/src/finders/Telegram.php index 6031767..af9edcf 100755 --- a/src/finders/Telegram.php +++ b/src/finders/Telegram.php @@ -21,8 +21,8 @@ final class Telegram extends Finder if ($providers === []) { return []; } - if (preg_match('#^https?://t\.me/(\w+)#', (string) $url, $m)) { - // todo: might not be a public channel + if (preg_match('#^https?://t\.me/(?:s/)?(\w+)#', (string) $url, $m)) { + // Might not be a public channel return [ $this->finding(sprintf($providers[array_rand($providers)], $m[1])), ]; -- 2.45.2