Reputation: 285
I'm trying to change the track details of an mp3 file with the getID3 library, which I then want to save to a directory.
How do I save the files after the tags have been written?
<?php
$remotefilename = 'http://musicbaap.com/public/music/Same-Beef-[Original]-Sidhu-Moose-Wala.mp3';
if ($fp_remote = fopen($remotefilename, 'rb')) {
$localtempfilename = tempnam('/tmp', 'getID3');
if ($fp_local = fopen($localtempfilename, 'wb')) {
while ($buffer = fread($fp_remote, 8192)) {
fwrite($fp_local, $buffer);
}
fclose($fp_local);
$getID3 = new \getID3;
$tagwriter = new \getid3_writetags;
$tagwriter->filename = $localtempfilename;
$tagwriter->tagformats = array('id3v1', 'id3v2.3');
// set various options (optional)
$tagwriter->overwrite_tags = true;
$getID3->encoding = 'UTF-8';
$tagwriter->tag_encoding = 'UTF-8';
$tagwriter->remove_other_tags = true;
// populate data array
$TagData['title'][] = 'My Song';
$TagData['artist'][] = 'The Artist';
$TagData['album'][] = 'Greatest Hits';
$TagData['year'][] = '2004';
$tagwriter->tag_data = $TagData;
// write tags
if ($tagwriter->WriteTags()) {
echo 'Successfully wrote tags<br>';
if (!empty($tagwriter->warnings)) {
echo 'There were some warnings:<br>'.implode('<br><br>', $tagwriter->warnings);
}
} else {
echo 'Failed to write tags!<br>'.implode('<br><br>', $tagwriter->errors);
}
// dd($tagwriter);
}
fclose($fp_remote);
}
Upvotes: 0
Views: 115
Reputation: 1273
The file has the tags written to after the method has been called.
$localtempfilename = tempnam('/tmp', 'getID3');
Here is where you place the file on your machine, this is also where the file is "saved". When you've done everything you've wanted then the changes will be saved to this file.
Upvotes: 1