diff --git a/src/Contracts/VendorInterface.php b/src/Contracts/VendorInterface.php index 8d69c70..7ec3b20 100644 --- a/src/Contracts/VendorInterface.php +++ b/src/Contracts/VendorInterface.php @@ -42,4 +42,9 @@ public function setLimit($limit); * @return array */ public function buildFeed(SimpleXMLElement $feed); + + /** + * @return void + */ + public function original(); } diff --git a/src/PodcastScraper.php b/src/PodcastScraper.php index b0cfb0c..f627ba5 100644 --- a/src/PodcastScraper.php +++ b/src/PodcastScraper.php @@ -95,6 +95,16 @@ public function limit($limit) return $this; } + /** + * @return PodcastScraper + */ + public function original() + { + $this->vendor->original(); + + return $this; + } + /** * @param Request $request * @param string $feedUrl diff --git a/src/ScrapePodcast.php b/src/ScrapePodcast.php index 64b53a6..8004883 100644 --- a/src/ScrapePodcast.php +++ b/src/ScrapePodcast.php @@ -17,6 +17,11 @@ class ScrapePodcast */ protected $count = 15; + /** + * @var bool + */ + protected $isOrginal = false; + /** * ScrapePodcast constructor. */ @@ -87,11 +92,23 @@ public function feed($feed) return $this->engine()->find($feed); } + /** + * @return ScrapePodcast + */ + public function original() + { + $this->isOrginal = true; + + return $this; + } + /** * @return PodcastScraper */ protected function engine() { - return (new PodcastScraper($this->vendor))->limit($this->count); + $engine = (new PodcastScraper($this->vendor))->limit($this->count); + + return $this->isOrginal ? $engine->original() : $engine; } } diff --git a/src/Vendors/AbstractVendor.php b/src/Vendors/AbstractVendor.php index 5c68737..1effcf2 100644 --- a/src/Vendors/AbstractVendor.php +++ b/src/Vendors/AbstractVendor.php @@ -7,6 +7,11 @@ abstract class AbstractVendor { + /** + * @var bool + */ + protected $isOrginal = false; + /** * @param SimpleXMLElement $feed * @@ -45,6 +50,7 @@ protected function getEpisodes($channel) 'size' => $this->getEpisodeSize($value), 'duration' => $this->getEpisodeDuration($value), 'description' => (string) $value->description, + 'keywords' => $this->getKeywords($value), 'link' => (string) $value->link, 'image' => $this->getEpisodeImage($value, $channel), 'published_at' => $this->getPublishedDate($value), @@ -54,6 +60,14 @@ protected function getEpisodes($channel) return $items; } + /** + * @return array + */ + protected function getKeywords($item) + { + return array_map('trim', explode(",", $this->getValueByPath($item, 'keywords'))); + } + /** * @param SimpleXMLElement $value * diff --git a/src/Vendors/DigitalPodcast.php b/src/Vendors/DigitalPodcast.php index 797524f..c819bf0 100644 --- a/src/Vendors/DigitalPodcast.php +++ b/src/Vendors/DigitalPodcast.php @@ -101,4 +101,12 @@ public function build(array $response) return $output; } + + /** + * @return void + */ + public function original() + { + $this->isOrginal = true; + } } diff --git a/src/Vendors/Itunes.php b/src/Vendors/Itunes.php index 85156e9..3f971f3 100644 --- a/src/Vendors/Itunes.php +++ b/src/Vendors/Itunes.php @@ -90,6 +90,9 @@ public function generateUrl($value) public function build(array $response) { $response = json_decode($response['search']); + if ($this->isOrginal) { + return $response; + } $output['result_count'] = $response->resultCount; foreach ($response->results as $value) { @@ -98,7 +101,7 @@ public function build(array $response) 'author' => $value->artistName, 'title' => $value->collectionName, 'episodes' => $value->trackCount, - 'image' => $value->artworkUrl100, + 'image' => $value->artworkUrl600, 'rss' => $value->feedUrl, 'itunes' => $value->collectionViewUrl, 'genre' => $value->primaryGenreName, @@ -107,4 +110,12 @@ public function build(array $response) return $output; } + + /** + * @return void + */ + public function original() + { + $this->isOrginal = true; + } } diff --git a/tests/SearchDigitalPodcastTest.php b/tests/SearchDigitalPodcastTest.php index 000dacf..56a0fa2 100644 --- a/tests/SearchDigitalPodcastTest.php +++ b/tests/SearchDigitalPodcastTest.php @@ -11,7 +11,7 @@ class SearchDigitalPodcastTest extends TestCase protected function setUp() { parent::setUp(); - $this->result = $this->scraper->digitalPodcast()->search("laravel"); + $this->result = $this->scraper->search("laravel"); $this->failedResult = $this->scraper->search(""); } } diff --git a/tests/SearchItunesPodcastTest.php b/tests/SearchItunesPodcastTest.php index ff9d36d..08f5d65 100644 --- a/tests/SearchItunesPodcastTest.php +++ b/tests/SearchItunesPodcastTest.php @@ -8,12 +8,14 @@ class SearchItunesPodcastTest extends TestCase protected $result; protected $itunesResult; protected $failedResult; + protected $itunesOriginal; protected function setUp() { parent::setUp(); $this->result = $this->scraper->search("laravel"); $this->itunesResult = $this->scraper->itunes()->search("laravel"); + $this->itunesOriginal = $this->scraper->original()->search("laravel"); $this->failedResult = $this->scraper->search(""); } @@ -21,4 +23,11 @@ public function testDefaultVendorIsItunes() { $this->assertSame($this->result, $this->itunesResult); } + + public function testOriginalItunesResponse() + { + $this->assertCount(2, $this->itunesOriginal); + $data = $this->itunesOriginal['data']; + $this->assertCount($data->resultCount, $data->results); + } }