I have a feed (parsed via the simpliepie parser) which provides the the feed information as below.

I would like to be able to map the options->enclosures->video->x-m4v->link to a custom cck field, but the mapping through the feed element mapper is only giving me options->enclosures->video->x-m4v.

Is there a way to get the mapping to drill down further into the array?

I'd really appreciate any help available.

Array
(
    [title] => The Sketchup Show #50 - Using Antics 3D with SketchUp Models for Previsualization
    [description] => Alex brings Brad from Antics Technologies into the studio to discuss how Antics 3D animation software can interface with SketchUp to bring your models to life.  If you know us, you know that we ...
    [options] => Array
        (
            [original_url] => http://atotheo.libsyn.com/index.php?post_id=293230
            [timestamp] => 1199431260
            [guid] => http://atotheo.libsyn.com/index.php?post_id=293230#
            [original_author] => Array
                (
                    [name] => School
                    [link] => 
                    [email] => 
                )

            [enclosures] => Array
                (
                    [video] => Array
                        (
                            [x-m4v] => Array
                                (
                                    [0] => Array
                                        (
                                            [bitrate] => 
                                            [captions] => 
                                            [categories] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [term] => 
                                                            [scheme] => http://www.itunes.com/dtds/podcast-1.0.dtd
                                                            [label] => Technology
                                                        )

                                                    [1] => Array
                                                        (
                                                            [term] => 
                                                            [scheme] => http://www.itunes.com/dtds/podcast-1.0.dtd
                                                            [label] => Software How-To
                                                        )

                                                    [2] => Array
                                                        (
                                                            [term] => 
                                                            [scheme] => http://www.itunes.com/dtds/podcast-1.0.dtd
                                                            [label] => Education
                                                        )

                                                    [3] => Array
                                                        (
                                                            [term] => 
                                                            [scheme] => http://www.itunes.com/dtds/podcast-1.0.dtd
                                                            [label] => Training
                                                        )

                                                )

                                            [channels] => 
                                            [copyright] => 
                                            [credits] => 
                                            [description] => 
                                            [duration] => 1496
                                            [expression] => 
                                            [framerate] => 
                                            [handler] => quicktime
                                            [hashes] => 
                                            [height] => 
                                            [javascript] => js
                                            [keywords] => Array
                                                (
                                                    [0] => Google
                                                    [1] => Apple
                                                    [2] => SketchUp
                                                    [3] => Google Earth
                                                    [4] => Film
                                                    [5] => production
                                                    [6] => Google 3D Warehouse
                                                    [7] => Digital
                                                    [8] => VFX
                                                    [9] => Pixel
                                                    [10] => Antics
                                                    [11] => Design
                                                    [12] => Art
                                                    [13] => 3D
                                                )

                                            [lang] => 
                                            [length] => 221901298
                                            [link] => http://media.libsyn.com/media/atotheo/school_tss_041_m4v_640.m4v
                                            [medium] => 
                                            [player] => 
                                            [ratings] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [scheme] => urn:itunes
                                                            [value] => Clean
                                                        )

                                                )

                                            [restrictions] => 
                                            [samplingrate] => 
                                            [thumbnails] => 
                                            [title] => 
                                            [type] => application/octet-stream
                                            [width] => 
                                        )

                                )

                            [quicktime] => Array
                                (
                                    [0] => Array
                                        (
                                            [bitrate] => 
                                            [captions] => 
                                            [categories] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [term] => 
                                                            [scheme] => http://www.itunes.com/dtds/podcast-1.0.dtd
                                                            [label] => Technology
                                                        )

                                                    [1] => Array
                                                        (
                                                            [term] => 
                                                            [scheme] => http://www.itunes.com/dtds/podcast-1.0.dtd
                                                            [label] => Software How-To
                                                        )

                                                    [2] => Array
                                                        (
                                                            [term] => 
                                                            [scheme] => http://www.itunes.com/dtds/podcast-1.0.dtd
                                                            [label] => Education
                                                        )

                                                    [3] => Array
                                                        (
                                                            [term] => 
                                                            [scheme] => http://www.itunes.com/dtds/podcast-1.0.dtd
                                                            [label] => Training
                                                        )

                                                )

                                            [channels] => 
                                            [copyright] => 
                                            [credits] => 
                                            [description] => 
                                            [duration] => 
                                            [expression] => 
                                            [framerate] => 
                                            [handler] => quicktime
                                            [hashes] => 
                                            [height] => 
                                            [javascript] => js
                                            [keywords] => Array
                                                (
                                                    [0] => Google
                                                    [1] => Apple
                                                    [2] => SketchUp
                                                    [3] => Earth
                                                    [4] => Google Earth
                                                    [5] => Google Maps
                                                    [6] => Google 3D Warehouse
                                                    [7] => Digital
                                                    [8] => VFX
                                                    [9] => Pixel
                                                    [10] => Photoshop
                                                    [11] => Design
                                                    [12] => Art
                                                    [13] => 3D
                                                )

                                            [lang] => 
                                            [length] => 143873392
                                            [link] => http://media.libsyn.com/media/atotheo/sksh_cirlcelTool_ipod_04.mov
                                            [medium] => 
                                            [player] => 
                                            [ratings] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [scheme] => urn:itunes
                                                            [value] => Clean
                                                        )

                                                )

                                            [restrictions] => 
                                            [samplingrate] => 
                                            [thumbnails] => 
                                            [title] => 
                                            [type] => video/quicktime
                                            [width] => 
                                        )

                                )

                        )

                )

            [domains] => 
            [tags] => Array
                (
                    [0] => Technology
                )

            [raw] => Array
                (
                    [title] => The Sketchup Show #50 - Using Antics 3D with SketchUp Models for Previsualization
                    [link] => http://atotheo.libsyn.com/index.php?post_id=396146#
                    [description] => Alex brings Brad from Antics Technologies into the studio to discuss how Antics 3D animation software can interface with SketchUp to bring your models to life.  If you know us, you know that ...
                    [category] => Technology
                    [pubDate] => Fri, 24 Oct 2008 19:22:00 GMT
                    [guid] => http://atotheo.libsyn.com/index.php?post_id=396146#
                    [enclosure] => 
                )

        )

)
CommentFileSizeAuthor
#16 feedapi_enc_link.patch625 byteskswan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

