Working with OGG metadata

OGG Vorbis files store their metadata as Vorbis comments: pairs of a field name and a value, such as ARTIST=... or TITLE=.... GroupDocs.Metadata for Java reads these comments through the OggPackage class.

The most common fields have dedicated getters:

GroupGetters
TrackgetTitle, getAlbum, getTracknumber, getArtist, getPerformer, getGenre, getDate
Rights and contactsgetCopyright, getLicense, getOrganization, getDescription, getLocation, getContact, getIsrc
EncodergetVendor, getVersion

All other comments are available through getOggUserComments.

Reading OGG Vorbis comments

  1. Load an OGG file
  2. Get the root metadata package
  3. Extract the native metadata package using the OggRootPackage.getOggPackage method
  4. Read the properties of the package

advanced_usage.managing_metadata_for_specific_formats.audio.ogg.OggReadNativeMetadataProperties

try (Metadata metadata = new Metadata(Constants.InputOgg)) {
    OggRootPackage root = metadata.getRootPackageGeneric();
    OggPackage ogg = root.getOggPackage();

    System.out.println(ogg.getVendor());
    System.out.println(ogg.getTitle());
    System.out.println(ogg.getArtist());
    System.out.println(ogg.getAlbum());
    System.out.println(ogg.getGenre());
    System.out.println(ogg.getDate());
    System.out.println(ogg.getCopyright());

    // Vorbis comments that are not mapped to dedicated properties
    for (OggUserComment comment : ogg.getOggUserComments()) {
        System.out.println(String.format("%s = %s", comment.getHeader(), comment.getValue()));
    }
}

Searching OGG properties by tags

The OGG properties are marked with the same tags as the properties of other audio formats. So you can find, for example, the artist and the title without knowing the format of the file.

try (Metadata metadata = new Metadata(Constants.InputOgg)) {
    IReadOnlyList<MetadataProperty> properties = metadata.findProperties(
            new ContainsTagSpecification(Tags.getPerson().getArtist())
                    .or(new ContainsTagSpecification(Tags.getContent().getTitle())));

    for (MetadataProperty property : properties) {
        System.out.println(String.format("%s = %s", property.getName(), property.getValue()));
    }
}

More resources

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document metadata management App

Along with full featured Java library we provide simple, but powerful free Apps.

You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.