/** * Execute the job. * * @return void */ public function handle(FeedService $parser, ImageDownloadService $downloader) { $feed = $parser->loadDetailsFromRss($this->podcast->feed); $this->podcast->name = $feed['title']; $this->podcast->url = $feed['link']; $this->podcast->description = $feed['summary']; $image_path = $downloader->saveImage($feed['image'], md5($this->podcast->feed), 600, 600); if ($image_path != null) { $this->podcast->coverimage = $image_path; } if ($this->podcast->name == null) { $this->podcast->error = 17; // podcast could not be parsed error } $this->podcast->save(); }
public function testFeed(FeedService $parser) { $json = file_get_contents('https://itunes.apple.com/search?media=podcast&term=life&limit=50'); $podcasts = json_decode($json); $result = ''; foreach ($podcasts->results as $podcast) { $url = $podcast->feedUrl; $feed = $parser->loadDetailsFromRss($url); $result .= '<table>'; $result .= '<tr><td><img src="' . $feed['image'] . '" width=200 height=200></td>'; $result .= '<td><h2>' . $feed['title'] . '</h2>'; $result .= '<p>' . $url . '</p><p>' . $feed['link'] . '</p><p>' . $feed['summary'] . '</p>'; $result .= '</td></tr>'; $result .= '</table>'; } return $result; }
/** * Save podcasts from uploaded opml file. * * @param Request $request * @return Response */ public function postPodcastsByOpml(Request $request, FeedService $parser) { if (!$request->hasFile('xml')) { return response()->json(['error' => 'No file.'], $status = 500); } elseif (!$request->file('xml')->isValid()) { return response()->json(['error' => 'File invalid.'], $status = 500); } $user = Auth::user(); $file = $request->file('xml'); $pos = $user->getNewPodcastPosition(); $new = []; try { $feeds = $parser->parseOpml($file); } catch (\Exception $e) { return response()->json(['error' => 'File could not be parsed.'], $status = 500); } foreach ($feeds as $feed) { $podcast = Podcast::getOrCreateFromRss($feed); $created = $user->addPodcast($podcast, $pos); if ($created) { $pos++; $new[] = $podcast; } } return response()->json(['success' => true, 'new' => $new, 'feeds' => $feeds]); }