Blog Detail

19

Oct
Extract Metadata From Media Files like mp3, aac in Laravel cover image

arrow_back Extract Metadata From Media Files like mp3, aac in Laravel

Laravel Getid3 is an awesome Laravel package that helps to extract metadata from media files. mp3, aac, etc. It can be used with files stored on different disks such as local disk, S3, etc.

Installation

Via Composer

You can install this package via composer by running this command:

$ composer require owen-oj/laravel-getid3

If you use Laravel 5.5+ you don’t need the following step. If not, once the package is installed, you need to register the service provider. Open config/app.php and add the following to the providers key.

Owenoj\LaravelGetId3\GetId3ServiceProvider::class,

Usage

use Owenoj\LaravelGetId3\GetId3;

//instantiate class with file
$track = new GetId3(request()->file('file'));

// Use static methods:
$track = GetId3::fromUploadedFile(request()->file('file'));
$track = GetId3::fromDiskAndPath('local', '/some/file.mp3');
$track = GetId3::fromDiskAndPath('s3', '/some/file.mp3'); // even works with S3

//get all info
$track->extractInfo();

//get title
$track->getTitle();

//get playtime
$track->getPlaytime();

We can also extract the artwork from the file

//calling this method will return artwork in base64 string
$track->getArtwork();
//Optionally you can pass `true` to the method to get a jpeg version. This will return an UploadedFile instance
$track->getArtwork(true);

Available Methods

extractInfo() : array

Get an array of all available metadata of file

getArtist() : string

Get the artist of the track

getTitle() : string

Get the title of the track

getAlbum() : string

Get name of Album

getPlaytime() : string

Get a tracks total playtime

getPlaytimeSeconds() : float

Get total playtime in seconds

getArtwork()

Get the artwork of the track

getGenres() : array

Get the list of genres

getComposer() : string

Get the composers of the track

getTrackNumber() : string

Get the track number out of total number on the album eg. 1/12

getCopyrightInfo() : string

Get copyright information of the track

getFileFormat() : string

Get the file format of the file eg. mp4

For more details, please visit Github.

Closing Note

If you have an awesome idea then Codebrisk is always here to convert your ideas into reality. Our team of expert developers is trained in Laravel custom web app development, CRM software development, and e-commerce app development. We run with a superior level of agility and an immense Laravel ecosystem to customize the software for your business. For further assistance, please contact us or you can launch a project with us.

Published at : 19-10-2022

Author : Rizwan Aslam
AUTHOR
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project