/// <summary> /// Loads the metadata for this file. /// </summary> public void Load() { IntPtr fileHandle = NativeMethods.MP4Read(this.fileName); if (fileHandle != IntPtr.Zero) { try { this.metadataTags = MetadataTags.ReadFromFile(fileHandle); this.chapters = ChapterList.ReadFromFile(fileHandle); } finally { NativeMethods.MP4Close(fileHandle); } } }
/// <summary> /// Reads the tags from the specified file. /// </summary> /// <param name="fileHandle">The handle to the file from which to read the tags.</param> /// <returns>A new instance of a <see cref="MetadataTags"/> object containing the values /// in the metadata tags for the file.</returns> internal static MetadataTags ReadFromFile(IntPtr fileHandle) { IntPtr tagPtr = NativeMethods.MP4TagsAlloc(); NativeMethods.MP4TagsFetch(tagPtr, fileHandle); NativeMethods.MP4Tags tags = tagPtr.ReadStructure <NativeMethods.MP4Tags>(); MetadataTags managedTags = new MetadataTags(); managedTags.Title = tags.name; managedTags.Artist = tags.artist; managedTags.AlbumArtist = tags.albumArtist; managedTags.Album = tags.album; managedTags.Grouping = tags.grouping; managedTags.Composer = tags.composer; managedTags.Comment = tags.comment; managedTags.Genre = tags.genre; managedTags.ReadTrackInfo(tags.track); managedTags.ReadDiskInfo(tags.disk); managedTags.Tempo = tags.tempo.ReadShort(); managedTags.IsCompilation = tags.compilation.ReadBoolean(); managedTags.Copyright = tags.copyright; managedTags.EncodingTool = tags.encodingTool; managedTags.EncodedBy = tags.encodedBy; // Tags specific to TV Episodes. managedTags.EpisodeNumber = tags.tvEpisode.ReadInt(); managedTags.SeasonNumber = tags.tvSeason.ReadInt(); managedTags.EpisodeId = tags.tvEpisodeID; managedTags.TVNetwork = tags.tvNetwork; managedTags.TVShow = tags.tvShow; managedTags.Description = tags.description; managedTags.LongDescription = tags.longDescription; managedTags.Lyrics = tags.lyrics; managedTags.SortName = tags.sortName; managedTags.SortArtist = tags.sortArtist; managedTags.SortAlbumArtist = tags.sortAlbumArtist; managedTags.SortAlbum = tags.sortAlbum; managedTags.SortComposer = tags.sortComposer; managedTags.SortTVShow = tags.sortTVShow; managedTags.ArtworkCount = tags.artworkCount; managedTags.ReadArtwork(tags.artwork); managedTags.IsPodcast = tags.podcast.ReadBoolean(); managedTags.Keywords = tags.keywords; managedTags.Category = tags.category; managedTags.IsHDVideo = tags.hdVideo.ReadEnumValue <HDKind>(HDKind.SD); managedTags.MediaType = tags.mediaType.ReadEnumValue <MediaKind>(MediaKind.NotSet); managedTags.ContentRating = tags.contentRating.ReadEnumValue <ContentRating>(ContentRating.NotSet); managedTags.IsGapless = tags.gapless.ReadBoolean(); managedTags.MediaStoreAccount = tags.itunesAccount; managedTags.MediaStoreCountry = tags.iTunesCountry.ReadEnumValue <Country>(Country.None); managedTags.MediaStoreAccountType = tags.iTunesAccountType.ReadEnumValue <MediaStoreAccountKind>(MediaStoreAccountKind.NotSet); managedTags.ContentId = tags.contentID.ReadInt(); managedTags.ArtistId = tags.artistID.ReadInt(); managedTags.PlaylistId = tags.playlistID.ReadInt(); managedTags.GenreId = tags.genreID.ReadInt(); managedTags.ComposerId = tags.composerID.ReadInt(); managedTags.Xid = tags.xid; NativeMethods.MP4TagsFree(tagPtr); managedTags.RatingInfo = ReadRawAtom <RatingInfo>(fileHandle); managedTags.MovieInfo = ReadRawAtom <MovieInfo>(fileHandle); return(managedTags); }