Fix isValidAudio()
Signed-off-by: Markus Birth <markus@birth-online.de>
This commit is contained in:
parent
120617847c
commit
48edb42c1e
@ -1021,19 +1021,33 @@ class Mp3Info {
|
|||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function isValidAudio($filename) {
|
public static function isValidAudio($filename) {
|
||||||
if (!file_exists($filename) && strpos($filename, '://') == false) {
|
if (str_contains($filename, '://')) {
|
||||||
throw new Exception('File ' . $filename . ' is not present!');
|
$fileObj = new Mp3FileRemote($filename);
|
||||||
|
} else {
|
||||||
|
if (!file_exists($filename)) {
|
||||||
|
throw new Exception('File ' . $filename . ' is not present!');
|
||||||
|
}
|
||||||
|
$fileObj = new Mp3FileLocal($filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$filesize = file_exists($filename) ? filesize($filename) : static::getUrlContentLength($filename);
|
$filesize = $fileObj->getFileSize();
|
||||||
|
|
||||||
$raw = file_get_contents($filename, false, null, 0, 3);
|
$raw = $fileObj->getBytes(3);
|
||||||
return $raw === self::TAG2_SYNC // id3v2 tag
|
if ($raw === self::TAG2_SYNC) {
|
||||||
|| (self::FRAME_SYNC === (unpack('n*', $raw)[1] & self::FRAME_SYNC)) // mpeg header tag
|
// id3v2 tag
|
||||||
|| (
|
return true;
|
||||||
$filesize > 128
|
}
|
||||||
&& file_get_contents($filename, false, null, -128, 3) === self::TAG1_SYNC
|
if (self::FRAME_SYNC === (unpack('n*', $raw)[1] & self::FRAME_SYNC)) {
|
||||||
) // id3v1 tag
|
// mpeg header tag
|
||||||
;
|
return true;
|
||||||
|
}
|
||||||
|
if ($filesize > 128) {
|
||||||
|
$fileObj->seekTo($filesize - 128);
|
||||||
|
if ($fileObj->getBytes(3) === self::TAG1_SYNC) {
|
||||||
|
// id3v1 tag
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user