You are here

public function FeedsYoutubeParser::parse in Feeds: YouTube Parser 6

Same name and namespace in other branches
  1. 7.3 plugins/FeedsYoutubeParser.inc \FeedsYoutubeParser::parse()
  2. 7.2 FeedsYoutubeParser.inc \FeedsYoutubeParser::parse()

Parse the extra mapping sources provided by this parser.

Parameters

$batch FeedsImportBatch:

$source FeedsSource:

Overrides FeedsParser::parse

See also

FeedsParser::parse()

File

./FeedsYoutubeParser.inc, line 23
Feeds parser class for Youtube

Class

FeedsYoutubeParser
Class definition for Youtube Parser.

Code

public function parse(FeedsImportBatch $batch, FeedsSource $source) {
  $youtube_feed = $batch
    ->getRaw();

  /** @see common_syndication_parser_parse() */
  if (!defined('LIBXML_VERSION') || version_compare(phpversion(), '5.1.0', '<')) {
    @($sxml = simplexml_load_string($youtube_feed, NULL));
  }
  else {
    @($sxml = simplexml_load_string($youtube_feed, NULL, LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NOCDATA));
  }

  // Got a malformed XML.
  if ($sxml === FALSE || is_null($sxml)) {
    throw new Exception(t('FeedsYoutubeParser: Malformed XML source.'));
  }

  // Run parsing if the feed is Atom or RSS
  if ($this
    ->isAtomFeed($sxml)) {
    $this
      ->parseAtom($sxml, $batch, $source);
  }
  elseif ($this
    ->isRssFeed($sxml)) {
    $this
      ->parseRss20($sxml, $batch, $source);
  }
  else {
    throw new Exception(t('FeedsYoutubeParser: Unknown type of feed.'));
  }
}