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; }
public static bool UpdateTags(TagLib.File fileInfo, NameValueCollection tags, CUEConfig config) { if (fileInfo is TagLib.Riff.File) return false; TagLib.Ogg.XiphComment xiph = (TagLib.Ogg.XiphComment)fileInfo.GetTag(TagLib.TagTypes.Xiph); if (xiph != null) { foreach (string tag in tags.AllKeys) xiph.SetField(tag, tags.GetValues(tag)); return true; } if (fileInfo is TagLib.Mpeg4.File) { var mpeg4 = (TagLib.Mpeg4.AppleTag)fileInfo.GetTag(TagLib.TagTypes.Apple, true); foreach (string tag in tags.AllKeys) { mpeg4.SetDashBox("com.apple.iTunes", tag, string.Join(";", tags.GetValues(tag))); } return true; } if (fileInfo is TagLib.Mpeg.AudioFile || (fileInfo is TagLib.UserDefined.File && (fileInfo as TagLib.UserDefined.File).Tagger == CUEToolsTagger.ID3v2)) { var id3v2 = (TagLib.Id3v2.Tag)fileInfo.GetTag(TagLib.TagTypes.Id3v2, true); id3v2.Version = (byte) (config.advanced.UseId3v24 ? 4 : 3); foreach (string tag in tags.AllKeys) { var frame = TagLib.Id3v2.UserTextInformationFrame.Get(id3v2, tag, true); frame.Text = tags.GetValues(tag); } return true; } TagLib.Ape.Tag ape = (TagLib.Ape.Tag)fileInfo.GetTag(TagLib.TagTypes.Ape, true); foreach (string tag in tags.AllKeys) ape.SetValue(XiphTagNameToApe(tag), tags.GetValues(tag)); return true; }
protected override void ExtractMetadata(TagLib.Image.File metadata) { base.ExtractMetadata (metadata); if (metadata == null) return; try { var tag = metadata.GetTag (TagTypes.TiffIFD) as IFDTag; var structure = tag.Structure; var entry = structure.GetEntry (0, (ushort)IFDEntryTag.StripOffsets); offset = (entry as StripOffsetsIFDEntry).Values [0]; } catch (Exception e) { Log.DebugException (e); } }
public static NameValueCollection Analyze(TagLib.File fileInfo) { NameValueCollection tags = new NameValueCollection(); TagLib.Ogg.XiphComment xiph = (TagLib.Ogg.XiphComment)fileInfo.GetTag(TagLib.TagTypes.Xiph); TagLib.Ape.Tag ape = (TagLib.Ape.Tag)fileInfo.GetTag(TagLib.TagTypes.Ape); if (xiph != null) { foreach (string tag in xiph) foreach (string value in xiph.GetField(tag)) tags.Add(tag, value); } else if (ape != null) { foreach (string tag in ape) foreach (string value in ape.GetItem(tag).ToStringArray()) tags.Add(ApeTagNameToXiph(tag), value); } else { //if (audioSource is CUETools.Codecs.ALAC.ALACReader) //tags = (audioSource as CUETools.Codecs.ALAC.ALACReader).Tags; } // TODO: enumerate dash atoms somehow? //TagLib.Mpeg4.AppleTag apple = (TagLib.Mpeg4.AppleTag)fileInfo.GetTag(TagLib.TagTypes.Apple); //if (apple != null) //{ // tags = new NameValueCollection(); // foreach (TagLib.Mpeg4.Box tag in apple) // if (tag.BoxType == "----") // foreach (string value in apple.GetDashBox(tag.) // tags.Add(tag, value); //} return tags; }
private static TagLib.Ogg.XiphComment GetTag(TagLib.File file) { try { return file.GetTag (TagLib.TagTypes.Xiph) as TagLib.Ogg.XiphComment; } catch (System.NullReferenceException e) { // Haven't seen crashes when getting Ogg tags, but just in case.. // (See commentary for ID3v2 version) Hyena.Log.WarningFormat ("Got exception when accessing Ogg Metadata in {0}:", file.Name); Hyena.Log.Warning (e.Message); Hyena.Log.Warning (e.StackTrace); return null; } }
private static TagLib.Id3v2.Tag GetTag(TagLib.File file) { try { return file.GetTag (TagLib.TagTypes.Id3v2) as TagLib.Id3v2.Tag; } catch (System.NullReferenceException e) { // TagLib# can crash here on unusual files (Ex: FLAC files with ID3v2 metadata) // Perhaps FLAC+ID3v2 is an unsupported combination for TagLib#? Hyena.Log.WarningFormat ("Got exception when accessing ID3v2 Metadata in {0}:", file.Name); Hyena.Log.Warning (e.Message); Hyena.Log.Warning (e.StackTrace); return null; } }
/// <summary> /// Sets the image tag value. /// </summary> /// <param name="tagFile">TagLib file.</param> /// <param name="tag">Tag to set.</param> /// <param name="value">Value to set.</param> private void SetImageTagValue(TagLib.File tagFile, Tags tag, object value) { var image = tagFile.GetTag(TagTypes.XMP) as TagLib.Image.ImageTag; if (image != null) { if (tag.HasFlag(Tags.Keywords)) image.Keywords = (string[])value; else if (tag.HasFlag(Tags.Rating)) image.Rating = Convert.ToUInt32(value); else if (tag.HasFlag(Tags.Comments)) image.Comment = value.ToString(); else Log.W("Setting value to tag '{0}' is not supported in image files.", tag); } }
/// <summary> /// Fills the video tags to the <paramref name="results"/> dictionary. /// </summary> /// <param name="tagFile">Tag file.</param> /// <param name="results">Result dictionary to be filled.</param> /// <param name="tags">Tags to read.</param> private void FillVideoTags(TagLib.File tagFile, Dictionary<Tags, object> results, Tags tags) { var h264 = tagFile.GetTag(TagTypes.H264) as TagLib.H264.Tag; if (tags.HasFlag(Tags.DateTimeTaken)) { if (h264 != null) results.Add(Tags.Keywords, h264.DateTimeOriginal); } }
/// <summary> /// Fills the image tags to the <paramref name="results"/> dictionary. /// </summary> /// <param name="tagFile">Tag file.</param> /// <param name="results">Result dictionary to be filled.</param> /// <param name="tags">Tags to read.</param> private void FillImageTags(TagLib.File tagFile, Dictionary<Tags, object> results, Tags tags) { var image = tagFile.GetTag(TagTypes.AudibleMetadata) as TagLib.Image.ImageTag; if (image != null) { if (tags.HasFlag(Tags.GpsLatitude)) results.Add(Tags.GpsLatitude, image.Latitude); if (tags.HasFlag(Tags.GpsLongitude)) results.Add(Tags.GpsLongitude, image.Longitude); if (tags.HasFlag(Tags.Keywords)) results.Add(Tags.Keywords, image.Keywords); if (tags.HasFlag(Tags.DateTimeTaken)) results.Add(Tags.DateTimeTaken, image.DateTime); if (tags.HasFlag(Tags.Rating)) results.Add(Tags.Rating, image.Rating); } }
private void Validate(TagLib.Image.File file) { // Note: these don't correspond to the image data, only to the metadata. We hacked the file for size. Assert.AreEqual (2000, file.Properties.PhotoWidth); Assert.AreEqual (3008, file.Properties.PhotoHeight); Assert.AreEqual (96, file.Properties.PhotoQuality); var tag = file.GetTag (TagTypes.TiffIFD) as IFDTag; Assert.IsNotNull (tag, "IFD tag not found"); var structure = tag.Structure; // Image.0x010F (Make/Ascii/18) "NIKON CORPORATION" { var entry = structure.GetEntry (0, (ushort) IFDEntryTag.Make); Assert.IsNotNull (entry, "Entry 0x010F missing in IFD 0"); Assert.IsNotNull (entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual ("NIKON CORPORATION", (entry as StringIFDEntry).Value); } XmpTag xmp = file.GetTag (TagTypes.XMP) as XmpTag; // Xmp.MicrosoftPhoto_1_.DateAcquired (XmpText/20) "2009-08-04T20:42:36Z" { var node = xmp.NodeTree; node = node.GetChild (XmpTag.MS_PHOTO_NS, "DateAcquired"); Assert.IsNotNull (node); Assert.AreEqual ("2009-08-04T20:42:36Z", node.Value); Assert.AreEqual (XmpNodeType.Simple, node.Type); Assert.AreEqual (0, node.Children.Count); } }
private static void SaveIsCompilation (TagLib.File file, bool is_compilation) { try { var xiph_tag = file.GetTag(TagLib.TagTypes.Xiph, true) as TagLib.Ogg.XiphComment; if (xiph_tag != null) { xiph_tag.IsCompilation = is_compilation; return; } } catch {} try { TagLib.Id3v2.Tag id3v2_tag = file.GetTag(TagLib.TagTypes.Id3v2, true) as TagLib.Id3v2.Tag; if (id3v2_tag != null) { id3v2_tag.IsCompilation = is_compilation; return; } } catch {} try { TagLib.Mpeg4.AppleTag apple_tag = file.GetTag(TagLib.TagTypes.Apple,true) as TagLib.Mpeg4.AppleTag; if (apple_tag != null) { apple_tag.IsCompilation = is_compilation; return; } } catch {} }
private static bool IsCompilation (TagLib.File file) { try { var xiph_tag = file.GetTag(TagLib.TagTypes.Xiph, true) as TagLib.Ogg.XiphComment; if (xiph_tag != null && xiph_tag.IsCompilation) return true; } catch {} try { TagLib.Id3v2.Tag id3v2_tag = file.GetTag(TagLib.TagTypes.Id3v2, true) as TagLib.Id3v2.Tag; if (id3v2_tag != null && id3v2_tag.IsCompilation) return true; } catch {} try { TagLib.Mpeg4.AppleTag apple_tag = file.GetTag(TagLib.TagTypes.Apple,true) as TagLib.Mpeg4.AppleTag; if (apple_tag != null && apple_tag.IsCompilation) return true; } catch {} // FIXME the FirstAlbumArtist != FirstPerformer check might return true for half the // tracks on a compilation album, but false for some // TODO checked for 'Soundtrack' (and translated) in the title? if (file.Tag.Performers.Length > 0 && file.Tag.AlbumArtists.Length > 0 && (file.Tag.Performers.Length != file.Tag.AlbumArtists.Length || file.Tag.FirstAlbumArtist != file.Tag.FirstPerformer)) { return true; } return false; }
public AppleTvTag(TagLib.File f) { m_Tags = (TagLib.Mpeg4.AppleTag) f.GetTag(TagLib.TagTypes.Apple, true); }
protected override void ExtractMetadata(TagLib.Image.File metadata) { base.ExtractMetadata (metadata); if (metadata == null) return; try { var tag = metadata.GetTag (TagTypes.TiffIFD) as IFDTag; var structure = tag.Structure; var SubImage1_structure = (structure.GetEntry (0, (ushort)IFDEntryTag.SubIFDs) as SubIFDArrayEntry).Entries [0]; var entry = SubImage1_structure.GetEntry (0, (ushort)IFDEntryTag.JPEGInterchangeFormat); jpeg_data = (entry as ThumbnailDataIFDEntry).Data.Data; } catch (Exception e) { Log.DebugException (e); jpeg_data = null; } }