Jump to content

using getid3 inside module


Macrura
 Share

Recommended Posts

Hi -

I was able to read id3 tags from audio files very easily using this library and the api, but now i'm stuck trying to get this to work inside a module;

in my api test, i just did this:

$templates = $config->paths->templates;
require_once("{$templates}tools/getid3/getid3.php");

$getID3 = new getID3;
$album = $pages->get(2130);

foreach($album->children as $track) {
	$audio = $track->audio_file_p;
	
	// Analyze file and store returned data in $track->tags
	$track->tags = $getID3->analyze($audio->filename);

	echo $track->tags['tags']['id3v2']['title'][0];  
	echo $track->tags['tags']['id3v2']['artist'][0];
	echo $track->tags['tags']['id3v2']['track_number'][0];
	echo $track->tags['audio']['bitrate']; 
	echo $track->tags['playtime_string']; 
}

but now in trying to get this to work inside a module, i can't get the id3 to return the array, not sure what I'm doing wrong... this code is within a method that runs on a saveReady hook:

<?php	

	require_once(dirname(__FILE__) . '/getid3.php'); 

	$getID3 = new getID3;
			
	$file = $page->audio_files->first();
	$tags = $getID3->analyze($file->filename);
	$title = $tags['tags']['id3v2']['title'][0]; 
	$this->message($title);

I did a print_r into a spare field on the $page but it only returned the number 1..

i guess there is something that isn't quite right about the file path or the way the classes are working together?

thanks!

Link to comment
Share on other sites

solved: i failed to put the full folder of the getid3, i had just copied only the main class file..

major facepalm

@adrian - forgot to thank you for helping.. (was actually replying to your post when the solution dawned on me..)

by the way, this is pretty awesome, now i can read id3 tags and create pages based on those tags;

also prevent users from uploading mp3 files where the bitrate is too high (in order to keep the filesizes small we use 128 for streaming files)...

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...