benced’s picture

I'd like this too am going to look into the code to see why it is restricted to three steps down the heirarchy of the array

benced’s picture

Found what's blocking it

These lines here

      // Arrays with keys of 0 are not considered collections of same items - reached a leaf.
      if (isset($items[$key][0])) {
        unset($items[$key]);
        return $path;
      }

i.e. anything stuck under an array beginning with

[0] => Array

will not come up as an option

Will try deleting these lines of code and see what happens, I'm sure there is probably a reason why this is there though :S

benced’s picture

I'm guessing this was done to save on memory as the element mapper seems to use a lot of memory (esp after selecting the Simplepie Parser)

I've tried removing these lines of code and eventually had to extend my php memory limit to 1024M and there still was not enough memory to run the script, I'm hesitant to try extending it further

I've tried adding the selection using PhpMyAdmin with no luck yet
I've tried a few things including adding a custom default option, which didn't work

I think this may be because it merges all the feed items into one item and if I could find a way to switch that off and for the map to map just one feed item, which breifly looking at the code I can't find a way of doing this despite there being some suggestions that you can, then removing the lines of code might be able to work without taking too long or using too much memory

Anyone else know how to do this?

benced’s picture

Going to try using this method instead -> http://drupal.org/node/170338

benced’s picture

Problem solved

In between line 188 and 189 in the simple parser module I added this

$curr_item->enclosure_link = $simplepie_item->get_enclosure()->get_link();

Now I can map this using the mapping interface to map the link to the enclosure item wherever I want to embed in a player, to display, whatever...

benced’s picture

Version: 6.x-1.x-dev » 5.x-1.0-beta7
Category: support » feature
Status: Active » Needs review

Changing to what my settings are,

Perhaps someone can make a version up for Drupal 6

benced’s picture

Code now wrapped in an if statement so that the link isn't searched for when it don't exist

