/** * Parse an M3U stream with a filter to remove unwanted entries. */ public async Task <ProviderChannels> Parse(StreamReader stream) { var currentEntry = new ProviderChannel(); var m3u = new ProviderChannels(); using (stream) { string line; while ((line = await stream.ReadLineAsync()) != null) { if (line.StartsWith("#EXTM3U")) { // Ignore the header. } else if (line.StartsWith("#EXTINF")) { // Populate the entry ID. currentEntry.ID = extractAttribute(idRegex, line); // Populate the entry name. currentEntry.Name = extractAttribute(nameRegex, line); if (logoRegex != null) { // Populate the entry logo. currentEntry.Logo = extractAttribute(logoRegex, line); } if (groupRegex != null) { // Populate the entry group. currentEntry.Group = extractAttribute(groupRegex, line); } } else if (line.StartsWith("#")) { // Ignore comments. } else { // Populate the entry URL. currentEntry.URL = line; // Filter entries from the list. if ((Filter == null) || Filter.Invoke(currentEntry)) { // Add the entry to the list. m3u.Add(currentEntry); } // Moving to the next entry. currentEntry = new ProviderChannel(); } } } return(m3u); }
public Boolean Predicate(ProviderChannel entry) { if (String.IsNullOrEmpty(entry.Group)) { return(false); } return(regex.IsMatch(entry.Group)); }