Welcome Guest, Not a member yet? Register   Sign In
Trouble loading getID3 library
#1

First post. I've deployed a couple sites running a CI framework, but now I am creating my first from scratch so bare with me. 



I would like to determine the length of a audio/video file after a user upload and a quick search online landed me with the getID3 library. Downloadeded the library (github) and placed it in my ThirdParty directory, but I am having trouble creating a getID3 object.



1) I created a test script my public_html.

Code:
require '../app/ThirdParty/getid3/getid3.php';
$getID3 = new getID3;
if(!file_exists("test.flac")){
    exit("File not found");
}
$file = $getID3->analyze("test.flac");
$duration_string = $file['playtime_string'];
echo $duration_string;

The script runs as expected, it outputs the length of the audio file. Great!



2) I tried loading the getID3 library from my controller 'app/Controllers/Job.php' (Note: showOrderForm functions as normal without getID3 and outputs a form for the user): 



Code:
private function showOrderForm($job){
    require_once APPPATH . "/ThirdParty/getid3/getid3.php";
    $getID3 = new getID3;
    // ...
}


But when I run the controller (while in development mode) I get the following error:

Code:
Class "App\Controllers\getID3" not found


Why is ci4 trying to load a controller?



3) I noticed that the getid3.php does not delcare a namespace, so I added 'namespace GetID3;' to the top of their script. Then modified my controller to include the namespace:



Code:
private function showOrderForm($job){
    require_once APPPATH . "/ThirdParty/getid3/getid3.php";
    $getID3 = new GetID3/getID3;
    // ...
}


but now I get another error:



Code:
Class "GetID3\Exception" not found
class getid3_exception extends Exception
{
    public $message;
}


So it looks like adding a namespace broke the getID3 library. Is there anyway to load this library without going through and adding namespaces to all their files? I understand this may not be a ci4 issue, but their library works outside ci4. I also know that the getID3 library does not follow ci4's naming convention with the Capitization of the class name, would this br the problem (I've tried unsucessfully renaming class names and direcory name).

Any help would be appreciated. Thanks!
~Pard
Reply
#2

Did you try to autoload the library using the Classmap?

CodeIgniter4 User Guide - Overview - Autoloading Files - Classmap
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Code:
If you use third-party libraries that are not Composer packages and are not namespaced, you can load those classes using the classmap:

Adding the 'non-composer' getID3 library to the classmap fixed the issue. Thank you InsiteFX
Reply
#4

Your Welcome.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB