Reputation: 51
I found a website recently that allows you to upload a file and change its ID3 tags (Image, Title, all that other stuff) and currently I am storing files in a directory after I parse them from another website before pushing them externally.
I am wondering if someone knows a library where I can read how to change the default ID3 tags in PHP? Is this a already existing feature with PHP?
Upvotes: 0
Views: 4068
Reputation: 113
I have recently made a PHP wrapper for eyeD3, a great python module for reading and updating ID3 metadata. Check it out here.
Usage is pretty simple if you're familiar with Composer. However, you will need to install eyed3 in order to use it. Then:
Install the php wrapper using composer:
composer require stormiix/php-eyed3 dev-master
Add the library to your code:
require __DIR__ . '/vendor/autoload.php';
Use the following code to read & update tags.
use Stormiix\EyeD3\EyeD3;
$eyed3 = new EyeD3("mp3 file path");
$tags = $eyed3->readMeta();
// $tags is an array that contains the following keys:
// artist, title, album, comment(s), lyrics ..etc
$meta = [
"artist" => "MyArtist",
"title" => "MyTitle",
"album" => "MyAlbum",
"comment" => "MyComment",
"lyrics" => "MyLyrics",
"album_art" => "cover.png"
];
// Update the mp3 file with the new meta tags
$eyed3->updateMeta($meta);
Upvotes: 0
Reputation: 689
if( writeTags($row['title'],$new) ) {
$fileName = rand(000000000,999999999).'_'.rand(0000000000,9999999999).'_'.rand(000000000,999999999).'.mp3';
$imageName = rand(000000000,999999999).'_'.rand(0000000000,9999999999).'_'.rand(000000000,999999999).'.jpg';
rename($new, $DPATH.'uploads/tracks/'.$fileName);
save_image($row['image'],$DPATH.'uploads/media/'.$imageName);
$track['uid'] = 151;
$track['title'] = $row['title'];
$track['description'] = '';
# fileName
$track['name'] = $fileName;
# make tag
$track['tag'] = $tag.',';
# download image
$track['art'] = $imageName;
# today date
$track['release'] = date("Y-m-d");
$track['size'] = filesize($DPATH.'uploads/tracks/'.$fileName);
$row['slippery_id'] = add_to_slippery($track);
}
function writeTags($title,$file) {
$TextEncoding = 'UTF-8';
require_once($DPATH.'cron/getid3/getid3.php');
$getID3 = new getID3;
$getID3->setOption(array('encoding'=>$TextEncoding));
require_once($DPATH.'cron/getid3/write.php');
$tagwriter = new getid3_writetags;
$tagwriter->filename = $file;
$tagwriter->tagformats = array('id3v1','id3v2.3');
$tagwriter->overwrite_tags = true;
$tagwriter->tag_encoding = $TextEncoding;
$tagwriter->remove_other_tags = true;
$TagData = array(
'album' => array($MP3TAG),
'comment' => array($MP3TAG),
);
$fd = fopen($DPATH.'cron/mp3image.png', 'rb');
$APICdata = fread($fd, filesize($DPATH.'cron/mp3image.png'));
fclose($fd);
$TagData['attached_picture'][0]['data'] = $APICdata;
$TagData['attached_picture'][0]['picturetypeid'] = 2;
$TagData['attached_picture'][0]['description'] = $MP3TAG;
$TagData['attached_picture'][0]['mime'] = 'image/jpeg';
$tagwriter->tag_data = $TagData;
if ($tagwriter->WriteTags()) {
return true;
} else {
return false;
}
}
I recently did something similar, you can edit the above code to match your requirements, if you wanted me to be more helpful you should have provided your own code within your question.
Please note that asking questions like this is often how your questions get shut down, good luck in the future and I hope this helps you.
EDIT: Use this GitHub for getting the ID3 tags.
Upvotes: 3