public Task <Uri> GetTrackAsync(PlsParser pls, ContentType contentType, CancellationToken cancellationToken) { var tracks = pls.Tracks; var plsTrack = SelectTrack(tracks); if (null == plsTrack) { return(TaskEx.FromResult <Uri>((Uri)null)); } if (tracks.Count > 1) { Debug.WriteLine("PlsSegmentManagerPolicy.GetTrackAsync() multiple tracks are not supported"); } if (null == plsTrack.File) { Debug.WriteLine("PlsSegmentManagerPolicy.GetTrackAsync() track does not have a file"); } Uri result; if (Uri.TryCreate(pls.BaseUrl, plsTrack.File, out result)) { return(TaskEx.FromResult <Uri>(result)); } Debug.WriteLine("PlsSegmentManagerPolicy.GetTrackAsync() invalid track file: " + plsTrack.File); return(TaskEx.FromResult <Uri>((Uri)null)); }
protected virtual async Task <ISegmentManager> CreateManagerAsync(PlsParser pls, IWebReader webReader, CancellationToken cancellationToken) { var trackUrl = await _plsSegmentManagerPolicy.GetTrackAsync(pls, webReader.ContentType, cancellationToken); ISegmentManager segmentManager; if (null == trackUrl) { segmentManager = null; } else { var contentType = await webReader.DetectContentTypeAsync(trackUrl, ContentKind.AnyMedia, cancellationToken); if (null == contentType) { Debug.WriteLine("PlsSegmentManagerFactory.CreateSegmentManager() unable to detect type for " + trackUrl); segmentManager = null; } else { segmentManager = new SimpleSegmentManager(webReader, new[] { trackUrl }, contentType); } } return(segmentManager); }
protected virtual async Task <ISegmentManager> ReadPlaylistAsync(IWebReader webReader, Uri url, Stream stream, CancellationToken cancellationToken) { var pls = new PlsParser(url); using (var streamReader = new StreamReader(stream)) { var ret = await pls.ParseAsync(streamReader); if (!ret) { return(null); } } var segmentManager = await CreateManagerAsync(pls, webReader, cancellationToken); return(segmentManager); }
private void HandleTrack(string line, string key, string value) { int startOfTrackNumber = PlsParser.FindStartOfTrackNumber(key); if (startOfTrackNumber < 0) { Debug.WriteLine("PlsParser.HandleTrack() unable to find track number: " + line); } else { string b = key.Substring(0, startOfTrackNumber + 1).Trim(); int result1; if (!int.TryParse(key.Substring(startOfTrackNumber + 1, key.Length - (startOfTrackNumber + 1)), NumberStyles.Integer, (IFormatProvider)CultureInfo.InvariantCulture, out result1)) { Debug.WriteLine("PlsParser.HandleTrack() invalid track number: " + line); } else { PlsTrack plsTrack; if (!_tracks.TryGetValue(result1, out plsTrack)) { plsTrack = new PlsTrack(); _tracks[result1] = plsTrack; } if (string.Equals("File", b)) { if (null != plsTrack.File) { Debug.WriteLine("PlsParser.Parser() duplicate file property for entry {0}: {1}", (object)result1, (object)line); } else { plsTrack.File = value; } } else if (string.Equals("Title", b)) { if (null != plsTrack.Title) { Debug.WriteLine("PlsParser.Parser() duplicate title property for entry {0}: {1}", (object)result1, (object)line); } else { plsTrack.Title = value; } } else if (string.Equals("Length", b)) { if (plsTrack.Length.HasValue) { Debug.WriteLine("PlsParser.Parser() duplicate length property for entry {0}: {1}", (object)result1, (object)line); } else { Decimal result2; if (!Decimal.TryParse(value, NumberStyles.Number, (IFormatProvider)CultureInfo.InvariantCulture, out result2)) { Debug.WriteLine("PlsParser.Parser() invalid length property for entry {0}: {1}", (object)result1, (object)line); } else { try { plsTrack.Length = new TimeSpan?(TimeSpan.FromSeconds((double)result2)); } catch (InvalidCastException ex) { Debug.WriteLine("PlsParser.Parser() invalid numeric length property for entry {0}: {1}", (object)result1, (object)line); } } } } else { Debug.WriteLine("PlsParser.Parse() unknown property: " + line); } } } }