Exemple #1
0
 /// <summary>
 /// Retrieve a tag with an arbitrary name.
 /// Returns an empty tag if the value isn't found or if no Xiph tags are present.
 /// </summary>
 /// <param name="TagName">
 /// A <see cref="System.String"/> containing the name of the tag to find
 /// </param>
 /// <returns>
 /// An <see cref="OggTag"/> containing the returned tag
 /// </returns>
 public OggTag GetTag(string TagName)
 {
     if (TagName.Length <= 0)
     {
         return(OggUtilities.GetEmptyTag());
     }                                                                         // Save some processing time and just exit if we haven't been given a tag name
     // Based on tasty examples @ "Accessing Hidden Gems": http://developer.novell.com/wiki/index.php/TagLib_Sharp:_Examples
     TagLib.Ogg.XiphComment XC = (TagLib.Ogg.XiphComment)m_TagLibFile.GetTag(TagTypes.Xiph);
     if (XC != null)
     {
         string[] TagValue = XC.GetField(TagName);
         if (TagValue.Length == 0)
         {
             // Tag doesn't exist, return empty
             return(OggUtilities.GetEmptyTag());
         }
         else
         {
             OggTag tmpTag;
             tmpTag.Name    = TagName;
             tmpTag.IsArray = (TagValue.Length > 1);
             tmpTag.IsEmpty = false;
             tmpTag.Values  = TagValue;
             tmpTag.Value   = TagValue[0];
             return(tmpTag);
         }
     }
     else
     {
         // No valid Xiph tags found
         return(OggUtilities.GetEmptyTag());
     }
 }
Exemple #2
0
        public static void DumpXiphMetadata(File tagFile)
        {
            TagLib.Ogg.XiphComment tags = (TagLib.Ogg.XiphComment)tagFile.GetTag(TagTypes.Xiph);

            foreach (string fieldName in tags.Distinct().OrderBy(t => t))
            {
                string[] fieldValue = tags.GetField(fieldName);
                if (fieldValue.Length > 1)
                {
                    Console.WriteLine("{0} ({1}):", fieldName, fieldValue.Length);
                    foreach (string fv in fieldValue)
                    {
                        WriteLineWithIndent(4, fv);
                    }
                }
                else if (fieldValue.Length == 1)
                {
                    Console.WriteLine("{0}:", fieldName);
                    WriteLineWithIndent(4, fieldValue[0]);
                }
                else
                {
                    Console.WriteLine("{0} (No Value)", fieldName);
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Retrieve an array of all tag values
 /// Returns a zero-length array if no Xiph tags are found
 /// </summary>
 /// <returns>
 /// An <see cref="OggTag[]"/> containing the returned values
 /// </returns>
 public OggTag[] GetTags()
 {
     TagLib.Ogg.XiphComment XC = (TagLib.Ogg.XiphComment)m_TagLibFile.GetTag(TagTypes.Xiph);
     if (XC != null)
     {
         if (XC.FieldCount > 0)
         {
             OggTag[] tmpOggTag = new OggTag[XC.FieldCount];
             int      Index     = 0;
             foreach (string FieldName in XC)
             {
                 string[] TagValue = XC.GetField(FieldName);
                 if (TagValue.Length == 0)
                 {
                     tmpOggTag[Index] = OggUtilities.GetEmptyTag();                                      // This should never happen, but I bet if I don't check it it will!
                 }
                 else
                 {
                     // Populate this tag
                     tmpOggTag[Index].Name    = FieldName;
                     tmpOggTag[Index].IsArray = (TagValue.Length > 1);
                     tmpOggTag[Index].IsEmpty = false;
                     tmpOggTag[Index].Values  = TagValue;
                     tmpOggTag[Index].Value   = TagValue[0];
                 }
                 ++Index;                                // Increment the index so we know which OggTag we're molesting
             }
             // Done! Return the heap of tags
             return(tmpOggTag);
         }
         else
         {
             // Xiph tags contain no items
             return(new OggTag[0]);
         }
     }
     else
     {
         // No valid Xiph tags found
         return(new OggTag[0]);
     }
 }
Exemple #4
0
        public static string[] GetMiscTag(TagLib.File file, string name)
        {
            //TagLib.Mpeg4.AppleTag apple = (TagLib.Mpeg4.AppleTag)file.GetTag(TagLib.TagTypes.Apple);
            //TagLib.Id3v2.Tag id3v2 = (TagLib.Id3v2.Tag)file.GetTag(TagLib.TagTypes.Id3v2);
            TagLib.Ogg.XiphComment xiph = (TagLib.Ogg.XiphComment)file.GetTag(TagLib.TagTypes.Xiph);
            TagLib.Ape.Tag         ape  = (TagLib.Ape.Tag)file.GetTag(TagLib.TagTypes.Ape);

            //if (apple != null)
            //{
            //    string[] text = apple.GetText(name);
            //    if (text.Length != 0)
            //        return text;
            //}

            //if (id3v2 != null)
            //    foreach (TagLib.Id3v2.Frame f in id3v2.GetFrames())
            //        if (f is TagLib.Id3v2.TextInformationFrame && ((TagLib.Id3v2.TextInformationFrame)f).Text != null)
            //            return ((TagLib.Id3v2.TextInformationFrame)f).Text;

            if (xiph != null)
            {
                string[] l = xiph.GetField(name);
                if (l != null && l.Length != 0)
                {
                    return(l);
                }
            }

            if (ape != null)
            {
                TagLib.Ape.Item item = ape.GetItem(name);
                if (item != null)
                {
                    return(item.ToStringArray());
                }
            }

            return(null);
        }