Exemplo n.º 1
0
        public static M3U8Segment[] AnalyzeSegments(Uri urlfix, string content)
        {
            var lst  = new List <M3U8Segment>();
            var strs = content.Split('\n');

            for (var index = 0; index < strs.Length; index++)
            {
                var str = strs[index].Trim();
                if (str.StartsWith("#EXTINF:"))
                {
                    str = str.Remove(0, 8).TrimEnd(',');
                    if (double.TryParse(str, out var dr))
                    {
                        var target = strs[++index];
                        if (target.StartsWith("/"))
                        {
                            target = urlfix.Scheme + "://" + urlfix.Authority + target;
                        }
                        else if (!target.Contains("://"))
                        {
                            target = urlfix + target;
                        }
                        var segment = new M3U8Segment(new Uri(target), dr);
                        lst.Add(segment);
                    }
                }
            }
            return(lst.ToArray());
        }
Exemplo n.º 2
0
        /// <summary>
        /// </summary>
        /// <param name="node"></param>
        /// <param name="savedir"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="DirectoryNotFoundException"></exception>
        /// <exception cref="PathTooLongException"></exception>
        public static bool DownloadM3U8Segment(M3U8Segment node, string savedir, WebClient client = null)
        {
            try
            {
                System.Diagnostics.Trace.TraceInformation($"{DateTime.Now} {Thread.CurrentThread.ManagedThreadId} Download {node.SegmentName}");

                var file = Path.Combine(savedir, node.SegmentName);
                if (client == null)
                {
                    client = new WebClient();
                }
                client.DownloadFile(node.Target, file);
                if (File.Exists(file))
                {
                    var finfo = new FileInfo(file);
                    node.Size = finfo.Length;
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceWarning($"Catch Ex When Download {node.SegmentName},{ex.Message}");
                return(false);
            }
        }
Exemplo n.º 3
0
 public M3U8SegmentDownloadedEventArgs(M3U8Segment node, M3U8File file)
 {
     Segment  = node;
     M3U8File = file;
 }
Exemplo n.º 4
0
 public M3U8VideoDownloadProgressChangedArgs(M3U8File file, M3U8Segment node)
 {
     File       = file;
     Node       = node;
     TotalCount = file.Segments.Length;
 }