All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.vpro.domain.subtitles.SubtitlesFormat Maven / Gradle / Ivy

Go to download

Subtitles are related to media, but are implemented completely parallel. Classes to contain, parse, and assemble subtitle objects are here.

There is a newer version: 8.3.0
Show newest version
package nl.vpro.domain.subtitles;

import lombok.Getter;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Optional;

import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;

import nl.vpro.api.rs.subtitles.Constants;
import nl.vpro.util.ISO6937CharsetProvider;


/**
 * The recognized (by POMS) subtitles formats.
 * @author Michiel Meeuwissen
 * @since 4.7
 */
@XmlEnum
@XmlType(name = "subtitlesFormatEnum")
public enum SubtitlesFormat {

    /**
     * WEBVTT
     */
    WEBVTT("vtt", Constants.VTT, StandardCharsets.UTF_8),
    TT888("txt", Constants.TT888, ISO6937CharsetProvider.ISO6937),
    EBU("stl", Constants.EBU, null),
    SRT("srt", Constants.SRT, Charset.forName("cp1252"))
    ;

    @Getter
    private final String extension;
    @Getter
    private final String mediaType;
    @Getter
    private final Charset charset;

    SubtitlesFormat(String extension, String mediaType, Charset charset) {
        this.extension = extension;
        this.mediaType = mediaType;
        this.charset = charset;
    }

    public static Optional ofExtension(String extension) {
        for (SubtitlesFormat sf : values()) {
            if (sf.extension.equalsIgnoreCase(extension)) {
                return Optional.of(sf);
            }
        }
        return Optional.empty();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy