コード例 #1
0
        private async Task <int> download_async(dl_item d)
        {
            TaskCompletionSource <int> ret = new TaskCompletionSource <int>();
            Process cmd = new Process();

            cmd.StartInfo.FileName = "youtube-dl.exe";
            cmd.StartInfo.RedirectStandardInput  = true;
            cmd.StartInfo.RedirectStandardOutput = true;
            cmd.StartInfo.CreateNoWindow         = true;
            cmd.StartInfo.UseShellExecute        = false;
            cmd.Exited             += (s, ea) => ret.SetResult(cmd.ExitCode);
            cmd.OutputDataReceived += (s, ea) => Debug.WriteLine(ea.Data);
            if (proxy == "")
            {
                cmd.StartInfo.Arguments = d.url;
            }
            else
            {
                cmd.StartInfo.Arguments = $"--proxy {proxy} {d.url}";
            }
            cmd.Start();
            cmd.BeginOutputReadLine();
            await ret.Task;

            return(ret.Task.Result);
        }
コード例 #2
0
        public void add(string url)
        {
            Debug.WriteLine($"Adding '{url}' to downloadlist.");
            dl_item d = new dl_item(url);

            urls.Add(d);
            start_download(d);
            Debug.WriteLine(proxy);
        }
コード例 #3
0
 public void start_download(dl_item d)
 {
     if (running_threads < max_threads)
     {
         running_threads++;
         d.status &= ~dl_state.notstarted;
         d.status |= dl_state.running;
         if (download(d) != 0)
         {
             d.status |= dl_state.error;
         }
         d.status &= ~dl_state.running;
         running_threads--;
     }
 }
コード例 #4
0
        public async Task start_download_async(dl_item d)
        {
            if (running_threads < max_threads)
            {
                running_threads++;
                d.status &= ~dl_state.notstarted;
                d.status |= dl_state.running;
                int r = await download_async(d);

                if (r != 0)
                {
                    d.status |= dl_state.error;
                }
                d.status &= ~dl_state.running;
                running_threads--;
            }
        }
コード例 #5
0
        public int download(dl_item d)
        {
            int     ret = 0;
            Process cmd = new Process();

            cmd.StartInfo.FileName = "youtube-dl.exe";
            cmd.StartInfo.RedirectStandardInput  = true;
            cmd.StartInfo.RedirectStandardOutput = true;
            cmd.StartInfo.CreateNoWindow         = true;
            //cmd.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            cmd.StartInfo.UseShellExecute = false;
            if (proxy == "")
            {
                cmd.StartInfo.Arguments = d.url;
            }
            else
            {
                cmd.StartInfo.Arguments = $"--proxy {proxy} {d.url}";
            }
            cmd.Start();
            StreamReader sr = cmd.StandardOutput;

            while (!sr.EndOfStream)
            {
                String s = sr.ReadLine();
                if (s != "")
                {
                    Debug.WriteLine(s);
                    d.output.Add(s);
                }
            }
            sr.ReadToEnd();
            cmd.WaitForExit();
            if (cmd.ExitCode != 0)
            {
                ret = cmd.ExitCode;
            }
            return(ret);
        }
コード例 #6
0
 public dl_EventArgs(dl_item i)
 {
     ea_dl_item = i;
 }