Exemplo n.º 1
0
        public void DemoBasicUsageForID3v2()
        {
            // Create a new ID3v2 tag. ID3v2 works mostly like ID3v1 from this
            // perspective, although there are a few enhancements we can use.
            ID3v2Tag v2Tag = new ID3v2Tag();

            // no length restrictions with v2
            v2Tag.Album = "An album with a really long name that wouldn't fit into a ID3v1 tag";
            v2Tag.Genre = "A genre of my own creation!";             // not restricted to pre-defined genres with v2

            // Write our new tag out to a file as ID3v2.3 (for example; v2.2
            // and v2.4 would work too, although ID3v2.4 support is scare out
            // in the real world)
            v2Tag.WriteTag("basic.tag", ID3Versions.V2_3);

            // Read the tag back from the file.
            v2Tag = null;
            if (!ID3v2Tag.HasTag("basic.tag"))
            {
                Console.WriteLine("Hmmmm....something didn't go right here.");
            }
            else
            {
                v2Tag = ID3v2Tag.ReadTag("basic.tag");

                // Some usage possibilities:
                Console.WriteLine("Album: " + v2Tag.Album);

                // Make a change and write it back out to the file.
                v2Tag.Comments = "New comments";
                v2Tag.WriteTag("basic.tag", ID3Versions.V2_3);

                // Show that the change worked.
                v2Tag = ID3v2Tag.ReadTag("basic.tag");
                if (v2Tag.HasComments)
                {
                    Console.WriteLine("The comments we just added: " + v2Tag.Comments);
                }
                else
                {
                    Console.WriteLine("Hmmmm....something didn't go right here.");
                }

                // Some other stuff:
                ID3Versions version = ID3v2Tag.LookForTag("basic.tag");
                Console.WriteLine("ID3 tag found, version: " + version.ToString());
            }
        }
Exemplo n.º 2
0
        public bool WriteTagsToFile(bool overwriteExistingTags)
        {
            if (Status != ItemStatus.Complete)
            {
                return(false);
            }

            if (!CompleteDestination.EndsWith(".mp3", StringComparison.CurrentCultureIgnoreCase))
            {
                return(false);
            }

            try
            {
                ID3Tag tag = null;

                switch (ID3v2Tag.LookForTag(CompleteDestination))
                {
                case ID3Versions.None:
                case ID3Versions.Unknown:
                default:

                    tag = new ID3v2Tag();
                    SetTagContent(tag, overwriteExistingTags);
                    tag.WriteTag(CompleteDestination, ID3Versions.V2_4);

                    break;

                case ID3Versions.V1:
                case ID3Versions.V1_0:
                case ID3Versions.V1_1:

                    tag = ID3v1Tag.ReadTag(CompleteDestination);
                    SetTagContent(tag, overwriteExistingTags);
                    tag.WriteTag(CompleteDestination, ID3Versions.V1_1);

                    break;

                case ID3Versions.V2:
                case ID3Versions.V2_2:
                case ID3Versions.V2_3:

                    tag = ID3v2Tag.ReadTag(CompleteDestination);
                    SetTagContent(tag, overwriteExistingTags);
                    tag.WriteTag(CompleteDestination, ID3Versions.V2_3);

                    break;

                case ID3Versions.V2_4:

                    tag = ID3v2Tag.ReadTag(CompleteDestination);
                    SetTagContent(tag, overwriteExistingTags);
                    tag.WriteTag(CompleteDestination, ID3Versions.V2_4);

                    break;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Error writing tags to: " + CompleteDestination + ". " + ex.Message);

                return(false);
            }

            return(true);
        }