Hi guys
What it is I am finding difficulty with is extracting the album art from a mp3 file.
I have tried to do it in FLASH, to no avail.
I have now turned to PHP and unknown to me the PHP code that I use has the capability to extract the exact data that I need from the mp3 file.
This is the code I use at present to generate the XML playlist.
<?php
require_once('getid3/getid3.php');
$dir = $_GET['folder'];
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<XML>";
$getID3 = new getID3;
$DirectoryToScan = $dir;
$dirHandle = opendir($dir);
$strIsNull = "not found";
$i = 0;
while (($file = readdir($dirHandle)) !== false) {
$FullFileName = realpath($dir.'/'.$file);
if ((substr($FullFileName, 0, 1) != '.') && is_file($FullFileName)) {
$i++;
set_time_limit(30);
$ThisFileInfo = $getID3->analyze($DirectoryToScan.'/'.$i.'.mp3');
getid3_lib::CopyTagsToComments($ThisFileInfo);
$xmlBody .= '<song>';
/// SONG.NUMBER ///
$xmlBody .= '<songNumber>' . $i . '</songNumber>
/// SONG.URL ///
<songURL>' . basename($ThisFileInfo['filenamepath']) . '</songURL>
/// SONG.ARTIST ///
<songArtist>' . (!empty($ThisFileInfo['comments_html']['artist']) ? implode('<br>',$ThisFileInfo['comments_html'][ 'artist']) : $strIsNull) . '</songArtist>
/// SONG.TITLE ///
<songTitle>' . (!empty($ThisFileInfo['comments_html']['title']) ?implode('<br>', $ThisFileInfo['comments_html']['title']) : $strIsNull) . '</songTitle>
/// SONG.BITRATE ///
<songBitrate>' . round($ThisFileInfo['audio']['bitrate'] / 1000) . '</songBitrate>
/// SONG.DURATION ///
<songDuration>' . $ThisFileInfo['playtime_string'] . '</songDuration>';
$xmlBody .= '</song>';
}
}
$xmlBody .= "</XML>";
header('Content-type: text/xml');
echo $xmlBody;
?>
All I want to do as it reads the id3tag I want it to save the album art to a file ie… 1.jpg 2.jpg
Here is the code I have tried
$i = 0;
while (($file = readdir($dirHandle)) !== false) {
$FullFileName = realpath($dir.'/'.$file);
if ((substr($FullFileName, 0, 1) != '.') && is_file($FullFileName)) {
$i++;
set_time_limit(30);
$ThisFileInfo = $getID3->analyze($DirectoryToScan);
if(isset($ThisFileInfo['comments']['picture'][0])){$Image='data:'.$ThisFileInfo['comments']['picture'][0]['image_mime'].';charset=utf-8;base64,'.base64_encode($ThisFileInfo['comments']['picture'][0]['data']);
}
file_put_contents($DirectoryToScan+"/ALBUMART/"+ $i + ".jpg", $image);
}
}
I know its wrong but hope someone can help
Thanks
Steven