Hi there,

Just been trying to use the YT parser and not having much luck importing any nodes. Every time I try to import, PHP responds with an error message, "Serialization of 'SimpleXMLElement' is not allowed".

I set up a new feed ("YT Feed") and attached it to a new content type ("YT Feed"). I set the parser to the YouTube Parser, and set the Processor to create nodes using my "YT Video" content type, replacing any that already exist, and doing some simple mapping. (Title to Title, Tags to a new taxonomy, "YT Tags")

I created a new feed, went to the YouTube API and coaxed a URL out of the API that looked like this: http://gdata.youtube.com/feeds/api/videos?orderby=rating&author=mazdacanada

(There's no place in your module to specify an API key, but it doesn't look like this is a problem anyways because Feeds is getting the data just fine without it)

Things just break down when I attempt to import from the feed, getting the "Serialization of 'SimpleXMLElement' is not allowed" error. I can run the YT feed through the normal feed engine fine, nodes get created, just not through the YT parser.

Am I missing something? Thanks!!

Drupal 6.20
Feeds 6.x-1.0-Beta10
Feeds: YouTube 6.x-2.0-Beta2

PHP 5.3.5
MySQL 5.5.8

Comments

Stephen Scholtz’s picture

I dug into your code and I think I found the problem. Or at least the import worked after I made these changes.

There were no references to serialize() in your code, so I deduced that this is something that the Feeds module proper does. SimpleXML objects are, well, objects, and apparently you're not supposed to serialize them.

I looked into FeedsYoutubeParser.inc and looped through the contents of your $item (around line 245), using gettype() to see what the parser was trying to send onwards to Feeds. Sure enough, I found two instances of SimpleXML objects, for thumbnail and for duration_raw. Casting them as string and integer respectively got rid of the error message and the nodes were properly imported and created.

The final $item declaration should look like this:


      $item = array(
        'feed_title' => $feed_title,
        'guid' => (string) $entry->id,
        'video_id' => $id,
        'url' => 'http://www.youtube.com/watch?v=' . $id,
        'watch_page' => $watch,
        'title' => (string) $media->group->title,
        'author' => (string) $entry->author->name,
        'description' => (string) $media->group->description,
        'thumbnail' => (string) $thumbnail, // was an object, now being cast to string
        'category' => (string) $media->group->category,
        'tags' => explode(',', $media->group->keywords),
        'embedded_player' => '',
        'duration' => $this->secsToTime($length),
        'duration_raw' => (integer) $length, // was an object, now being cast to integer
        'view_count' => (string) $viewCount,
        'fav_count' => (string) $viewCount,
        'rating' => (string) $rating,
        'updated_datetime' => date('Y-m-d H:i:s', strtotime($updated)),
        'updated_timestamp' => strtotime($published),
        'published_datetime' => date('Y-m-d H:i:s', strtotime($published)),
        'published_timestamp' => strtotime($updated),
      );

Not sure if this has always been an error or if it's because of my version of PHP or changes to the YouTube API, but there you go.

Stephen Scholtz’s picture

Status: Active » Needs review
good_man’s picture

Version: 6.x-1.0-beta2 » 6.x-1.x-dev
Priority: Normal » Critical

yes $length should be converted to int, either by (int) or (integer) both works well.

Also this applies to 7.x as well, please commit it to both versions.

good_man’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
StatusFileSize
new1.44 KB

A patch against 7.x-2.x branch, you can back-port it easily to 6.x branch.

wojtha’s picture

+++ b/FeedsYoutubeParser.incundefined
@@ -264,7 +260,7 @@ class FeedsYoutubeParser extends FeedsParser {
         'duration' => $this->secsToTime($length),
-        'duration_raw' => $length,
+        'duration_raw' => (int) $length,

This is ok, but he second cast is missing.

+++ b/FeedsYoutubeParser.incundefined
@@ -44,16 +42,14 @@ class FeedsYoutubeParser extends FeedsParser {
-    }
-    else {
+

Please don't do this, "else" should be on the new line.

Powered by Dreditor.

wojtha’s picture

Status: Needs review » Needs work
good_man’s picture

Status: Needs work » Needs review
StatusFileSize
new2.41 KB

Fixed the else thing, but didn't understand what do you mean by the second cast?

wojtha’s picture

@good_man Stephen in #1 has reported two properties which needs the explicit conversion. The second one is:

'thumbnail' => (string) $thumbnail, // was an object, now being cast to string
good_man’s picture

hmmm just rethinking of it, there is already a cast before that:

      // Get video thumbnail
      $attrs = $media->group->thumbnail[0]->attributes();
      $thumbnail = (string) $attrs['url'];

      // Get <yt:duration> node for video length
      $yt = $media->children('http://gdata.youtube.com/schemas/2007');
      $attrs = $yt->duration->attributes();
      $length = (int) $attrs['seconds'];

Why re-casting again? and why the first cast (the one in the code above) is not working, any thoughts?

wojtha’s picture

@good_man Ok, it was probably because Stephen reported it against 6.x-1.0-beta2 and there was couple of fixes since then. So left the patch as it is, I'll try to review the patch ASAP but I can't promise it will be today... I'm pretty busy these days... :-/

good_man’s picture

Status: Needs review » Active

It's also appears in 7.x that's why I got to here, I'll give it another look and report back my tests.

wojtha’s picture

Status: Active » Fixed

Thanks, fixed in dev.

Commit 5076f9c on 6.x-1.x
Commit dd740b2 on 7.x-2.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

carsato’s picture

Hello

The same happens to 6.x-1.0-beta2 version.

I did this modifications (see the patch) and all worked fine.

theohawse’s picture

Current 6.x dev version has this issue fixed, no patch required.

However current recommended version still has this bug.

odyseg’s picture

I also had this problem just now.. suggestion #5 and #8 works for me :)