public static PlaylistValidation from(Playlist playlist, ParsingMode parsingMode) { HashSet <PlaylistError> errors = new HashSet <PlaylistError>(); if (playlist == null) { errors.Add(PlaylistError.NO_PLAYLIST); return(new PlaylistValidation(errors)); } if (playlist.getCompatibilityVersion() < Playlist.MIN_COMPATIBILITY_VERSION) { errors.Add(PlaylistError.COMPATIBILITY_TOO_LOW); } if (hasNoPlaylistTypes(playlist)) { errors.Add(PlaylistError.NO_MASTER_OR_MEDIA); } else if (hasBothPlaylistTypes(playlist)) { errors.Add(PlaylistError.BOTH_MASTER_AND_MEDIA); } if (playlist.hasMasterPlaylist()) { if (!playlist.isExtended()) { errors.Add(PlaylistError.MASTER_NOT_EXTENDED); } addMasterPlaylistErrors(playlist.getMasterPlaylist(), errors); } if (playlist.hasMediaPlaylist()) { addMediaPlaylistErrors(playlist.getMediaPlaylist(), errors, playlist.isExtended(), parsingMode); } return(new PlaylistValidation(errors)); }
public void testParseMaster() { List <MediaData> expectedMediaData = new List <MediaData>(); expectedMediaData.Add(new MediaData.Builder() .withType(MediaType.AUDIO) .withGroupId("1234") .withName("Foo") .build()); StreamInfo expectedStreamInfo = new StreamInfo.Builder() .withBandwidth(500) .build(); String validData = "#EXTM3U\n" + "#EXT-X-VERSION:2\n" + "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"1234\",NAME=\"Foo\"\n" + "#EXT-X-STREAM-INF:BANDWIDTH=500\n" + "http://foo.bar.com/\n" + "\n"; Stream inputStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(validData)); ExtendedM3uParser parser = new ExtendedM3uParser(inputStream, Encoding.UTF_8, ParsingMode.STRICT); Assert.True(parser.isAvailable()); Playlist playlist = parser.parse(); Assert.False(parser.isAvailable()); Assert.True(playlist.isExtended()); Assert.Equal(2, playlist.getCompatibilityVersion()); Assert.True(playlist.hasMasterPlaylist()); Assert.Equal(expectedMediaData, playlist.getMasterPlaylist().getMediaData()); Assert.Equal(expectedStreamInfo, playlist.getMasterPlaylist().getPlaylists()[0].getStreamInfo()); }