Beispiel #1
0
 public static void ConcatFiles(string ConcatList, string DestFilePath)
 {
     //TODO add error catching for the ffmpeg process erroring.
     if (!File.Exists(ConcatList))
     {
         throw new ArgumentException(String.Format("{0} does not exist", ConcatList));
     }
     try
     {
         System.Diagnostics.Process          process   = new System.Diagnostics.Process();
         System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
         startInfo.Arguments       = "/c " + ffmpegDir + " -f concat -i \"" + ConcatList + "\" -c copy \"" + DestFilePath + "\"";
         startInfo.FileName        = "cmd.exe";
         startInfo.UseShellExecute = false;
         process.StartInfo         = startInfo;
         process.StartInfo.RedirectStandardOutput = true;
         process.StartInfo.UseShellExecute        = false;
         process.Start();
         DebugLog.Log(String.Format("Concat of file {0}", ConcatList));
         process.WaitForExit();
         DebugLog.Log("Concat done");
     }
     catch (IOException ioex)
     {
         throw new IOException("Unable to write/access concat files", ioex);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #2
0
 public static void ConvertFile(String InputFilePath, String OutputFilePath)
 {
     //TODO add error catching for the ffmpeg process erroring.
     //TODO should probably check or add mp4 to the end of the outfile
     if (!File.Exists(InputFilePath))
     {
         throw new ArgumentException(String.Format("{0} does not exist", InputFilePath));
     }
     try
     {
         System.Diagnostics.Process          process   = new System.Diagnostics.Process();
         System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
         startInfo.Arguments       = "/c " + ffmpegDir + " -i \"" + InputFilePath + "\" -bsf:a aac_adtstoasc -c copy \"" + OutputFilePath + "\"";
         startInfo.FileName        = "cmd.exe";
         startInfo.UseShellExecute = false;
         process.StartInfo         = startInfo;
         process.StartInfo.RedirectStandardOutput = true;
         process.StartInfo.UseShellExecute        = false;
         process.Start();
         DebugLog.Log(String.Format("Convert of file {0}", InputFilePath));
         process.WaitForExit();
         DebugLog.Log("Convert done");
     }
     catch (IOException ioex)
     {
         throw new IOException("Unable to write/access concat files", ioex);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #3
0
            private void CreateM3List(string ListFilePath)
            {
                if (!File.Exists(ListFilePath))
                {
                    throw new ArgumentException(String.Format("File at {0} does not exist", ListFilePath));
                }
                List <string> lines       = File.ReadLines(ListFilePath).ToList <string>();
                List <string> links       = new List <string>();
                bool          startedLink = false;
                string        conLink     = "";
                string        endtime     = "";

                foreach (string line in lines)
                {
                    if (line.Contains("start_offset=0"))
                    {
                        if (!String.IsNullOrEmpty(conLink))
                        {
                            links.Add(String.Format("{0}?start_offset=0&end_offset={1}", conLink, endtime));
                        }
                        conLink = line.Substring(0, line.IndexOf("?start_offset"));
                        //startedLink = true;
                    }
                    else if (line.Contains("end_offset="))
                    {
                        endtime = line.Substring(line.IndexOf("end_offset=") + 11); //offset for length of phrase
                    }
                }
                File.WriteAllLines(Directory.GetCurrentDirectory() + "\\linklist.txt", links.ToArray());
                DownloadProcess dp = new DownloadProcess(links);

                DebugLog.Log("Download process start -" + System.DateTime.Now.ToString());
                dp.StartDownload();
            }
Beispiel #4
0
        private void ProcessFile(BackgroundWorker worker, RunWorkerCompletedEventArgs e)
        {
            String next = GetNextFile();

            if (!String.IsNullOrEmpty(next))
            {
                worker.RunWorkerAsync(next);
            }
            else
            {
                DebugLog.Log("Worker done -" + System.DateTime.Now.ToString());
                worker.Dispose();
                WorkList.Remove(worker);
                if (WorkList.Count == 0)
                {
                    //File.AppendAllLines(CatFile, downloadedFiles);
                    DebugLog.Log("All workders done");
                    videoWorker.RunWorkerAsync();
                }
            }
            //if(FileList.Count > 0)
            //{
            //    //DebugLog.Log("Download file");
            //    //DownloadFile(FileList.First(), GetFileNameFromURL(FileList.First()));
            //    worker.RunWorkerAsync(FileList.First());
            //    FileList.RemoveAt(0); //TODO this will probably not work since the threads will collide on accessing the list
            //}
        }
Beispiel #5
0
 public void StartDownload()
 {
     CreateConcatFile();
     foreach (BackgroundWorker worker in WorkList)
     {
         DebugLog.Log("Spawn worker");
         worker.RunWorkerAsync(GetNextFile());
         System.Threading.Thread.Sleep(50);
     }
 }
Beispiel #6
0
        private String GetFileNameFromURL(String URL)
        {
            if (String.IsNullOrEmpty(URL))
            {
                throw new ArgumentException("Cannot get file name");
            }
            int firstIndex = URL.LastIndexOf("/");
            int lastIndex  = URL.IndexOf("?");

            DebugLog.Log(URL.Substring(firstIndex + 1, (lastIndex - (firstIndex + 1))));
            return(URL.Substring(firstIndex + 1, (lastIndex - (firstIndex + 1))));
        }
Beispiel #7
0
 public static String APIRequest(String URL)
 {
     try
     {
         HttpWebRequest  request   = (HttpWebRequest)System.Net.WebRequest.Create(URL);
         HttpWebResponse response  = (HttpWebResponse)request.GetResponse();
         Stream          resStream = response.GetResponseStream();
         StreamReader    sr        = new StreamReader(resStream);
         //TODO Error handling
         return(sr.ReadToEnd());
     }
     catch (Exception ex)
     {
         DebugLog.Log(String.Format("Request error for {0}\r\n{1}", URL, ex.ToString()));
         return(null);
     }
 }
Beispiel #8
0
 public DownloadProcess(List <String> ListOfFiles)
 {
     if (ListOfFiles.Count == 0)
     {
         throw new ArgumentException("No files for download");
     }
     FileList       = ListOfFiles;
     downloadPath   = @"T:\Videos\twitch"; //Directory.GetCurrentDirectory() + "\\Videos\\Download";
     CatFile        = downloadPath + "\\" + GetVodName(FileList.First()) + ".txt";
     catVideoName   = downloadPath + "\\" + GetVodName(FileList.First()) + ".ts";
     finalVideoName = downloadPath + "\\" + GetVodName(FileList.First()) + ".mp4";
     DebugLog.Log("Cat file " + CatFile);
     InitializeWorkers();
     fileCount       = 0;
     lockObj         = new Object();
     downloadedFiles = new List <string>();
 }
Beispiel #9
0
            private string ParseStreamLink(string Link)
            {
                int index = Link.LastIndexOf('/'); //Link.IndexOf("/index");

                if (index <= 0)
                {
                    DebugLog.Log("Cannot find m3u8: " + Link);
                    throw new Exception("Unable to parse stream link");
                }
                string sub = Link.Substring(0, index + 1);

                //string sub = Link.Substring(0, Link.IndexOf("index-dvr.m3u8"));
                if (sub.Length <= 0)
                {
                    return("");
                }
                return(sub);
            }
Beispiel #10
0
 private void DownloadFile(String FileURL, String FileName)
 {
     try
     {
         //lock (lockObj)
         //{
         using (WebClient client = new WebClient())
         {
             fileCount++;
             //string downPath = downloadPath + "\\" + fileCount.ToString() + "." + FileName;
             string downPath = downloadPath + "\\" + FileName;
             //File.AppendAllText(CatFile, String.Format("file '{0}'\r\n", downPath));
             downloadedFiles.Add(downPath);
             client.DownloadFile(FileURL, downPath);
         }
         //}
     }
     catch (Exception ex)
     {
         DebugLog.Log(String.Format("Download error on {0}\r\n{1}", FileURL, ex.ToString()));
     }
 }
Beispiel #11
0
 void videoWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     DebugLog.Log(String.Format("Start video process {0} {1}", catVideoName, finalVideoName));
     VideoProcess.ConcatFiles(CatFile, catVideoName);
 }