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

io.lindstrom.m3u8.parser.SegmentMapParser Maven / Gradle / Ivy

There is a newer version: 0.28
Show newest version
package io.lindstrom.m3u8.parser;

import io.lindstrom.m3u8.model.SegmentMap;

import java.util.Map;

import static io.lindstrom.m3u8.parser.Tags.*;

class SegmentMapParser extends AbstractLineParser {
    private final ByteRangeParser byteRangeParser;

    SegmentMapParser(ByteRangeParser byteRangeParser) {
        super(EXT_X_MAP);
        this.byteRangeParser = byteRangeParser;
    }

    @Override
    SegmentMap parseAttributes(Map attributes) throws PlaylistParserException {
        SegmentMap.Builder builder = SegmentMap.builder()
                .uri(attributes.get(URI));

        if (attributes.containsKey(BYTERANGE)) {
            builder.byteRange(byteRangeParser.parse(attributes.get(BYTERANGE)));
        }

        return builder.build();
    }

    @Override
    String writeAttributes(SegmentMap segmentMap) {
        AttributeListBuilder attributes = new AttributeListBuilder();
        attributes.addQuoted(URI, segmentMap.uri());
        segmentMap.byteRange().map(byteRangeParser::writeAttributes).ifPresent(value ->
                attributes.addQuoted(BYTERANGE, value));
        return attributes.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy