public void mergeChunks(PlaylistM3U8 pl, List <VideoChunk> lvc)
 {
     try
     {
         uint           i  = 0;
         RefreshingLine rl = new RefreshingLine(string.Format("Start merging {0} chunkds", lvc.Count));
         using (var outputStream = File.Create("mid_" + pl.meetingID + ".ts"))
         {
             foreach (VideoChunk vc in lvc)
             {
                 string chunkFile = Path.GetFileName(vc.file.AbsolutePath);
                 rl.WriteRefreshLine(string.Format("Merging chunk {0} / {1} / {2:0.00}%", i, chunkFile, ((i++ + 1) / (float)lvc.Count) * 100));
                 using (var inputStream = File.OpenRead(vc.file.LocalPath))
                 {
                     int    readCount;
                     byte[] buffer = new byte[1024];
                     while ((readCount = inputStream.Read(buffer, 0, buffer.Length)) != 0)
                     {
                         outputStream.Write(buffer, 0, readCount);
                     }
                     inputStream.Close();
                     File.Delete(vc.file.LocalPath);
                 }
             }
             outputStream.Close();
             rl.NewWriteLine("Merging is complete");
             Process.Start("mid_" + pl.meetingID + ".ts");
         }
     }
     catch (Exception)
     {
         throw new Exception("Cannot merging chunks");
     }
 }
        public List <VideoChunk> loadPlaylist(PlaylistM3U8 pl)
        {
            Console.WriteLine("Loading meeting id " + pl.meetingID + " video chunks ...");
            string reCL = webReq.getRequest(pl.chunklist.AbsoluteUri, String.Empty);

            uint i = 0;
            List <VideoChunk> lvc    = new List <VideoChunk>();
            Uri            localPath = pl.getLocalUri();
            RefreshingLine rl        = new RefreshingLine("Creates chunks list...");

            try
            {
                string       line;
                StringReader reader = new StringReader(reCL);
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.StartsWith("media"))
                    {
                        rl.WriteRefreshLine(string.Format("Add chunk number {0}", i));
                        lvc.Add(new VideoChunk(new Uri(localPath.AbsoluteUri + Uri.UnescapeDataString(line))));
                        i++;
                    }
                }
                ;
                rl.NewWriteLine(string.Format("Finsh - added {0} chunks", i));
                return(lvc);
            }
            catch (Exception)
            {
                throw new Exception("Cannot create chunks list");
            }
        }
        public List <VideoChunk> downloadMeeting(PlaylistM3U8 pl, List <VideoChunk> lvc)
        {
            string            dirName = Path.GetTempPath() + "\\ClassBoostDownloader_" + DateTime.Now.ToFileTime() + "_" + pl.meetingID;
            List <VideoChunk> reLvc   = new List <VideoChunk>();

            if (Directory.CreateDirectory(dirName).Exists)
            {
                try
                {
                    uint           i  = 0;
                    RefreshingLine rl = new RefreshingLine(string.Format("Starting download {0} chunkds", lvc.Count));
                    foreach (VideoChunk vc in lvc)
                    {
                        using (var client = new WebClient())
                        {
                            string chunkFile = Path.GetFileName(vc.file.AbsoluteUri);
                            if (vc.file.Query.Length > 0)
                            {
                                chunkFile = chunkFile.Replace(vc.file.Query, String.Empty);
                            }
                            rl.WriteRefreshLine(string.Format("Download chunk {0} / {1} / {2:0.00}%", i, chunkFile, ((i++ + 1) / (float)lvc.Count) * 100));
                            chunkFile = dirName + "\\" + chunkFile;
                            client.DownloadFile(vc.file, chunkFile);
                            reLvc.Add(new VideoChunk(new Uri(chunkFile)));
                        }
                    }
                    rl.NewWriteLine("Download complete");
                    return(reLvc);
                }
                catch (Exception)
                {
                    throw new Exception("Cannot download chunk");
                }
            }
            else
            {
                throw new Exception("Cannot create download directory");
            }
        }