<?php
/*
* Author : ShubhaM
* Posted at http://www.w3tools.info/2012/02/php-function-to-edit-mp3-tags.html
* Visit for more.
*/
/* Prepare an array that holds tag info */
$data = array(
"mp3_songname" => "", // Song's name. Leave this blank to keep original song name
"mp3_artist" => "w3tools",// Artist's name.
"mp3_album" => "w3tools", // Album's name.
"mp3_year" => "2011", // Song's year.
"mp3_genre" => "w3tools", // Genre.
"mp3_comment" => "Visit w3tools.info ", // Some comment on song.
"mp3_image" => array(
"path" => "../albumart.jpg", // Albumart image must be present at this path.
"type" => "image/jpeg", // Albumart image's mime type.
"name" => "albumart.jpg" // Albumart image's name.
)
);
/* The function for mp3 tag processing */
function write_tags($mp3_file,$data=""){
if(!is_file($mp3_file))return false;
$mp3_tagformat = 'UTF-8';
require_once('getid3/getid3.php');
$mp3_handler = new getID3;
$mp3_handler->setOption(array('encoding'=>$mp3_tagformat));
require_once('getid3/write.php');
$mp3_writter = new getid3_writetags;
$mp3_writter->filename = $mp3_file;
$mp3_writter->tagformats = array('id3v1', 'id3v2.3');
$mp3_writter->overwrite_tags = true;
$mp3_writter->tag_encoding = $mp3_tagformat;
$mp3_writter->remove_other_tags = false;
$mp3_data['title'][] = $data['mp3_songname'];
$mp3_data['artist'][] = $data['mp3_artist'];
$mp3_data['album'][] = $data['mp3_album'];
$mp3_data['year'][] = $data['mp3_year'];
$mp3_data['genre'][] = $data['mp3_genre'];
$mp3_data['comment'][] = $data['mp3_comment'];
$mp3_data['attached_picture'][0]['data'] = file_get_contents($data['mp3_image']['path']);
$mp3_data['attached_picture'][0]['picturetypeid'] = $data['mp3_image']['type'];
$mp3_data['attached_picture'][0]['description'] = $data['mp3_image']['name'];
$mp3_data['attached_picture'][0]['mime'] = $data['mp3_image']['type'];
$mp3_writter->tag_data = $mp3_data;
$mp3_writter->WriteTags();
}
/* End of function */
/* Call the function */
write_tags("../my_song.mp3",$data);
?>