if (is_array($enclosures)) {
    $curr_item->enclosure_link = $simplepie_item->get_enclosure()->get_link();
    }
bigjim’s picture

Using feedapi 6.x.1.6 #7 works except insert it at line 155 in lieu of 188

ball.in.th’s picture

Hi,

I think the proper way to do this is for the mapper to handle an array of elements. You can just pick "options->enclosures->video->x-m4v", and the mapper should see that it's an array and maps properly. If it doesn't, perhaps its a bug in the mapper. For example, see the feedapi_mapper_emimage.inc:

      elseif (is_array($feed_element)) {
        foreach ($feed_element as $element) {
          if (is_array($element)) {
            // is this an options->enclosure-media->type array
            if (valid_url($element['link'])) {
              $items[]['embed'] = $element['link'];
            }
            elseif (valid_url($element['player'])) {
              $items[]['embed'] = $element['player'];
            }
          }
          elseif (is_string($element) && valid_url($element)) {
            // not sure when this would be called but for completeness
            $items[]['embed'] = $element;
          }
        }
      }
alienresident’s picture

I also had to make this change to map .mp3 enclosure for a feed directly from iTunes itself.

Thanks for the code it worked like a charm.

Anonymous’s picture

Version: 5.x-1.0-beta7 » 6.x-1.x-dev

An even better way would be to allow a custom mapping, instead of the fixed dropdown. For example, a textfield to enter: options->enclosures->image->jpeg->0->link which can be mapped to a custom cck field.

That would accomodate for every possibility...

mickfuzz’s picture

I've got a situation pretty much exactly the same but with an Audio file.

What is the code in #7 that you added supposed to do benced?
I've added it but can't see any extra elements in the mapper. Only as you point out upto the
[0] => Array - point

It would be good to find out what the deal is.

dman’s picture

RE #11

FYI, I just found feedapi_parser_exhaustive which exposes every bit of data in the feed in a structured way for you to choose from.
It's not as 'clever' as the other ones like simplepie or FeedAPI Extensible Parser that strictly offer an interpreted subset of the half-dozen feed formats out there. This one just throws all the data back at you. Cherry-pick the field from an exposed array. No code.
Also handy for non-standard 'extensions' to RSS!

whatdoesitwant’s picture

Thanks dman. I was wondering what was causing all my errors. I did not understand from the documentation that feedapi_parser_exhaustive and simplepie parser are interchangable and not supposed to be used additionally like feedapi_scraper. The activation of feedapi_node results in the suggestion to install parser simplepie. I therefore assumed feedapi_node and parser simplepie to be joined at the hip. I then assumed that feedapi_parser_exhaustive was an add on to parser simplepie. This is a misconception.

Am I correct in stating the following?
Within the feedapi package, in a nutshell you can install:

  • feedapi to mark a content type as a feed.
  • feedapi filters to filter feed items: feedapi_dedupe, feedapi_tagger.
  • "primary" (stand alone) feedapi parsers to make feed item data readable to drupal: feedapi_parser_exhaustive, or parser simplepie.
  • "secondary" (add-on) parsers to help primary parsers: feedapi_scraper for parser simplepie.
  • feedapi processors to convert feed items to nodes (feedapi_node) or to pass on feed settings to feed items (feedapi_inherit).
  • feedapi add ons to do cool stuff: to map parts of feed items to fields (feedapi_mapper) or to get pretty images (feedapi_imagegrabber).
  • dman’s picture

    That's a pretty good explanation of my understanding ... although the first time I saw the suite at all was yesterday :-)

    We need a nice big picture of the jigsaw.

    Slightly disconcerting is how feed parsers may not have settings that show up (not all need them) on the feed-nod form so it's tricky to tell when they are enabled and working.
    I'm still unsure on the exclusiveness of the base+add-on parsers ... and what effect the weight has when they don't over-write each other anyway, but I've created a recipe that fits for me... for now.

    kswan’s picture

    FileSize
    625 bytes

    I think that the normal use for the "enclosure" tag is to get the file url. The attached patch adds an "enclosure_link" item to the "Feed items" so that you can easily map the enclosure url to a text or link field.

    dman’s picture

    Nice, trivial, handy addition.