~thirdplace/feed-finder

2b9709abd54af76983785e80d95f392c5f74091c — Dag 4 months ago b17a2c8 main
fix: use instagram providers
2 files changed, 14 insertions(+), 8 deletions(-)

M src/FeedFinder.php
M src/finders/Instagram.php
M src/FeedFinder.php => src/FeedFinder.php +4 -0
@@ 16,6 16,7 @@ final class FeedFinder
            'hidden' => [],
            'feeds' => [],
            'peertube' => [],
            'instagram' => [],
            'telegram' => [],
            'twitch' => [],
            'twitter' => [],


@@ 74,6 75,9 @@ final class FeedFinder
                case Hidden::class:
                    $finders[] = new Hidden($this->config['hidden']);
                    break;
                case Instagram::class:
                    $finders[] = new Instagram($this->config['instagram']);
                    break;
                case PeerTube::class:
                    $finders[] = new PeerTube($this->config['peertube']);
                    break;

M src/finders/Instagram.php => src/finders/Instagram.php +10 -8
@@ 6,27 6,29 @@ namespace Thirdplace;
final class Instagram extends Finder
{
    public const NAME = 'Instagram';
    public const DESCRIPTION = 'This feed contains instamgram items. WARNING: This is a third-party provider.';

    private array $providers;

    // todo: inject providers
    public function __construct(array $providers = [])
    {
        $this->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',
        ];
        $this->providers = $providers;
    }

    public function findByUrl(Url $url): array
    {
        if ($this->providers === []) {
            return [];
        }

        $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 [
                $this->finding(sprintf($provider, $m[1])),
            ];
        }
        return [];
    }

}
\ No newline at end of file
}