
Welcome to PcCare.com
| Mp3 Changing Name Artist Album | |
// // .net c# code to Change Mp3 Name Artist Album Comment and Year // // Some code from http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/ee65171a-a4e5-4d9a-b2be-337c8f2adeac/ // using System; using System.Collections.Generic; using System.Linq; using System.Text; using System; using System.IO; using System.Text; namespace mp3info { /// <summary> /// Reads/writes Id3v1 tags. lots of help from Paul Lockwood's code /// http://www.csharphelp.com/archives/archive226.html /// </summary> public class ID3v1 { public TagValues ValuesToWrite = new TagValues(); public TagValues CurrentValues = new TagValues(); public bool hasTag; public bool ReadTags = true; public string filename; static int Main(string[] args) { int ReturnStatus = 0; int index = 0; ID3v1 mp3File = new ID3v1(); string text; string ArgName; while (index < args.Length) { text = args[index].ToUpper(); ArgName = "/FILENAME:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.filename = args[index].Substring(ArgName.Length); } ArgName = "/TITLE:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.ValuesToWrite.Title = args[index].Substring(ArgName.Length); } ArgName = "/ARTIST:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.ValuesToWrite.Artist = args[index].Substring(ArgName.Length); } ArgName = "/Album:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.ValuesToWrite.Album = args[index].Substring(ArgName.Length); } ArgName = "/Year:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.ValuesToWrite.Year = args[index].Substring(ArgName.Length); } ArgName = "/Comment:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.ValuesToWrite.Comment = args[index].Substring(ArgName.Length); } ArgName = "/Write:"; ArgName = ArgName.ToUpper(); if (text.StartsWith(ArgName)) { mp3File.ReadTags = (!(Convert.ToBoolean(args[index].Substring(ArgName.Length)))); } index = index + 1; } if (mp3File.filename.Length == 0 || mp3File.filename.Length == 0) { Console.Error.WriteLine("\n\nMp3TagWrite invalid command line argument. usage: Mp3TagWrite /filename:'c:\\temp\\Dark Side Of the Moon.Mp3' /Write:True /Artist:'Pink Floyd' [Title,Album,Year,Comment]"); Console.Error.WriteLine("/Write:True writes tags to file, /Write:False read tags from file"); return (1); } try { // read current values from mp3 file mp3File.Read(); if (!mp3File.ReadTags) { // read current values mp3File.updateMP3Tag(); // Read to print new values mp3File.Read(); } Console.WriteLine("\n\nFilename: {0}", mp3File.filename); Console.WriteLine("Title: {0}", mp3File.CurrentValues.Title); Console.WriteLine("Artist: {0}", mp3File.CurrentValues.Artist); Console.WriteLine("Album: {0}", mp3File.CurrentValues.Album); Console.WriteLine("Year: {0}", mp3File.CurrentValues.Year); Console.WriteLine("Comment: {0}", mp3File.CurrentValues.Comment); return(ReturnStatus); } catch (Exception e) { Console.Error.WriteLine("\n\n{0}",e.ToString()); ReturnStatus = 1; } return (ReturnStatus); } private void Initialize_Components() { hasTag = false; } public ID3v1() { Initialize_Components(); } public ID3v1( string filename ) { Initialize_Components(); this.filename = filename; } public void Read () { // Read the 128 byte ID3 tag into a byte array FileStream oFileStream; oFileStream = new FileStream( this.filename, FileMode.Open); byte[] bBuffer = new byte[128]; oFileStream.Seek(-128, SeekOrigin.End); oFileStream.Read(bBuffer,0, 128); oFileStream.Close(); // Convert the Byte Array to a String Encoding instEncoding = new ASCIIEncoding(); // NB: Encoding is an Abstract class string id3Tag = instEncoding.GetString(bBuffer); // If there is an attched ID3 v1.x TAG then read it if (id3Tag .Substring(0,3) == "TAG") { this.CurrentValues.Title = id3Tag.Substring(3, 30).Trim(); this.CurrentValues.Artist = id3Tag.Substring(33, 30).Trim(); this.CurrentValues.Album = id3Tag.Substring(63, 30).Trim(); this.CurrentValues.Year = id3Tag.Substring(93, 4).Trim(); this.CurrentValues.Comment = id3Tag.Substring(97, 28).Trim(); |