mirror of
https://github.com/samsonjs/media.git
synced 2026-04-22 14:05:55 +00:00
Fix HLS playlist parsing of boolean attributes.
The regex included quotation marks like X="YES", but the manifests don't actually contain them, for examples X=YES.
This commit is contained in:
parent
85be2aed0a
commit
5a5935cb72
2 changed files with 11 additions and 6 deletions
|
|
@ -23,9 +23,10 @@ import java.util.regex.Pattern;
|
|||
/**
|
||||
* Utility methods for HLS manifest parsing.
|
||||
*/
|
||||
/* package */ class HlsParserUtil {
|
||||
/* package */ final class HlsParserUtil {
|
||||
|
||||
private static final String BOOLEAN_YES = "YES";
|
||||
private static final String BOOLEAN_NO = "NO";
|
||||
|
||||
private HlsParserUtil() {}
|
||||
|
||||
|
|
@ -56,7 +57,7 @@ import java.util.regex.Pattern;
|
|||
return null;
|
||||
}
|
||||
|
||||
public static boolean parseOptionalBoolAttr(String line, Pattern pattern) {
|
||||
public static boolean parseOptionalBooleanAttr(String line, Pattern pattern) {
|
||||
Matcher matcher = pattern.matcher(line);
|
||||
if (matcher.find() && matcher.groupCount() == 1) {
|
||||
return BOOLEAN_YES.equals(matcher.group(1));
|
||||
|
|
@ -64,4 +65,8 @@ import java.util.regex.Pattern;
|
|||
return false;
|
||||
}
|
||||
|
||||
public static Pattern compileBooleanAttrPattern(String attrName) {
|
||||
return Pattern.compile(attrName + "=(" + BOOLEAN_YES + "|" + BOOLEAN_NO + ")");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,9 +98,9 @@ public final class HlsPlaylistParser implements NetworkLoadable.Parser<HlsPlayli
|
|||
private static final Pattern NAME_ATTR_REGEX =
|
||||
Pattern.compile(NAME_ATTR + "=\"(.+?)\"");
|
||||
private static final Pattern AUTOSELECT_ATTR_REGEX =
|
||||
Pattern.compile(AUTOSELECT_ATTR + "=\"(.+?)\"");
|
||||
HlsParserUtil.compileBooleanAttrPattern(AUTOSELECT_ATTR);
|
||||
private static final Pattern DEFAULT_ATTR_REGEX =
|
||||
Pattern.compile(DEFAULT_ATTR + "=\"(.+?)\"");
|
||||
HlsParserUtil.compileBooleanAttrPattern(DEFAULT_ATTR);
|
||||
|
||||
@Override
|
||||
public HlsPlaylist parse(String connectionUrl, InputStream inputStream)
|
||||
|
|
@ -156,8 +156,8 @@ public final class HlsPlaylistParser implements NetworkLoadable.Parser<HlsPlayli
|
|||
String name = HlsParserUtil.parseStringAttr(line, NAME_ATTR_REGEX, NAME_ATTR);
|
||||
String uri = HlsParserUtil.parseStringAttr(line, URI_ATTR_REGEX, URI_ATTR);
|
||||
String language = HlsParserUtil.parseOptionalStringAttr(line, LANGUAGE_ATTR_REGEX);
|
||||
boolean isDefault = HlsParserUtil.parseOptionalBoolAttr(line, DEFAULT_ATTR_REGEX);
|
||||
boolean autoSelect = HlsParserUtil.parseOptionalBoolAttr(line, AUTOSELECT_ATTR_REGEX);
|
||||
boolean isDefault = HlsParserUtil.parseOptionalBooleanAttr(line, DEFAULT_ATTR_REGEX);
|
||||
boolean autoSelect = HlsParserUtil.parseOptionalBooleanAttr(line, AUTOSELECT_ATTR_REGEX);
|
||||
subtitles.add(new Subtitle(name, uri, language, isDefault, autoSelect));
|
||||
} else {
|
||||
// TODO: Support other types of media tag.
|
||||
|
|
|
|||
Loading…
Reference in a new issue