Skip to content

Commit

Permalink
Merge pull request #182 from j0k3r/fix-reddit-video
Browse files Browse the repository at this point in the history
Fix video fetching from RSS
  • Loading branch information
j0k3r authored Sep 23, 2018
2 parents 7847246 + eb27262 commit 92c04ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/FeedBundle/Extractor/RedditVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@ public function match($url)
return false;
}

if (!\in_array($host, ['reddit.com', 'www.reddit.com'], true)) {
// usually happen when fetching from the debug page
if (\in_array($host, ['reddit.com', 'www.reddit.com'], true)) {
$jsonUrl = 'https://' . $host . $path . '/.json';
}

// usually happen when fetching from the RSS feed
if (\in_array($host, ['v.redd.it'], true)) {
$jsonUrl = 'https://www.reddit.com/video/' . $path . '/.json';
}

if (!isset($jsonUrl)) {
return false;
}

$url = 'https://' . $host . $path . '/.json';
$url = str_replace('//.json', '/.json', $url);
$jsonUrl = str_replace('//', '/', $jsonUrl);

try {
$data = $this->client->get($url)->json();
$data = $this->client->get($jsonUrl)->json();
} catch (RequestException $e) {
return false;
}
Expand Down
4 changes: 1 addition & 3 deletions tests/FeedBundle/Extractor/RedditVideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class RedditVideoTest extends TestCase
public function dataMatch()
{
return [
['https://v.redd.it/funfg141o3hz', false],
['http://v.redd.it/', false],
['https://goog.co', false],
['http://user@:80', false],
];
Expand Down Expand Up @@ -45,7 +43,7 @@ public function testMatchRedditBadRequest()
$redditVideo = new RedditVideo();
$redditVideo->setClient($client);

$this->assertFalse($redditVideo->match('https://www.reddit.com/r/videos/comments/6rrwyj/that_small_heart_attack/'));
$this->assertFalse($redditVideo->match('https://v.redd.it/funfg141o3hz'));
}

public function testMatchRedditNotAVideo()
Expand Down

0 comments on commit 92c04ab

Please sign in to comment.