/// <summary> /// Loads the metadata for this file. /// </summary> public void Load() { var fileHandle = NativeMethods.MP4Read(System.Text.Encoding.UTF8.GetBytes(this.fileName), IntPtr.Zero); if (fileHandle == IntPtr.Zero) { // open for modify to see if that enables us to read fileHandle = NativeMethods.MP4Modify(System.Text.Encoding.UTF8.GetBytes(this.fileName), 0); } if (fileHandle != IntPtr.Zero) { try { this.Tags = MetadataTags.ReadFromFile(fileHandle); this.Chapters = ChapterList.ReadFromFile(fileHandle); this.Tracks = TrackList.ReadFromFile(fileHandle); } finally { NativeMethods.MP4Close(fileHandle); } } }
/// <summary> /// Get meta-data <paramref name="tag" /> content from <paramref name="document" />. /// </summary> /// <param name="document">Handle to the document.</param> /// <param name="tag">The tag to retrieve.</param> /// <returns>The meta-data.</returns> /// <remarks> /// For detailed explanations of these tags and their respective /// values, please refer to PDF Reference 1.6, section 10.2.1, /// 'Document Information Dictionary'. /// </remarks> /// <seealso href="http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf">PDF Reference</seealso> /// <seealso cref="PdfDocument.GetMetaText(MetadataTags)" /> public static string FPDF_GetMetaText(FPDF_DOCUMENT document, MetadataTags tag) => FPDF_GetMetaText(document, tag.ToString());
public string GetMetaText(MetadataTags tag) => PDFium.FPDF_GetMetaText(Handle, tag);
private void readTags( MetadataTags tags, string header, bool listable ) { if( header == null ) { return; } string[] attrs = header.Split( new string[] { "," }, StringSplitOptions.RemoveEmptyEntries ); for( int i = 0; i < attrs.Length; i++ ) { string attr = attrs[i].Trim(); tags.AddTag( new MetadataTag( utf8Enabled ? utf8Decode(attr) : attr, listable ) ); } }
private void processTags( MetadataTags tags, Dictionary<string, string> headers ) { StringBuilder taglist = new StringBuilder(); log.TraceEvent(TraceEventType.Verbose, 0, "Processing " + tags.Count() + " metadata tag entries" ); foreach( MetadataTag tag in tags ) { if( taglist.Length > 0 ) { taglist.Append( "," ); } taglist.Append( utf8Enabled ? utf8Encode(tag.Name) : tag.Name ); } if( taglist.Length > 0 ) { headers.Add( "x-emc-tags", taglist.ToString() ); } if ( utf8Enabled && !headers.ContainsKey("x-emc-utf8") ) { headers.Add("x-emc-utf8", "true"); } }
/// <summary> /// Returns the list of user metadata tags assigned to the object. /// </summary> /// <param name="id">The object whose metadata tags to list</param> /// <returns>The list of user metadata tags assigned to the object</returns> public MetadataTags ListUserMetadataTags( Identifier id ) { HttpWebResponse resp = null; try { string resource = getResourcePath(context, id) + "?metadata/tags"; Uri u = buildUrl( resource ); HttpWebRequest con = createWebRequest(u); // Build headers Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add( "x-emc-uid", uid ); if (utf8Enabled) headers.Add("x-emc-utf8", "true"); if (id is ObjectKey) { headers.Add("x-emc-pool", (id as ObjectKey).pool); } // Add date addDateHeader(headers); // Sign request signRequest( con, "GET", resource, headers ); // Check response resp = (HttpWebResponse)con.GetResponse(); int statInt = (int)resp.StatusCode; if( statInt > 299 ) { handleError( resp ); } // Get the user metadata tags out of x-emc-listable-tags and // x-emc-tags MetadataTags tags = new MetadataTags(); readTags( tags, resp.Headers["x-emc-listable-tags"], true ); readTags( tags, resp.Headers["x-emc-tags"], false ); return tags; } catch( UriFormatException e ) { throw new EsuException( "Invalid URL", e ); } catch( IOException e ) { throw new EsuException( "Error connecting to server", e ); } catch( WebException e ) { if (e.Response != null) { handleError((HttpWebResponse)e.Response); } else { throw new EsuException("Error executing request: " + e.Message, e); } } finally { if( resp != null ) { resp.Close(); } } return null; }
/// <summary> /// Fetches the system metadata for the object. /// </summary> /// <param name="id">the identifier of the object whose system metadata to fetch.</param> /// <param name="tags">A list of system metadata tags to fetch. Optional. If null, all metadata will be fetched.</param> /// <returns>The list of system metadata for the object.</returns> public MetadataList GetSystemMetadata( Identifier id, MetadataTags tags ) { HttpWebResponse resp = null; try { string resource = getResourcePath(context, id) + "?metadata/system"; Uri u = buildUrl( resource ); HttpWebRequest con = createWebRequest(u); // Build headers Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add( "x-emc-uid", uid ); if (id is ObjectKey) { headers.Add("x-emc-pool", (id as ObjectKey).pool); } // Add tags if needed if( tags != null ) { processTags( tags, headers ); } // Add date addDateHeader(headers); // Sign request signRequest( con, "GET", resource, headers ); // Check response resp = (HttpWebResponse)con.GetResponse(); int statInt = (int)resp.StatusCode; if( statInt > 299 ) { handleError( resp ); } // Parse return headers. Regular metadata is in x-emc-meta and // listable metadata is in x-emc-listable-meta MetadataList meta = new MetadataList(); readMetadata( meta, resp.Headers["x-emc-meta"], false ); readMetadata( meta, resp.Headers["x-emc-listable-meta"], true ); return meta; } catch( UriFormatException e ) { throw new EsuException( "Invalid URL", e ); } catch( IOException e ) { throw new EsuException( "Error connecting to server", e ); } catch( WebException e ) { if (e.Response != null) { handleError((HttpWebResponse)e.Response); } else { throw new EsuException("Error executing request: " + e.Message, e); } } finally { if( resp != null ) { resp.Close(); } } return null; }
/// <summary> /// Deletes metadata items from an object. /// </summary> /// <param name="id">The identifier of the object whose metadata to delete.</param> /// <param name="tags">The list of metadata tags to delete.</param> public void DeleteUserMetadata( Identifier id, MetadataTags tags ) { if( tags == null ) { throw new EsuException( "Must specify tags to delete" ); } HttpWebResponse resp = null; try { string resource = getResourcePath(context, id) + "?metadata/user"; Uri u = buildUrl( resource ); HttpWebRequest con = createWebRequest(u); // Build headers Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add( "x-emc-uid", uid ); if (id is ObjectKey) { headers.Add("x-emc-pool", (id as ObjectKey).pool); } // Add tags if needed processTags( tags, headers ); // Add date addDateHeader(headers); // Sign request signRequest( con, "DELETE", resource, headers ); // Check response resp = (HttpWebResponse)con.GetResponse(); int statInt = (int)resp.StatusCode; if( statInt > 299 ) { handleError( resp ); } } catch( UriFormatException e ) { throw new EsuException( "Invalid URL", e ); } catch( IOException e ) { throw new EsuException( "Error connecting to server", e ); } catch( WebException e ) { if (e.Response != null) { handleError((HttpWebResponse)e.Response); } else { throw new EsuException("Error executing request: " + e.Message, e); } } finally { if( resp != null ) { resp.Close(); } } }
/// <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); } } }
public void testGetSystemMetadata() { // Create an object MetadataList mlist = new MetadataList(); Metadata listable = new Metadata( "listable", "foo", true ); Metadata unlistable = new Metadata( "unlistable", "bar", false ); Metadata listable2 = new Metadata( "listable2", "foo2 foo2", true ); Metadata unlistable2 = new Metadata( "unlistable2", "bar2 bar2", false ); mlist.AddMetadata( listable ); mlist.AddMetadata( unlistable ); mlist.AddMetadata( listable2 ); mlist.AddMetadata( unlistable2 ); ObjectId id = this.esu.CreateObject( null, mlist, null, null ); Assert.IsNotNull( id,"null ID returned" ); cleanup.Add( id ); // Read only part of the metadata MetadataTags mtags = new MetadataTags(); mtags.AddTag( new MetadataTag( "atime", false ) ); mtags.AddTag( new MetadataTag( "ctime", false ) ); MetadataList meta = this.esu.GetSystemMetadata( id, mtags ); Assert.IsNotNull( meta.GetMetadata( "atime" ), "value of 'atime' missing" ); Assert.IsNull( meta.GetMetadata( "mtime" ), "value of 'mtime' should not have been returned" ); Assert.IsNotNull( meta.GetMetadata( "ctime" ), "value of 'ctime' missing" ); Assert.IsNull( meta.GetMetadata( "gid" ), "value of 'gid' should not have been returned" ); Assert.IsNull( meta.GetMetadata( "listable" ), "value of 'listable' should not have been returned" ); }
public void testDeleteUserMetadata() { // Create an object with metadata MetadataList mlist = new MetadataList(); Metadata listable = new Metadata( "listable", "foo", true ); Metadata unlistable = new Metadata( "unlistable", "bar", false ); Metadata listable2 = new Metadata( "listable2", "foo2 foo2", true ); Metadata unlistable2 = new Metadata( "unlistable2", "bar2 bar2", false ); mlist.AddMetadata( listable ); mlist.AddMetadata( unlistable ); mlist.AddMetadata( listable2 ); mlist.AddMetadata( unlistable2 ); ObjectId id = this.esu.CreateObject( null, mlist, null, null ); Assert.IsNotNull( id,"null ID returned" ); cleanup.Add( id ); // Delete a couple of the metadata entries MetadataTags mtags = new MetadataTags(); mtags.AddTag( new MetadataTag( "listable2", true ) ); mtags.AddTag( new MetadataTag( "unlistable2", false ) ); this.esu.DeleteUserMetadata( id, mtags ); // Read back the metadata for the object and ensure the deleted // entries don't exist MetadataList meta = this.esu.GetUserMetadata( id, null ); Assert.AreEqual( "foo", meta.GetMetadata( "listable" ).Value, "value of 'listable' wrong" ); Assert.IsNull( meta.GetMetadata( "listable2" ), "value of 'listable2' should not have been returned" ); Assert.AreEqual( "bar", meta.GetMetadata( "unlistable" ).Value, "value of 'unlistable' wrong" ); Assert.IsNull( meta.GetMetadata( "unlistable2" ), "value of 'unlistable2' should not have been returned" ); }
public void testGetUserMetadata() { // Create an object with user metadata MetadataList mlist = new MetadataList(); Metadata listable = new Metadata( "listable", "foo", true ); Metadata unlistable = new Metadata( "unlistable", "bar", false ); Metadata listable2 = new Metadata( "listable2", "foo2 foo2", true ); Metadata unlistable2 = new Metadata( "unlistable2", "bar2 bar2", false ); mlist.AddMetadata( listable ); mlist.AddMetadata( unlistable ); mlist.AddMetadata( listable2 ); mlist.AddMetadata( unlistable2 ); ObjectId id = this.esu.CreateObject( null, mlist, null, null ); Assert.IsNotNull( id, "null ID returned" ); cleanup.Add( id ); // Read only part of the metadata MetadataTags mtags = new MetadataTags(); mtags.AddTag( new MetadataTag( "listable", true ) ); mtags.AddTag( new MetadataTag( "unlistable", false ) ); MetadataList meta = this.esu.GetUserMetadata( id, mtags ); Assert.AreEqual( "foo", meta.GetMetadata( "listable" ).Value, "value of 'listable' wrong" ); Assert.IsNull( meta.GetMetadata( "listable2" ), "value of 'listable2' should not have been returned" ); Assert.AreEqual( "bar", meta.GetMetadata( "unlistable" ).Value, "value of 'unlistable' wrong" ); Assert.IsNull( meta.GetMetadata( "unlistable2" ), "value of 'unlistable2' should not have been returned" ); }
public void testUtf8DeleteMetadata() { String oneByteCharacters = "Hello! "; String twoByteCharacters = "\u0410\u0411\u0412\u0413"; // Cyrillic letters String fourByteCharacters = "\ud841\udf0e\ud841\udf31\ud841\udf79\ud843\udc53"; // Chinese symbols String utf8String = oneByteCharacters + twoByteCharacters + fourByteCharacters; MetadataList metaList = new MetadataList(); metaList.AddMetadata( new Metadata( "utf8Key", utf8String, false ) ); metaList.AddMetadata( new Metadata( utf8String, "utf8Value", false ) ); ObjectId id = this.esu.CreateObject( null, metaList, null, null ); cleanup.Add( id ); // delete the UTF8 tag MetadataTags tags = new MetadataTags(); tags.AddTag( new MetadataTag( utf8String, false ) ); this.esu.DeleteUserMetadata( id, tags ); // verify delete was successful tags = this.esu.ListUserMetadataTags( id ); Assert.IsFalse( tags.Contains( utf8String ), "UTF8 key was not deleted" ); }
public void testUtf8MetadataFilter() { String oneByteCharacters = "Hello! "; String twoByteCharacters = "\u0410\u0411\u0412\u0413"; // Cyrillic letters String fourByteCharacters = "\ud841\udf0e\ud841\udf31\ud841\udf79\ud843\udc53"; // Chinese symbols String utf8String = oneByteCharacters + twoByteCharacters + fourByteCharacters; MetadataList metaList = new MetadataList(); metaList.AddMetadata( new Metadata( "utf8Key", utf8String, false ) ); metaList.AddMetadata( new Metadata( utf8String, "utf8Value", false ) ); ObjectId id = this.esu.CreateObject( null, metaList, null, null ); cleanup.Add( id ); // apply a filter that includes the UTF8 tag MetadataTags tags = new MetadataTags(); tags.AddTag( new MetadataTag( utf8String, false ) ); metaList = this.esu.GetUserMetadata( id, tags ); Assert.AreEqual( metaList.Count(), 1, "UTF8 filter was not honored" ); Assert.IsNotNull( metaList.GetMetadata( utf8String ), "UTF8 key was not found in filtered results" ); }
internal override void ReadData(AwesomeReader ar) { // Clears tag/path lists MetadataTags.Clear(); GenreTags.Clear(); Labels.Clear(); InstrumentPaths.Clear(); // 184 bytes Title = ar.ReadUInt64(); Artist = ar.ReadUInt64(); Description = ar.ReadUInt64(); Album = ar.ReadUInt64(); TexturePath = ar.ReadUInt64(); LegendTag = ar.ReadUInt64(); EraTag = ar.ReadUInt64(); Year = ar.ReadInt32(); GuitarIntensity = ar.ReadSingle(); BassIntensity = ar.ReadSingle(); VoxIntensity = ar.ReadSingle(); // Reads metadata tags int count = ar.ReadInt32(); int offset = ar.ReadInt32(); long previousPosition = ar.BaseStream.Position; ar.BaseStream.Position += offset - 4; for (int i = 0; i < count; i++) { MetadataTags.Add(ar.ReadUInt64()); } ar.BaseStream.Position = previousPosition; // Reads genre tags count = ar.ReadInt32(); offset = ar.ReadInt32(); previousPosition = ar.BaseStream.Position; ar.BaseStream.Position += offset - 4; for (int i = 0; i < count; i++) { GenreTags.Add(ar.ReadUInt64()); } ar.BaseStream.Position = previousPosition; // Reads labels count = ar.ReadInt32(); offset = ar.ReadInt32(); previousPosition = ar.BaseStream.Position; ar.BaseStream.Position += offset - 4; for (int i = 0; i < count; i++) { Labels.Add(ar.ReadUInt64()); } ar.BaseStream.Position = previousPosition; SongLength = ar.ReadSingle(); ar.BaseStream.Position += 4; // Should be zero PreviewPath = ar.ReadUInt64(); VideoPath = ar.ReadUInt64(); ar.BaseStream.Position += 8; // Should be zero // Reads instrument paths. count = ar.ReadInt32(); offset = ar.ReadInt32(); previousPosition = ar.BaseStream.Position; ar.BaseStream.Position += offset - 4; for (int i = 0; i < count; i++) { InstrumentPaths.Add(ar.ReadUInt64()); } ar.BaseStream.Position = previousPosition; // Reads audio paths BackingAudioPath = ar.ReadUInt64(); BassAudioPath = ar.ReadUInt64(); DrumsAudioPath = ar.ReadUInt64(); LeadGuitarAudioPath = ar.ReadUInt64(); RhythmGuitarAudioPath = ar.ReadUInt64(); VoxAudioPath = ar.ReadUInt64(); }