Quick Search for:  in language:    
MP3,script,will,take,file,with,ID3v2,Tags,wan
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
PHP Stats

 Code: 113,010. lines
 Jobs: 41. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login





Latest Code Ticker for PHP.
Simplest Web-Counter
By Kamran Riaz on 1/18


Easy Webcomic System
By Kyle Temkin on 1/17


Click here to see a screenshot of this code!AutoIndex PHP Script (Directory Indexer)
By J J H on 1/17

(Screen Shot)

DB Selector
By Martyn Merrett on 1/17


MapQuest Link Generator
By Steve Schoenfeld on 1/15


Click here to see a screenshot of this code!A Simple FTP Solution
By Marcelo Valle Franco on 1/15

(Screen Shot)

Web Blog / Content Updater
By Matthew Sparrow on 1/14


Current Users Online v1
By Robert Peterson on 1/13


Click here to see a screenshot of this code!Blobsy : MSN Messenger Bot
By JawishHameed on 1/12

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

AcidicChip's MP3 ID3v2 Tag Writer 1.0

Print
Email
 
VB icon
Submitted on: 8/14/2002 3:40:16 PM
By: AcidicChip  
Level: Beginner
User Rating: Unrated
Compatibility:PHP 3.0, PHP 4.0

Users have accessed this code 3702 times.
 

