Skip to content

Commit 4c118fe

Browse files
authored
Merge pull request #6 from 1stphorm/master
Cleanup + enable remote reading
2 parents a5fcd26 + 5f42824 commit 4c118fe

File tree

5 files changed

+50
-72
lines changed

5 files changed

+50
-72
lines changed

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

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

5+
## master
6+
7+
### Added
8+
- fromUploadedFile() static helper
9+
- fromDiskAndPath() static helper
10+
- extractInfo() output is now cached
11+
512
## Version 1.0
613

714
### Added

config/laravel-getid3.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

readme.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,19 @@ use Owenoj\LaravelGetId3\GetId3;
2626
//instantiate class with file
2727
$track = new GetId3(request()->file('file'));
2828

29+
// Use static methods:
30+
$track = GetId3::fromUploadedFile(request()->file('file'));
31+
$track = GetId3::fromDiskAndPath('local', '/some/file.mp3');
32+
$track = GetId3::fromDiskAndPath('s3', '/some/file.mp3'); // even works with S3
33+
2934
//get all info
30-
$track->extractInfo()
35+
$track->extractInfo();
3136

3237
//get title
33-
$track->getTitle()
38+
$track->getTitle();
3439

3540
//get playtime
36-
$track->getPlaytime()
41+
$track->getPlaytime();
3742
```
3843

3944
We can also extract the artwork from the file

src/GetId3.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,38 @@
33
namespace Owenoj\LaravelGetId3;
44

55
use Illuminate\Http\UploadedFile;
6+
use Illuminate\Support\Facades\Storage;
67
use Illuminate\Support\Str;
78

89
class GetId3
910
{
1011
protected $file;
1112

12-
public function __construct(UploadedFile $file)
13+
protected $filesize;
14+
15+
protected $fp;
16+
17+
private $_info;
18+
19+
public function __construct($filename, $filesize = null, $fp = null)
20+
{
21+
$this->file = $filename;
22+
$this->filesize = $filesize;
23+
$this->fp = $fp;
24+
}
25+
26+
public static function fromUploadedFile(UploadedFile $file)
27+
{
28+
return new static($file);
29+
}
30+
31+
public static function fromDiskAndPath($disk, $path)
1332
{
14-
$this->file = $file;
33+
return new static(
34+
$path,
35+
Storage::disk($disk)->getSize($path),
36+
Storage::disk($disk)->readStream($path)
37+
);
1538
}
1639

1740
/**
@@ -31,10 +54,19 @@ private function getId3()
3154
* @throws \getid3_exception
3255
*/
3356
public function extractInfo()
57+
{
58+
if (! isset($this->_info)) {
59+
$this->_info = $this->analyze();
60+
}
61+
62+
return $this->_info;
63+
}
64+
65+
private function analyze()
3466
{
3567
$comments = ['comments' => []];
3668

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

3971
//if comments doesn't exist, we will add it ourselves
4072
isset($info['comments']) ? $info['comments'] : ($info + $comments);

src/GetId3ServiceProvider.php

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,79 +6,18 @@
66

77
class GetId3ServiceProvider extends ServiceProvider
88
{
9-
/**
10-
* Perform post-registration booting of services.
11-
*
12-
* @return void
13-
*/
14-
public function boot()
15-
{
16-
// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'owen-oj');
17-
// $this->loadViewsFrom(__DIR__.'/../resources/views', 'owen-oj');
18-
// $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
19-
// $this->loadRoutesFrom(__DIR__.'/routes.php');
20-
21-
// Publishing is only necessary when using the CLI.
22-
if ($this->app->runningInConsole()) {
23-
$this->bootForConsole();
24-
}
25-
}
26-
279
/**
2810
* Register any package services.
2911
*
3012
* @return void
3113
*/
3214
public function register()
3315
{
34-
$this->mergeConfigFrom(__DIR__.'/../config/laravel-getid3.php', 'laravel-getid3');
35-
3616
// Register the service the package provides.
3717
$this->app->singleton('GetId3', function ($app) {
3818
return new GetId3();
3919
});
4020

4121
$this->app->alias('GetId3', 'Owenoj\LaravelGetId3\GetId3');
4222
}
43-
44-
/**
45-
* Get the services provided by the provider.
46-
*
47-
* @return array
48-
*/
49-
public function provides()
50-
{
51-
return ['laravel-getid3'];
52-
}
53-
54-
/**
55-
* Console-specific booting.
56-
*
57-
* @return void
58-
*/
59-
protected function bootForConsole()
60-
{
61-
// Publishing the configuration file.
62-
$this->publishes([
63-
__DIR__.'/../config/laravel-getid3.php' => config_path('laravel-getid3.php'),
64-
], 'laravel-getid3.config');
65-
66-
// Publishing the views.
67-
/*$this->publishes([
68-
__DIR__.'/../resources/views' => base_path('resources/views/vendor/owen-oj'),
69-
], 'laravel-getid3.views');*/
70-
71-
// Publishing assets.
72-
/*$this->publishes([
73-
__DIR__.'/../resources/assets' => public_path('vendor/owen-oj'),
74-
], 'laravel-getid3.views');*/
75-
76-
// Publishing the translation files.
77-
/*$this->publishes([
78-
__DIR__.'/../resources/lang' => resource_path('lang/vendor/owen-oj'),
79-
], 'laravel-getid3.views');*/
80-
81-
// Registering package commands.
82-
// $this->commands([]);
83-
}
8423
}

0 commit comments

Comments
 (0)