static HlsStreamInfoFormatter() { VideoDimension = new DelegateHlsStreamInfoFormatter(streamInfo => string.Format("{0}x{1}", streamInfo.Width, streamInfo.Height)); Bitrate = new DelegateHlsStreamInfoFormatter(streamInfo => string.Format("Bitrate: {0} Kbps", streamInfo.Bandwidth / 1000)); VideoDimensionAndBitrate = new DelegateHlsStreamInfoFormatter(streamInfo => string.Format("{0} ({1})", VideoDimension.Format(streamInfo), Bitrate.Format(streamInfo))); }
/// <summary> /// Parse a m3u8 playlist into a dictionary with streamname and streamurl /// Sorting and streamname are customizable /// </summary> /// <param name="playlist">the m3u8 data</param> /// <param name="url">url to use if the m3u8 data contains relative urls</param> /// <param name="comparer">comparing two HlsStreamInfo, used in the sorting</param> /// <param name="formatter">formating display string for a given HlsStreamInfo</param> /// <returns>Dictionary with the streamnames and urls</returns> public static Dictionary <string, string> GetPlaybackOptions(string playlist, string url, HlsStreamInfoComparer comparer, HlsStreamInfoFormatter formatter) { Dictionary <string, string> playbackOptions = new Dictionary <string, string>(); var tmp = new HlsPlaylistParser(playlist, url); foreach (var streamInfo in tmp.StreamInfos.OrderBy(info => info, comparer)) { var streamName = formatter.Format(streamInfo); if (!playbackOptions.ContainsKey(streamName)) { playbackOptions.Add(streamName, streamInfo.Url); } } return(playbackOptions); }
/// <summary> /// Parse a m3u8 playlist into a dictionary with streamname and streamurl /// Sorting is done from high to low bandwidth, and streamname is customizable /// </summary> /// <param name="playlist">the m3u8 data</param> /// <param name="url">url to use if the m3u8 data contains relative urls</param> /// <param name="formatter">delegate returning the formatted string for a given HlsStreamInfo</param> /// <returns>Dictionary with the streamnames and urls</returns> public static Dictionary <string, string> GetPlaybackOptions(string playlist, string url, HlsStreamInfoFormatter formatter) { return(GetPlaybackOptions(playlist, url, HlsStreamInfoComparer.BandwidthHighLow, formatter)); }