(About the author)
 
     This script will take an MP3 file, with the ID3v2 Tags you want and output them into a single MP3 file to download. This script will *NOT* edit the MP3 file itself.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    //**************************************
    //     
    // Name: AcidicChip's MP3 ID3v2 Tag Writ
    //     er 1.0
    // Description:This script will take an 
    //     MP3 file, with the ID3v2 Tags you want a
    //     nd output them into a single MP3 file to
    //     download. This script will *NOT* edit th
    //     e MP3 file itself.
    // By: AcidicChip
    //
    //This code is copyrighted and has    // limited warranties.Please see http://
    //     www.Planet-Source-Code.com/vb/scripts/Sh
    //     owCode.asp?txtCodeId=710&lngWId;=8    //for details.    //**************************************
    //     
    
    <?
    	// Script Name: AcidicChip's MP3 ID3v2 Tag Writer 1.0
    	//
    	// Script Author: Chance O. One (acidicchip@acidicchip.com)
    	//
    	// Script Description: This script will take an MP3 file, with the ID3v2 Tags you want and output them into 
    	// a single MP3 file to download. This script will *NOT* edit the MP3 file itself. If 
    	// you wish to make this script write the tags to the physical file, instead of the file 
    	// that it outputs to download, you will have to make the changes yourself. Please do 
    	// not e-mail me, asking me how to do it. Feel free to e-mail me, and let me know of 
    	// any bugs it may have.
    	//
    	// Author's Note: I tried to make this script as easy as possible, so that even newbies can understand it.
    	//But if there is something that you don't understand, go ahead and e-mail me, and I'll 
    	//help you understand it the best I can. 
    	// Change the line below to the path of your MP3 file. eg: $MP3 = "music/mp3/file.mp3";
    	$MP3 = "TetrisXP.mp3";
    	// The function below is a reverse function of bin2hex. It will convert hex to binary.
    	function hex2bin($data) {
    		$len = strlen($data);
    		for($i=0;$i<$len;$i+=2) {
    			$newdata .= pack("C",hexdec(substr($data,$i,2)));
    		}
    		return $newdata;
    	}
    	// Change the variable values below to what you want for the ID3v2 Tags.
    	$TrackNum = "01";
    	$Title = "This is the title";
    	$Artist	= "This is the artist";
    	$Album = "This is the album";
    	$Year = "2002";
    	$Genre = "This is the genre";
    	$Comment = "This is the comment";
    	$Composer = "This is the composer";
    	$OrigArtist = "This is the original artist";
    	$Copyright = "This is the copyright";
    	$URL = "This is the url";
    	$EncodedBy = "This is the encoded by";
    	// The variables below are converting the values you entered for the tags (above) into hex, in order to 
    	// have a better reassurance that your MP3 won't sound funny.
    	$TrackNumHEX = bin2hex($TrackNum);
    	$TitleHEX = bin2hex($Title);
    	$ArtistHEX	= bin2hex($Artist);
    	$AlbumHEX = bin2hex($Album);
    	$YearHEX = bin2hex($Year);
    	$GenreHEX = bin2hex($Genre);
    	$CommentHEX = bin2hex($Comment);
    	$ComposerHEX = bin2hex($Composer);
    	$OrigArtistHEX = bin2hex($OrigArtist);
    	$CopyrightHEX = bin2hex($Copyright);
    	$URLHEX = bin2hex($URL);
    	$EncodedByHEX = bin2hex($EncodedBy);
    	// The variables below are creating a hex value for the length of each of the values you entered for the 
    	// tags (above).
    	$TrackNumLenHEX = bin2hex(chr((strlen($TrackNum) + 1)));
    	$TitleLenHEX = bin2hex(chr((strlen($Title) + 1)));
    	$ArtistLenHEX	= bin2hex(chr((strlen($Artist) + 1)));
    	$AlbumLenHEX = bin2hex(chr((strlen($Album) + 1)));;
    	$YearLenHEX = bin2hex(chr((strlen($Year) + 1)));;
    	$GenreLenHEX = bin2hex(chr((strlen($Genre) + 1)));
    	$CommentLenHEX = bin2hex(chr((strlen($Comment) + 5)));
    	$ComposerLenHEX = bin2hex(chr((strlen($Composer) + 1)));
    	$OrigArtistLenHEX = bin2hex(chr((strlen($OrigArtist) + 1)));
    	$CopyrightLenHEX = bin2hex(chr((strlen($Copyright) + 1)));
    	$URLLenHEX = bin2hex(chr((strlen($URL) + 2)));
    	$EncodedByLenHEX = bin2hex(chr((strlen($EncodedBy) + 1)));
    	// The lines below is the creation of the ID3v2 tags. The tags are usually in this hex format:
    	// XXXXXXXX000000YY0000ZZZZZZZZZZZZZZZZZZZZ
    	// X = The marking for the tag, telling the MP3 player that this tag is right here
    	// Y = The length of the text inputted for the tag (Usually +1)
    	// Z = The content of the tag
    	$Data = "49443303000000000E7A";
    	$Data .= "5452434B000000" . $TrackNumLenHEX . "000000" . $TrackNumHEX;
    	$Data .= "54454E43000000" . $EncodedByLenHEX . "400000" . $EncodedByHEX;
    	$Data .= "57585858000000" . $URLLenHEX . "00000000" . $URLHEX;
    	$Data .= "54434F50000000" . $CopyrightLenHEX . "000000" . $CopyrightHEX;
    	$Data .= "544F5045000000" . $OrigArtistLenHEX . "000000" . $OrigArtistHEX;
    	$Data .= "54434F4D000000" . $ComposerLenHEX . "000000" . $ComposerHEX;
    	$Data .= "434F4D4D000000" . $CommentLenHEX . "00000000000000" . $CommentHEX;
    	$Data .= "54434F4E000000" . $GenreLenHEX . "000000" . $GenreHEX;
    	$Data .= "54594552000000" . $YearLenHEX . "000000" . $YearHEX;
    	$Data .= "54414C42000000" . $AlbumLenHEX . "000000" . $AlbumHEX;
    	$Data .= "54504531000000" . $ArtistLenHEX . "000000" . $ArtistHEX;
    	$Data .= "54495432000000" . $TitleLenHEX . "000000" . $TitleHEX;
    	// The ID3v2 Tags are EXACTLY 2048 bytes, no matter what. The lines below are filling in the remaining 2048 
    	// bytes (4096 HEX character).
    	$FillIn = (4096 - strlen($Data));
    	$Data .= str_repeat("0", $FillIn);
    	// The lines below are checking to see if an ID3v2 tag already exists in the MP3.
    	$MusicFile = fopen($MP3, "r");
    	If (fread($MusicFile, 3) == "ID3") {
    		// If the ID3v2 tag does exist, this line tells it to start the file read after 2048 bytes (The length 
    		// of the ID3v2 tags.)
    		fseek($MusicFile, 2048);
    	}
    	// The line below is converting the tags from HEX to binary.
    	$FinalOutput = hex2bin($Data);
    	// The line below is telling your browser that the data that is going to be sent is an MP3 file to download 
    	// (or play)
    	header("Content-Type: audio/mp3");
    	// The line below is uploading your ID3v2 tags.
    	echo($FinalOutput);
    	// The line below is uploading your MP3 file right after the tags (both are being sent as one file)
    	echo(fread($MusicFile,FileSize($MP3)));
    	fclose($MusicFile);
    ?>

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
5/29/2003 7:04:55 AM:
Could this code be modified to get the 
current ID2 tag info about a 
MP3?
Thanks, Martin.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/29/2003 1:48:25 PM:AcidicChip
I'm sure it could. I haven't tried it, 
but it's not very different from 
writing the tag.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | PHP Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.