예제 #1
0
        private void Tõmba_Click(object sender, EventArgs e)
        {
            kõik          = string.Empty;
            Protsenttekst = string.Empty;
            protsent      = 0;

            progressBar1.Visible = true;
            int i = 1;

            formaat = Convert.ToString(FormatList.SelectedItem);
            if (!valeLink)
            {
                if ((formaat != "wav" && formaat != "mp3" || !string.IsNullOrWhiteSpace(ffmpeg) || File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "ffmpeg.exe"))) && !valeLink)
                {
                    if (formaat == "mp4")
                    {
                        switch (i)
                        {
                        case 1:     //720p
                            index = 22;
                            i++;
                            break;

                        case 2:     //360p
                            index = 18;
                            i++;
                            break;
                        }
                    }
                    if (formaat == "m4a")
                    {
                        index = 140;
                    }
                    if (File.Exists("ffprobe.exe") && File.Exists("ffmpeg.exe"))
                    {
                        ffmpeg = "olemas";
                        YTdl   = Path.Combine(Directory.GetCurrentDirectory(), "youtube-dl.exe");
                    }

                    if (!string.IsNullOrWhiteSpace(link) || !string.IsNullOrWhiteSpace(TXTFail) && !string.IsNullOrWhiteSpace(formaat))
                    {
                        if (string.IsNullOrWhiteSpace(path))
                        {
                            path = Directory.GetCurrentDirectory();
                        }
                        while (true)
                        {
                            var convert = new Process();
                            convert.StartInfo.FileName = "youtube-dl.exe";
                            if (!string.IsNullOrWhiteSpace(NimeBox.Text))
                            {
                                //f**k me
                            }
                            else
                            {
                                if (!link.Contains("playlist"))
                                {
                                    var fileName = new Process
                                    {
                                        StartInfo = new ProcessStartInfo
                                        {
                                            FileName               = "youtube-dl.exe",
                                            Arguments              = "--get-filename " + link,
                                            UseShellExecute        = false,
                                            RedirectStandardOutput = true,
                                            CreateNoWindow         = true
                                        }
                                    };
                                    fileName.Start();
                                    failiNimi = fileName.StandardOutput.ReadToEnd();
                                    fileName.WaitForExit();
                                    failiNimi = failiNimi.Replace("\n", "");
                                    convert.StartInfo.Arguments = "-f " + index + " -o " + "\u0022" + path + @"\" + failiNimi + "\u0022" + " " + link;
                                }
                            }
                            if (!KonsooliNäha.Checked)
                            {
                                convert.StartInfo.UseShellExecute = false;
                                convert.StartInfo.CreateNoWindow  = true;
                            }
                            if (valeLink)
                            {
                                break;
                            }
                            if (!string.IsNullOrWhiteSpace(YTdl))
                            {
                                convert.StartInfo.FileName = YTdl;
                            }
                            if (!link.Contains("playlist") && NimeBox.Text == "" && path != Directory.GetCurrentDirectory())
                            {
                                if (!string.IsNullOrWhiteSpace(ffmpeg) && !string.IsNullOrWhiteSpace(YTdl))
                                {
                                    if (formaat == "wav" || formaat == "mp3" || formaat == "m4a")
                                    {
                                        if (!string.IsNullOrWhiteSpace(NimeBox.Text))
                                        {
                                            convert.StartInfo.Arguments = "--extract-audio --audio-format " + formaat + " --output " + "\u0022" + path + @"\" + failiNimi.Replace("\n", "") + ".mp4" + "\u0022" + " " + link;
                                        }
                                        else
                                        {
                                            convert.StartInfo.Arguments = "--extract-audio --audio-format " + formaat + " -o " + "\u0022" + path + @"\" + failiNimi + "\u0022" + " " + link;
                                            failiNimi = failiNimi.Replace(".mp4", "." + formaat);
                                        }
                                    }
                                }
                                if (!string.IsNullOrWhiteSpace(TXTFail))
                                {
                                    if (formaat == "wav" || formaat == "mp3" || formaat == "m4a")
                                    {
                                        convert.StartInfo.Arguments = "--extract-audio --audio-format " + formaat + " -a " + TXTFail;
                                    }
                                    else
                                    {
                                        convert.StartInfo.Arguments = "-f " + index + " -a " + TXTFail;
                                    }
                                }
                            }
                            else
                            {
                                if (NimeBox.Text == "")
                                {
                                    convert.StartInfo.Arguments = "--extract-audio --audio-format " + formaat + " " + link;
                                }
                                else if (formaat == "mp4")
                                {
                                    convert.StartInfo.Arguments = "-f " + index + " -o " + "\u0022" + path + @"\" + failiNimi + ".mp4" + "\u0022" + " " + link;
                                }
                                else
                                {
                                    convert.StartInfo.Arguments = "--extract-audio --audio-format " + formaat + " --output " + "\u0022" + path + @"\" + failiNimi.Replace("\n", "") + ".mp4" + "\u0022" + " " + link;
                                }
                            }
                            failiNimi = failiNimi.Replace(".webm", "." + formaat);
                            failiNimi = failiNimi.Replace(".mp4", "." + formaat);
                            if (!File.Exists(path + @"\" + failiNimi))
                            {
                                while (true)
                                {
                                    if (!KonsooliNäha.Checked)
                                    {
                                        convert.StartInfo.RedirectStandardOutput = true;
                                        convert.Start();
                                        if (!link.Contains("playlist"))
                                        {
                                            for (int a = 0; a < 6; a++)
                                            {
                                                kõik = convert.StandardOutput.ReadLine();
                                            }
                                        }
                                        else
                                        {
                                            for (int a = 0; a < 15; a++)
                                            {
                                                kõik = convert.StandardOutput.ReadLine();
                                                if (a == 2)
                                                {
                                                    kõik = Regex.Match(kõik, @"\d+").Value;
                                                    playlistVideoNumber = Int32.Parse(kõik);
                                                }
                                            }
                                        }
                                        if (!link.Contains("playlist"))
                                        {
                                            playlistVideoNumber = 1;
                                        }
                                        for (int a = 0; a < playlistVideoNumber; a++)
                                        {
                                            while (protsent != 100)
                                            {
                                                kõik = convert.StandardOutput.ReadLine();
                                                Kook = kõik;
                                                if (kõik != null)
                                                {
                                                    Protsenttekst = kõik.Substring(11, 6);
                                                    //Protsenttekst = Regex.Replace(Protsenttekst, "[^0-9.]", "");
                                                    Protsenttekst = Regex.Match(Protsenttekst, @"\d+").Value;
                                                    try
                                                    {
                                                        protsent = Int32.Parse(Protsenttekst);
                                                    }
                                                    catch (Exception)
                                                    {
                                                        MessageBox.Show("See fail juba eksisteerib");
                                                        throw;
                                                    }
                                                    progressBar1.Value = protsent;
                                                    using (Graphics gr = progressBar1.CreateGraphics())
                                                    {
                                                        gr.DrawString(Kook.ToString(),
                                                                      SystemFonts.DefaultFont,
                                                                      Brushes.Black,
                                                                      new PointF(progressBar1.Width / 2 - (gr.MeasureString(Kook.ToString(),
                                                                                                                            SystemFonts.DefaultFont).Width / 2.0F),
                                                                                 progressBar1.Height / 2 - (gr.MeasureString(Kook.ToString(),
                                                                                                                             SystemFonts.DefaultFont).Height / 2.0F)));
                                                    }
                                                }
                                                else
                                                {
                                                    if (formaat == "mp4")
                                                    {
                                                        switch (i)
                                                        {
                                                        case 1:     //720p
                                                            index = 22;
                                                            i++;
                                                            break;

                                                        case 2:     //360p
                                                            index = 18;
                                                            i++;
                                                            break;
                                                        }
                                                        convert.StartInfo.Arguments = convert.StartInfo.Arguments = "-f " + index + " -o " + "\u0022" + path + @"\" + failiNimi + ".mp4" + "\u0022" + " " + link;
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("Link ei tööta");
                                                        valeLink = true;
                                                        lõpetada = true;
                                                        break;
                                                    }
                                                    break;
                                                }
                                                if (protsent == 100 && link.Contains("playlist"))
                                                {
                                                    for (int b = 0; b < 10; b++)
                                                    {
                                                        kõik = convert.StandardOutput.ReadLine();
                                                    }
                                                }
                                            }
                                            protsent = 0;
                                        }
                                        convert.WaitForExit();
                                        if (File.Exists(path + @"\" + failiNimi) || File.Exists(path + @"\" + failiNimi + "." + formaat) || lõpetada)
                                        {
                                            break;
                                        }
                                    }

                                    else
                                    {
                                        while (true)
                                        {
                                            convert.Start();
                                            convert.WaitForExit();
                                            if (File.Exists(path + @"\" + failiNimi) || File.Exists(path + @"\" + failiNimi + "." + formaat))
                                            {
                                                break;
                                            }
                                            else
                                            {
                                                switch (i)
                                                {
                                                case 1:     //720p
                                                    index = 22;
                                                    i++;
                                                    break;

                                                case 2:     //360p
                                                    index = 18;
                                                    i++;
                                                    break;
                                                }
                                                convert.StartInfo.Arguments = convert.StartInfo.Arguments = "-f " + index + " -o " + "\u0022" + path + @"\" + failiNimi + ".mp4" + "\u0022" + " " + link;
                                            }
                                        }
                                        break;
                                    }
                                }

                                if (string.IsNullOrWhiteSpace(TXTFail) && !link.Contains("playlist"))
                                {
                                    if (!string.IsNullOrWhiteSpace(NimeBox.Text))
                                    {
                                        if (File.Exists(path + @"\" + failiNimi + "." + formaat))
                                        {
                                            MessageBox.Show("Teie video on alla laetud");
                                            LinkBox.Text = "";
                                            FormatList.ResetText();
                                            NimeBox.Text       = "";
                                            progressBar1.Value = 0;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        if (File.Exists(path + @"\" + failiNimi) || File.Exists(path + @"\" + failiNimi + "." + formaat))
                                        {
                                            MessageBox.Show("Teie video on alla laetud");
                                            LinkBox.Text = "";
                                            FormatList.ResetText();
                                            NimeBox.Text       = "";
                                            progressBar1.Value = 0;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Teie videod on alla laetud");
                                    LinkBox.Text = "";
                                    FormatList.ResetText();
                                    NimeBox.Text       = "";
                                    progressBar1.Value = 0;
                                    break;
                                }
                            }
                            else
                            {
                                MessageBox.Show("See video/audio on teil juba seal olemas");
                                progressBar1.Value = 0;
                                break;
                            }
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Palun täida kõik väljad ja tee kindlaks, et link on õige");
                    }
                }
                else
                {
                    if (!valeLink)
                    {
                        MessageBox.Show("Palun lisage ffmpeg ja ffprobe directory või pange see samasse folderisse, kus on see programm");
                    }
                    else
                    {
                        MessageBox.Show("Sisestatud link ei tööta, palun asendage see millegi muuga");
                    }
                }
            }
            else
            {
                MessageBox.Show("Sisestatud link ei tööta, palun asendage see millegi muuga");
            }
        }
예제 #2
0
 private void ClearButton_Click(object sender, EventArgs e)
 {
     LinkBox.Text = "";
     FormatList.ResetText();
     NimeBox.Text = "";
 }