I would like to have an inline audio helper, similar to Playtagger that would provide an audio player for each audio file in the directory listing.

Thanks

Comments

Yoran’s picture

I think this is not difficult to implement using filebrowser_video plugin pattern.

renders’s picture

I will give this a try. In the case of playtagger, it is a javascript that looks thru the page for the mp3 extension on links. This does not work with the filebrowser listing though.

coopercrazy’s picture

I must say, I really do like the filebrowser module. I'm surprised drupal doesn't do this out of the box though.

With regard to the audio helper function-- I would find it very useful to include additional columns which can read id3 tags and the like for various audio files.

Maybe a good place to start would be apache's mod_musicindex module? I am not a coder, so I wouldn't begin to know how to add those features, but I am willing to beta test the modules you write if needed.

Thanks,
Kevin

Yoran’s picture

Status: Active » Fixed

You know have a full metadata API in order to provide all needed informations. Be carefull to cache those data in order not to reduce performances.

coopercrazy’s picture

Thanks Yoran,

I've finally gotten back to this project after some other matters.
I had also finally installed 6.x-2.x-dev branch to do some testing. After untarring the module I had several errors with my database (which I think I have successfully now recovered from). I noticed the Video and Image helper modules and attempted to use one of those as a template for the audio helper module, but I am lost.

How does one call up the metadata api for an audio helper?

I'm by no means a php coder, but I am thinking I need to do something along the following.

In pseudo code . . .

generate list of files in directory and store in a VARIABLE
for SINGLEFILE in $VARIABLE
do
getID3($SINGLEFILE)
return FIELDS with non-null values
for FIELD in $FIELDS
do
getID3_FIELD($FIELD) and store in object array
done
return ARRAY for FILE and store in CACHE
done

handoff CACHE to filebrowser module for displaying.

Let me know what you think.

Also one an unrelated note, the "Whitelist" concept is working nicely. And, in my directory listing, the "Go Up" link tends to move around and be anywhere in the list. Shouldn't it be anchored to either the top or the bottom of the directory list?

Kevin

Yoran’s picture

