Skip to content
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: 1 addition & 1 deletion parser/pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>net.chilicat.m3u8</groupId>
<artifactId>m3u8parser</artifactId>
<packaging>jar</packaging>
<version>0.2</version>
<version>0.3</version>
<name>m3u8</name>
<url>http://m3u8parser.chilicat.net/</url>

Expand Down
Empty file modified parser/src/main/java/net/chilicat/m3u8/M3uConstants.java
100644 → 100755
Empty file.
37 changes: 33 additions & 4 deletions parser/src/main/java/net/chilicat/m3u8/PlaylistParser.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.nio.channels.Channels;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -51,7 +53,7 @@ public Playlist parse(Readable source) throws ParseException {
boolean firstLine = true;

int lineNumber = 0;

final List<Element> elements = new ArrayList<Element>(10);
final ElementBuilder builder = new ElementBuilder();
boolean endListSet = false;
Expand Down Expand Up @@ -89,7 +91,9 @@ public Playlist parse(Readable source) throws ParseException {
builder.programDate(programDateTime);
} else if (line.startsWith(EXT_X_KEY)) {
currentEncryption = parseEncryption(line, lineNumber);
} else {
} else if (line.startsWith(EXT_X_STREAM_INF)){
parseStreamInf(line,builder);
} else {
log.log(Level.FINE, new StringBuilder().append("Unknown: '").append(line).append("'").toString());
}
} else if (line.startsWith(COMMENT_PREFIX)) {
Expand Down Expand Up @@ -120,7 +124,32 @@ public Playlist parse(Readable source) throws ParseException {
return new Playlist(Collections.unmodifiableList(elements), endListSet, targetDuration, mediaSequenceNumber);
}

private URI toURI(String line) {

private void parseStreamInf(final String line, final ElementBuilder builder)
{
String ln = line.replace(EXT_X_STREAM_INF + ":", "");

//this isn't the proper way to parse these, this will break for parameters that
// can have comma separated lists for their value (eg CODECS)
String[] split = ln.split(",");

Map<String, String> params = new HashMap<String, String>();

for (String kvp : split)
{
String param = kvp.substring(0, kvp.indexOf('='));
String value = kvp.substring(kvp.indexOf('=') + 1);
params.put(param, value);
}

final int programId = Integer.parseInt(params.get("PROGRAM-ID"));
final int bandwidth = Integer.parseInt(params.get("BANDWIDTH"));

builder.playList(programId, bandwidth, null);
}


private URI toURI(String line) {
try {
return (URI.create(line));
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -175,7 +204,7 @@ private void parseExtInf(String line, int lineNumber, ElementBuilder builder) th
try {
builder.duration(Double.valueOf(duration)).title(title);
} catch (NumberFormatException e) {
// should not happen because of
// should not happen because of
throw new ParseException(line, lineNumber, e);
}
}
Expand Down