-
Notifications
You must be signed in to change notification settings - Fork 0
/
SongReader.php
75 lines (63 loc) · 1.08 KB
/
SongReader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Created by PhpStorm.
* User: Azathoth
* Date: 21. 3. 2016
* Time: 17:39
*/
class SongReader
{
/** @var string */
private $duration;
/** @var string */
private $author;
/** @var string */
private $title;
/** @var string */
private $album;
/**
* Song constructor.
* @param string $path
*/
public function __construct(string $path)
{
$this->loadInfo($path);
}
private function loadInfo(string $path)
{
$getID3 = new getID3();
$info = $getID3->analyze("$path");
$this->author = $info['tags']['id3v1']['artist'][0] ?? null;
$this->title = $info['tags']['id3v1']['title'][0] ?? null;
$this->album = $info['tags']['id3v1']['album'][0] ?? null;
$this->duration = $info['playtime_string'] ?? null;
}
/**
* @return string
*/
public function getDuration()
{
return $this->duration;
}
/**
* @return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @return string
*/
public function getAlbum()
{
return $this->album;
}
}