Coder Social home page Coder Social logo

owen-oj / laravel-getid3 Goto Github PK

View Code? Open in Web Editor NEW
78.0 3.0 12.0 177 KB

A Laravel package 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.

License: MIT License

PHP 100.00%
laravel getid3 audio music file-metadata audio-metadata laravel-getid3 id3v2 id3 id3v1

laravel-getid3's Introduction

laravel-getid3

Latest Version on Packagist Total Downloads StyleCI

This package is a wrapper around james-heinrich/getid3.

"Buy Me A Coffee"

Installation

Via Composer

$ composer require owen-oj/laravel-getid3

If you use Laravel 5.5+ you don't need the following step. If not, once 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 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 album eg. 1/12

getCopyrightInfo() : string

Get copyright information of the track

getFileFormat() : string

Get the file format of the file eg. mp4

Change log

Please see the changelog for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

laravel-getid3's People

Contributors

bumbummen99 avatar dependabot[bot] avatar laravel-shift avatar mrtawil avatar nvahalik avatar owen-oj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel-getid3's Issues

Changing ID3 to MP3

Hello.
Is it possible to change the received data and save it to mp3 using PHP?

Undefined array key "comments"

This package works fine on Laravel 9, except for this:

Seeding: Database\Seeders\SongSeeder

   ErrorException 

  Undefined array key "comments"

  at vendor/owen-oj/laravel-getid3/src/GetId3.php:101
     97▕      * @throws \getid3_exception
     98▕      */
     99▕     private function comments()
    100▕     {
  ➜ 101▕         return $this->extractInfo()['comments'];
    102▕     }
    103▕ 
    104▕     /**
    105▕      * Get the title of the media file.

      +2 vendor frames 
  3   database/seeders/SongSeeder.php:31
      Owenoj\LaravelGetId3\GetId3::getArtist()

      +8 vendor frames 
  12  database/seeders/DatabaseSeeder.php:17
      Illuminate\Database\Seeder::call()

This is my seeder:

        $files = Storage::disk('musicas')->allFiles();
        sort($files);

        foreach ($files as $file) {
            if (!Song::find($file)) {

                $filename = basename($file, ".mp3");
                $filepath = Storage::disk('musicas')->path($file);
                $track = new GetId3($filepath);
                $artist = $track->getArtist();
                $title = $track->getTitle();
                $playtime = $track->getPlaytime();

                Song::create([
                    'artist' => $artist,
                    'title' => $title,
                    'playtime' => $playtime,
                    'filename' => $filename,
                    'filesize' => Storage::disk('musicas')->size($file),
                    'filepath' => $filepath,
                    'last_modified' => Storage::disk('musicas')->lastModified($file),
                ]);
            }
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.