I just commited a dev version (it'll take someting for drupal.org to update the tarball). In this you have a filebrowser_STARTER module in which you'll find everything you need. You can focus on :

function filebrowser_STARTER_filebrowser_metadata_info() {

function filebrowser_STARTER_filebrowser_metadata_get($file) {

function filebrowser_STARTER_filebrowser_metadata_set($file, $metadata) {

I made in the header of the module a copy of what you should find in $file object.

Let me know if this is enough for you

coopercrazy’s picture

Thanks Yoran,

I will give drupal some time to post the new module for download.

I'll let you know how I'm doing.

Kevin

Status: Fixed » Closed (fixed)

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

coopercrazy’s picture

Yoran,

I've thought about what functions I would need for this.
I think there needs to be dependency on the getID3() drupal module. This is supposed to be accomplished by calling the getid3_load function.

I am thinking the functions you listed should contain something like the following (I am sure there are many errors and missing pieces):
function filebrowser_STARTER_filebrowser_metadata_info() {
$FileTag = $getID3-> analyze($file);
getid3_lib::CopyTagsToComments($FileTag);
};

function filebrowser_STARTER_filebrowser_metadata_get($file) {
return array(
'STARTER_foo' => 'artist' .$FileTag['comments_html']['artist'];
'STARTER_foo => 'genre' .$FileTag['comments_html']['genre'];
'STARTER_foo => 'title' .$FileTag['comments_html']['title'];
'STARTER_foo => 'length' .$FileTag['playtime_string'];
'STARTER_foo => 'copywright' .$FileTag['comments_html']['copywright'];
);
};

function filebrowser_STARTER_filebrowser_metadata_set($file, $metadata) {
I may be misunderstanding the purpose of this function, but I do not want to be able to modify the tags of audio files from within filebrowser.
};

Let me know what you think.
Kevin

coopercrazy’s picture

Status: Closed (fixed) » Needs review
coopercrazy’s picture

Status: Needs review » Active

Yoran,

I think I am going to need some more help with this.

Kevin

Yoran’s picture

There is just one mistake as far as I can see. The filebrowser_STARTER_filebrowser_metadata_info is here to publish metadata names to the system. Perhaps something more like this :

function filebrowser_STARTER_filebrowser_metadata_info() {
return array(
'STARTER_genre => array(
'title=>'genre' ,
'writable'=>FALSE,
'sortable'=>TRUE,
'type'=>'string'));
}

function filebrowser_STARTER_filebrowser_metadata_get($file) {
$FileTag = $getID3-> analyze($file);
getid3_lib::CopyTagsToComments($FileTag);
return array(
'STARTER_genre => $FileTag['comments_html']['genre']);
};
coopercrazy’s picture

StatusFileSize
new5.15 KB
new397 bytes

Yoran,

That helps a lot. I had to close a couple of single quotes (') to make it parse correctly. Attached the filebrowser_STARTER.info files and filebrowswer_STARTER.module files I've modified. I've enabled the module and checked the "genre" checkbox to display and created the Directory Listing page. When I attempt to view the page I get an error message:

"Fatal error: Call to a member function analyze() on a non-object in /drupal-common/sites/all/modules/filebrowser/filebrowser_STARTER/filebrowser_STARTER.module on line 99"

I don't know if this means that it is unable to find the analyze function, or if the object being referenced (i.e. $file) does not exist. Any ideas?

I can create an ordinary page in drupal with the following code and the file tags get parsed and displayed properly. So I am thinking that when I call analyze($file); that $file is not being populated with the filename to analyze. Do you have any suggestions?

getid3_load;
$filename =  'sites/default/files/myfile.mp3';
$getid3 = new getID3;
$getid3->encoding = 'UTF-8';
header('Content-Type: text/html; charset=UTF-8');
try {

    $getid3->Analyze($filename);

    // Show audio bitrate and length
    echo 'Filename: ' . print($filename) . '<br>' ;
    echo 'Bitrate:  ' . @$getid3->info['audio']['bitrate'] . '<br>'; 
    echo 'Playtime: ' . @$getid3->info['playtime_string']  . '<br>';

}
catch (Exception $e) {
    
    echo 'An error occured: ' .  $e->message;
}
Yoran’s picture

$file is a record, not only the file name. To get the filename you have to use $file['full-path']

 if (is_file($file['full-path'])) {
    $FileTag = $getID3->analyze($file['full-path']);
 }

You can have a look at filebrowser.module/filebrowser_filebrowser_metadata_get function for a concrete example (reading/writing to descript.ion files is done through metadata api).

coopercrazy’s picture

Yoran,

That is working much better. I am finally getting some of the contents of the array.
I will try to get it to where one could select which fields they would like to see displayed in the description column.

Hopefully I will post the contents of my module shortly for your testing. How do I rename it from something like filebrowser_STARTER to something like filebrowser_AUDIO? Do a global find and replace?

Kevin

Yoran’s picture

If you want me to open you a CVS access juste tell me. We can add a 'contrib' subfolder for that kind of modules

coopercrazy’s picture

I'll leave that up to you. It might make it easier to submit any changes I make using the CVS than uploading to drupal here.

I'm having some problems getting anything to show up in the description column of the directory listing. I can print the contents of the array using print_r('STARTER_title') and see it's contents so I know it is being populated with the title of the mp3 file in my directory. Do I have to do anything special to return the value of the array to the filebrowser handler? I also looked at the filebrowser.module file and didn't see anything relevant in there.

function filebrowser_STARTER_filebrowser_metadata_info() {
return array(
'STARTER_title' => array(
'title'=>'Title' ,
'writable'=>FALSE,
'sortable'=>TRUE,
'type'=>'string'));
}
function filebrowser_STARTER_filebrowser_metadata_get($file) {
getid3_load();
$getid3 = new getID3;
$getid3->encoding = 'UTF-8';
$full_path = $file['full-path'];
if (is_file($full_path'])) {
try {
$FileTags = $getid3->analyze($full_path);
getid3_lib::CopyTagsToComments($FileTags);
$artist = $FileTags['comments']['title']['0'];
//print_r($FileTags);
}
catch (Exception $e) {
echo 'An error occured: ' . $e->message;
}

return array(
'STARTER_title' => @$FileTags['comments']['title']['0']);
}
}

Kevin

coopercrazy’s picture

Just adding a post to keep the thread alive.

coopercrazy’s picture

Version: master » 6.x-2.x-dev
Yoran’s picture

Sorry for my late answer.

Did you end up with a correct handling of ID3 ?

Yoran’s picture

Status: Active » Postponed (maintainer needs more info)
coopercrazy’s picture

Nope. Never got it to work.

Nicolas Georget’s picture

Nope. Never got it to work.

@coopercrazy
I am working on the MetaDatas for Filebrowser: ID3, IPTC, EXIF, etc... and what is the best way to fetch them properly.
What's up exactly with your code getID3 ?

coopercrazy’s picture

Don't really know. I've conceeded that i dont know what i am doing.

The idea was to be able to share a directory (with filebrowser ) of media files (mp3 to be exact). The module was supposed to parse the id3 tags on all the songs in the dielrectory and display them to the user in seperate columns like artist, title, and copyright. I got it to the point where i could read the tags in from 1 file and store in a variable. I could never actually pass that variable to the filebrowser view part to be displayed. The thing with the getid3 was just the only way i could figure out to read the tag.

I actually started using the "sermons " module to display my church's messages instead of using the filebrowser module. However, i still think there is value in adding these features to filebrowser, I just don't know how to implement - seeing as how my php skills aren't so good.

Nicolas Georget’s picture

Status: Postponed (maintainer needs more info) » Reviewed & tested by the community
StatusFileSize
new275.76 KB

@coopercrazy
Here's the way to read and push the ID3 into a table(1) with filebrowser.
In this example, I push 5 Tags into a table:

  1. The name of the file, fetch by filebrowser
  2. Its size in bytes
  3. The name of the artist » Fetch by getID3
  4. Time of the song » Fetch by getID3
  5. The Title » Fetch by getID3

There's many things to review. First, i create a new object getID3 if the mime-type == 'audio/mpeg' which is in your case might match with your files.
Because the method getID3::analyze() return a huge list of metatags, it was impossible to return a form with what fields to display in the table (like filebrowser does). Third thing (1), i could not made the table sortable because... it depends of the displayed fields and a lack of time today ;-)

So, now you can create a dir_list with mp3/4. In the default view, choose "getID3 view" and try it...

coopercrazy’s picture

Thanks for the help Nicolas. I haven't had much time to work on this recently. I'll try to give it a shot this weekend.

coopercrazy’s picture

Nicolas,

I finally had a few moments to test out the getid3 filebrowser example you made ( I know its been over 2 years since you posted it for me ).

A couple of things I am planning on adding:

  • The name of the File should also be a link to the file download location.
  • The default view of "getID3 view" should recurse through a direcotry tree just like the "Folder View"

You've given me a huge jump on this and I'll hopefully post something back here in the next couple of months.

clivesj’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Closed (outdated)