Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed all master to main #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
build
out
/.gradle/
/.idea/
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ implementation 'io.lindstrom:m3u8-parser:0.21'

## Usage

### Create master playlist
### Create main playlist
```java
MasterPlaylist playlist = MasterPlaylist.builder()
MainPlaylist playlist = MainPlaylist.builder()
.version(4)
.independentSegments(true)
.addAlternativeRenditions(AlternativeRendition.builder()
Expand All @@ -55,11 +55,11 @@ MasterPlaylist playlist = MasterPlaylist.builder()
.build())
.build();

MasterPlaylistParser parser = new MasterPlaylistParser();
MainPlaylistParser parser = new MainPlaylistParser();
System.out.println(parser.writePlaylistAsString(playlist));
```

This code should produce the following master playlist:
This code should produce the following main playlist:
```
#EXTM3U
#EXT-X-VERSION:4
Expand Down Expand Up @@ -113,15 +113,15 @@ http://media.example.com/third.ts
#EXT-X-ENDLIST
```

### Parse master playlist
### Parse main playlist
```java
MasterPlaylistParser parser = new MasterPlaylistParser();
MainPlaylistParser parser = new MainPlaylistParser();

// Parse playlist
MasterPlaylist playlist = parser.readPlaylist(Paths.get("path/to/master.m3u8"));
MainPlaylist playlist = parser.readPlaylist(Paths.get("path/to/main.m3u8"));

// Update playlist version
MasterPlaylist updated = MasterPlaylist.builder()
MainPlaylist updated = MainPlaylist.builder()
.from(playlist)
.version(2)
.build();
Expand Down Expand Up @@ -153,7 +153,7 @@ By default, the parser will throw an exception on unsupported tags and attribute
passing a `ParsingMode` to the parser. Example:

```java
MasterPlaylistParser lenientParser = new MasterPlaylistParser(ParsingMode.LENIENT);
MainPlaylistParser lenientParser = new MainPlaylistParser(ParsingMode.LENIENT);
```

Currently two modes are available:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import java.util.List;

/**
* Master playlist interface
* Main playlist interface
*/
@Value.Immutable
public interface MasterPlaylist extends Playlist {
public interface MainPlaylist extends Playlist {

/**
* A list of alternate renditions related to this playlist.
Expand Down Expand Up @@ -59,6 +59,6 @@ static Builder builder() {
return new Builder();
}

class Builder extends MasterPlaylistBuilder {
class Builder extends MainPlaylistBuilder {
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/lindstrom/m3u8/model/Playlist.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Common playlist interface
*
* @see MasterPlaylist
* @see MainPlaylist
* @see MediaPlaylist
*/
public interface Playlist {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package io.lindstrom.m3u8.parser;

import io.lindstrom.m3u8.model.MasterPlaylist;
import io.lindstrom.m3u8.model.MainPlaylist;

import java.util.Iterator;

/**
* MasterPlaylistParser can read and write Master Playlists according to RFC 8216 (HTTP Live Streaming).
* MainPlaylistParser can read and write Main Playlists according to RFC 8216 (HTTP Live Streaming).
* <p>
* Example usage:
* <pre>
* {@code
* MasterPlaylistParser parser = new MasterPlaylistParser();
* MainPlaylistParser parser = new MainPlaylistParser();
*
* // Parse playlist
* MasterPlaylist playlist = parser.readPlaylist(Paths.get("path/to/master.m3u8"));
* MainPlaylist playlist = parser.readPlaylist(Paths.get("path/to/main.m3u8"));
*
* // Update playlist version
* MasterPlaylist updated = MasterPlaylist.builder()
* MainPlaylist updated = MainPlaylist.builder()
* .from(playlist)
* .version(2)
* .build();
Expand All @@ -28,34 +28,34 @@
*
* This implementation is reusable and thread safe.
*/
public class MasterPlaylistParser extends AbstractPlaylistParser<MasterPlaylist, MasterPlaylist.Builder> {
public class MainPlaylistParser extends AbstractPlaylistParser<MainPlaylist, MainPlaylist.Builder> {
private final ParsingMode parsingMode;

public MasterPlaylistParser() {
public MainPlaylistParser() {
this(ParsingMode.STRICT);
}

public MasterPlaylistParser(ParsingMode parsingMode) {
public MainPlaylistParser(ParsingMode parsingMode) {
this.parsingMode = parsingMode;
}

@Override
void write(MasterPlaylist playlist, TextBuilder textBuilder) {
for (MasterPlaylistTag tag : MasterPlaylistTag.tags.values()) {
void write(MainPlaylist playlist, TextBuilder textBuilder) {
for (MainPlaylistTag tag : MainPlaylistTag.tags.values()) {
tag.write(playlist, textBuilder);
}
}

@Override
MasterPlaylist.Builder newBuilder() {
return MasterPlaylist.builder();
MainPlaylist.Builder newBuilder() {
return MainPlaylist.builder();
}

@Override
void onTag(MasterPlaylist.Builder builder, String name, String attributes, Iterator<String> lineIterator) throws PlaylistParserException{
MasterPlaylistTag tag = MasterPlaylistTag.tags.get(name);
void onTag(MainPlaylist.Builder builder, String name, String attributes, Iterator<String> lineIterator) throws PlaylistParserException{
MainPlaylistTag tag = MainPlaylistTag.tags.get(name);

if (tag == MasterPlaylistTag.EXT_X_STREAM_INF) {
if (tag == MainPlaylistTag.EXT_X_STREAM_INF) {
String uriLine = lineIterator.next();
if (uriLine == null || uriLine.startsWith("#")) {
throw new PlaylistParserException("Expected URI, got " + uriLine);
Expand All @@ -69,14 +69,14 @@ void onTag(MasterPlaylist.Builder builder, String name, String attributes, Itera
}

@Override
void onComment(MasterPlaylist.Builder builder, String value) {
void onComment(MainPlaylist.Builder builder, String value) {
builder.addComments(
value
);
}

@Override
MasterPlaylist build(MasterPlaylist.Builder builder) {
MainPlaylist build(MainPlaylist.Builder builder) {
return builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package io.lindstrom.m3u8.parser;

import io.lindstrom.m3u8.model.MasterPlaylist;
import io.lindstrom.m3u8.model.MainPlaylist;

import java.util.Map;

enum MasterPlaylistTag implements Tag<MasterPlaylist, MasterPlaylist.Builder> {
enum MainPlaylistTag implements Tag<MainPlaylist, MainPlaylist.Builder> {
EXT_X_VERSION {
@Override
public void read(MasterPlaylist.Builder builder, String attributes, ParsingMode parsingMode) {
public void read(MainPlaylist.Builder builder, String attributes, ParsingMode parsingMode) {
builder.version(Integer.parseInt(attributes));
}

@Override
public void write(MasterPlaylist playlist, TextBuilder textBuilder) {
public void write(MainPlaylist playlist, TextBuilder textBuilder) {
playlist.version().ifPresent(version -> textBuilder.addTag(tag(), version));
}
},

EXT_X_INDEPENDENT_SEGMENTS {
@Override
public void read(MasterPlaylist.Builder builder, String attributes, ParsingMode parsingMode) {
public void read(MainPlaylist.Builder builder, String attributes, ParsingMode parsingMode) {
builder.independentSegments(true);
}

@Override
public void write(MasterPlaylist playlist, TextBuilder textBuilder) {
public void write(MainPlaylist playlist, TextBuilder textBuilder) {
if (playlist.independentSegments()) {
textBuilder.addTag(tag());
}
Expand All @@ -33,48 +33,48 @@ public void write(MasterPlaylist playlist, TextBuilder textBuilder) {

EXT_X_START {
@Override
public void read(MasterPlaylist.Builder builder, String attributes, ParsingMode parsingMode) throws PlaylistParserException {
public void read(MainPlaylist.Builder builder, String attributes, ParsingMode parsingMode) throws PlaylistParserException {
builder.startTimeOffset(StartTimeOffsetAttribute.parse(attributes, parsingMode));
}

@Override
public void write(MasterPlaylist playlist, TextBuilder textBuilder) {
public void write(MainPlaylist playlist, TextBuilder textBuilder) {
playlist.startTimeOffset().ifPresent(value -> textBuilder.addTag(tag(), value, StartTimeOffsetAttribute.attributeMap));
}
},

EXT_X_DEFINE {
@Override
public void read(MasterPlaylist.Builder builder, String attributes, ParsingMode parsingMode) throws PlaylistParserException {
public void read(MainPlaylist.Builder builder, String attributes, ParsingMode parsingMode) throws PlaylistParserException {
builder.addVariables(PlaylistVariableAttribute.parse(attributes, parsingMode));
}

@Override
public void write(MasterPlaylist playlist, TextBuilder textBuilder) {
public void write(MainPlaylist playlist, TextBuilder textBuilder) {
textBuilder.addTag(tag(), playlist.variables(), PlaylistVariableAttribute.attributeMap);
}
},

EXT_X_MEDIA {
@Override
public void read(MasterPlaylist.Builder builder, String attributes, ParsingMode parsingMode) throws PlaylistParserException {
public void read(MainPlaylist.Builder builder, String attributes, ParsingMode parsingMode) throws PlaylistParserException {
builder.addAlternativeRenditions(AlternativeRenditionAttribute.parse(attributes, parsingMode));
}

@Override
public void write(MasterPlaylist playlist, TextBuilder textBuilder) {
public void write(MainPlaylist playlist, TextBuilder textBuilder) {
textBuilder.addTag(tag(), playlist.alternativeRenditions(), AlternativeRenditionAttribute.attributeMap);
}
},

EXT_X_STREAM_INF {
@Override
public void read(MasterPlaylist.Builder builder, String attributes, ParsingMode parsingMode) {
// Not used. This is handled by the MasterPlaylistParser directly.
public void read(MainPlaylist.Builder builder, String attributes, ParsingMode parsingMode) {
// Not used. This is handled by the MainPlaylistParser directly.
}

@Override
public void write(MasterPlaylist playlist, TextBuilder textBuilder) {
public void write(MainPlaylist playlist, TextBuilder textBuilder) {
String tag = tag();
playlist.variants().forEach(variant -> textBuilder.addTag(tag, variant, VariantAttribute.attributeMap)
.add(variant.uri())
Expand All @@ -84,39 +84,39 @@ public void write(MasterPlaylist playlist, TextBuilder textBuilder) {

EXT_X_I_FRAME_STREAM_INF {
@Override
public void read(MasterPlaylist.Builder builder, String attributes, ParsingMode parsingMode) throws PlaylistParserException {
public void read(MainPlaylist.Builder builder, String attributes, ParsingMode parsingMode) throws PlaylistParserException {
builder.addIFrameVariants(IFrameVariantAttribute.parse(attributes, parsingMode));
}

@Override
public void write(MasterPlaylist playlist, TextBuilder textBuilder) {
public void write(MainPlaylist playlist, TextBuilder textBuilder) {
textBuilder.addTag(tag(), playlist.iFrameVariants(), IFrameVariantAttribute.attributeMap);
}
},

EXT_X_SESSION_DATA {
@Override
public void read(MasterPlaylist.Builder builder, String attributes, ParsingMode parsingMode) throws PlaylistParserException {
public void read(MainPlaylist.Builder builder, String attributes, ParsingMode parsingMode) throws PlaylistParserException {
builder.addSessionData(SessionDataAttribute.parse(attributes, parsingMode));
}

@Override
public void write(MasterPlaylist playlist, TextBuilder textBuilder) {
public void write(MainPlaylist playlist, TextBuilder textBuilder) {
textBuilder.addTag(tag(), playlist.sessionData(), SessionDataAttribute.attributeMap);
}
},

EXT_X_SESSION_KEY {
@Override
public void read(MasterPlaylist.Builder builder, String attributes, ParsingMode parsingMode) throws PlaylistParserException {
public void read(MainPlaylist.Builder builder, String attributes, ParsingMode parsingMode) throws PlaylistParserException {
builder.addSessionKeys(SegmentKeyAttribute.parse(attributes, parsingMode));
}

@Override
public void write(MasterPlaylist playlist, TextBuilder textBuilder) {
public void write(MainPlaylist playlist, TextBuilder textBuilder) {
textBuilder.addTag(tag(), playlist.sessionKeys(), SegmentKeyAttribute.attributeMap);
}
};

static final Map<String, MasterPlaylistTag> tags = ParserUtils.toMap(values(), Tag::tag);
static final Map<String, MainPlaylistTag> tags = ParserUtils.toMap(values(), Tag::tag);
}
32 changes: 16 additions & 16 deletions src/test/java/io/lindstrom/m3u8/examples/ParsePlaylists.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.lindstrom.m3u8.examples;

import io.lindstrom.m3u8.parser.MasterPlaylistParser;
import io.lindstrom.m3u8.model.MasterPlaylist;
import io.lindstrom.m3u8.parser.MainPlaylistParser;
import io.lindstrom.m3u8.model.MainPlaylist;
import org.junit.Test;

import java.io.BufferedReader;
Expand All @@ -18,40 +18,40 @@
import static org.junit.Assert.assertEquals;

public class ParsePlaylists {
private final Path masterPlaylist = Paths.get("src/test/resources/master/master.m3u8");
private final MasterPlaylistParser masterPlaylistParser = new MasterPlaylistParser();
private final Path mainPlaylist = Paths.get("src/test/resources/main/main.m3u8");
private final MainPlaylistParser mainPlaylistParser = new MainPlaylistParser();

@Test
public void readPlaylist() throws Exception {
Set<MasterPlaylist> playlists = new HashSet<>();
Set<MainPlaylist> playlists = new HashSet<>();

playlists.add(
// From Path
masterPlaylistParser.readPlaylist(masterPlaylist)
mainPlaylistParser.readPlaylist(mainPlaylist)
);

playlists.add(
// From String
masterPlaylistParser.readPlaylist(new String(Files.readAllBytes(masterPlaylist), UTF_8))
mainPlaylistParser.readPlaylist(new String(Files.readAllBytes(mainPlaylist), UTF_8))
);

try (InputStream inputStream = Files.newInputStream(masterPlaylist)) {
try (InputStream inputStream = Files.newInputStream(mainPlaylist)) {
playlists.add(
// From InputStream
masterPlaylistParser.readPlaylist(inputStream)
mainPlaylistParser.readPlaylist(inputStream)
);
}

try (BufferedReader bufferedReader = Files.newBufferedReader(masterPlaylist, UTF_8)) {
try (BufferedReader bufferedReader = Files.newBufferedReader(mainPlaylist, UTF_8)) {
playlists.add(
// From BufferedReader
masterPlaylistParser.readPlaylist(bufferedReader)
mainPlaylistParser.readPlaylist(bufferedReader)
);
}

playlists.add(
// From Iterator<String>
masterPlaylistParser.readPlaylist(Files.readAllLines(masterPlaylist, UTF_8).iterator())
mainPlaylistParser.readPlaylist(Files.readAllLines(mainPlaylist, UTF_8).iterator())
);

// All methods should produce the same playlist
Expand All @@ -60,11 +60,11 @@ public void readPlaylist() throws Exception {

@Test
public void writePlaylist() throws Exception {
MasterPlaylist playlist = masterPlaylistParser.readPlaylist(masterPlaylist);
MainPlaylist playlist = mainPlaylistParser.readPlaylist(mainPlaylist);

byte[] bytes = masterPlaylistParser.writePlaylistAsBytes(playlist);
String string = masterPlaylistParser.writePlaylistAsString(playlist);
ByteBuffer byteBuffer = masterPlaylistParser.writePlaylistAsByteBuffer(playlist);
byte[] bytes = mainPlaylistParser.writePlaylistAsBytes(playlist);
String string = mainPlaylistParser.writePlaylistAsString(playlist);
ByteBuffer byteBuffer = mainPlaylistParser.writePlaylistAsByteBuffer(playlist);

assertArrayEquals(bytes, string.getBytes(UTF_8));
assertArrayEquals(bytes, byteBuffer.array());
Expand Down
Loading