Skip to content

Commit

Permalink
Merge pull request #6 from 1stphorm/master
Browse files Browse the repository at this point in the history
Cleanup + enable remote reading
  • Loading branch information
Owen-oj authored Jan 23, 2021
2 parents a5fcd26 + 5f42824 commit 4c118fe
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 72 deletions.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to `laravel-getid3` will be documented in this file.

## master

### Added
- fromUploadedFile() static helper
- fromDiskAndPath() static helper
- extractInfo() output is now cached

## Version 1.0

### Added
Expand Down
5 changes: 0 additions & 5 deletions config/laravel-getid3.php

This file was deleted.

11 changes: 8 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ 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()
$track->extractInfo();

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

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

We can also extract the artwork from the file
Expand Down
38 changes: 35 additions & 3 deletions src/GetId3.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,38 @@
namespace Owenoj\LaravelGetId3;

use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

class GetId3
{
protected $file;

public function __construct(UploadedFile $file)
protected $filesize;

protected $fp;

private $_info;

public function __construct($filename, $filesize = null, $fp = null)
{
$this->file = $filename;
$this->filesize = $filesize;
$this->fp = $fp;
}

public static function fromUploadedFile(UploadedFile $file)
{
return new static($file);
}

public static function fromDiskAndPath($disk, $path)
{
$this->file = $file;
return new static(
$path,
Storage::disk($disk)->getSize($path),
Storage::disk($disk)->readStream($path)
);
}

/**
Expand All @@ -31,10 +54,19 @@ private function getId3()
* @throws \getid3_exception
*/
public function extractInfo()
{
if (! isset($this->_info)) {
$this->_info = $this->analyze();
}

return $this->_info;
}

private function analyze()
{
$comments = ['comments' => []];

$info = $this->getId3()->analyze($this->file);
$info = $this->getId3()->analyze($this->file, $this->filesize, '', $this->fp);

//if comments doesn't exist, we will add it ourselves
isset($info['comments']) ? $info['comments'] : ($info + $comments);
Expand Down
61 changes: 0 additions & 61 deletions src/GetId3ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,18 @@

class GetId3ServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'owen-oj');
// $this->loadViewsFrom(__DIR__.'/../resources/views', 'owen-oj');
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
// $this->loadRoutesFrom(__DIR__.'/routes.php');

// Publishing is only necessary when using the CLI.
if ($this->app->runningInConsole()) {
$this->bootForConsole();
}
}

/**
* Register any package services.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/laravel-getid3.php', 'laravel-getid3');

// Register the service the package provides.
$this->app->singleton('GetId3', function ($app) {
return new GetId3();
});

$this->app->alias('GetId3', 'Owenoj\LaravelGetId3\GetId3');
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['laravel-getid3'];
}

/**
* Console-specific booting.
*
* @return void
*/
protected function bootForConsole()
{
// Publishing the configuration file.
$this->publishes([
__DIR__.'/../config/laravel-getid3.php' => config_path('laravel-getid3.php'),
], 'laravel-getid3.config');

// Publishing the views.
/*$this->publishes([
__DIR__.'/../resources/views' => base_path('resources/views/vendor/owen-oj'),
], 'laravel-getid3.views');*/

// Publishing assets.
/*$this->publishes([
__DIR__.'/../resources/assets' => public_path('vendor/owen-oj'),
], 'laravel-getid3.views');*/

// Publishing the translation files.
/*$this->publishes([
__DIR__.'/../resources/lang' => resource_path('lang/vendor/owen-oj'),
], 'laravel-getid3.views');*/

// Registering package commands.
// $this->commands([]);
}
}

0 comments on commit 4c118fe

Please sign in to comment.