Filefield Description used as title in playlist

iaminawe - July 16, 2009 - 11:04
Project:XSPF Playlist
Version:6.x-1.0-alpha2
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi,
I have finally managed to get this module to work with CCK filefields and the FLV Media player but I have a question with regards the title that is output in the playlist.
At current I am using a multiple filefield and it correctly adds the different files to the xspf playlist but the title of each is set to the node title.

Would it be possible for the file title in the playlist field to be set to its description as enabled through the fields configuration? Then my four different videos would have four different titles based on what is entered into their description via the node edit screen

This would be awesome... can anyone assist?

Thanks
Gregg

#1

mongolito404 - July 20, 2009 - 08:36

Here is a modified xspf_playlist_cck_filefield_handler from my xspf_playlist_cck.module, it uses filefield's description as title. It first try to use the 'title' set by FileField, then the description and finally the file name (without the extension). As a bonus, it also set to type and duration field and remove the identifier one (see http://drupal.org/node/524878).

<?php
function xspf_playlist_cck_filefield_handler($node, $field_name) {
  global
$base_url;
 
$items = array();
 
// extract all the embeded items from this field
 
foreach ($node->{$field_name} as $field) {
    if (
$field['filepath']) {
      if (
$xspf_item = xspf_playlist_node_build_file_item($node, $base_url . $field['filepath'])) {
        foreach(
$xspf_item as $delta => &$xspf_field) {
          switch(
$xspf_field['key']){
            case
'identifier':
             
//unset($xspf_item[$delta]);
             
break;
            case
'title':
              if(
$field['data']['title']) {
               
$xspf_field['value'] = check_plain($field['data']['title']);
              } elseif (
$field['data']['description']) {
               
$xspf_field['value'] = check_plain($field['data']['description']);
              } else {
               
$path_info = pathinfo($field['filepath']);
               
$xspf_field['value'] = $path_info['filename'];
              }
              break;
            case
'meta':
              switch(
$xspf_field['attributes']['rel']) {
                case
'type':
                  if(
$field['filemime']) {
                   
$xspf_field['value'] = $field['filemime'];
                  }
              }
              break;
          }
        }
        if(
$field['data']['duration']) {
         
$xspf_item[] = array(
           
'key' => 'duration',
           
'value' => (int) ($field['data']['duration'] * 1000)
          );
        }
       
$items[] = $xspf_item;
      }
    }
  }
  return
$items;
}
?>

#2

iaminawe - July 21, 2009 - 18:33

Thanks Mongolito, unfortunately didn't work for me using the description field. Not sure why exactly but I have moved on from using Filefield and trying to get a similar thing working with the CCK link field. If you can assist over at http://drupal.org/node/526608 I would be so grateful.

#3

jsulmar - October 20, 2009 - 13:12

Can you please help explain how you got filefields to work with XSPF Playlist and FLV Player? I've described my problem in http://drupal.org/node/494818#comment-2171410 . I feel like a real dufus because I've been trying for 2 weeks to create a simple mp3 playlist and I keep hitting brick walls.

Thanks very much if you can help.

#4

iaminawe - October 20, 2009 - 13:25

This thread http://drupal.org/node/374238 has a patch that should enable you to see filefields in this reference.

#5

mongolito404 - October 21, 2009 - 09:01

One could probably also use hook_xspf_playlist_list_alter or hook__xspf_playlist_item_alter to achieve similar results without patching xspf_playlist_cck.module.

 
 

Drupal is a registered trademark of Dries Buytaert.