コード例 #1
0
        /// <summary>
        /// Deletes the selected object from the list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Deletebtn_Click(object sender, RoutedEventArgs e)
        {
            UrlStuffLol stuffLol = lvUrls.SelectedItem as UrlStuffLol;

            if (stuffLol != null)
            {
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                {
                    items.Remove(stuffLol);
                }));
                lvUrls.ItemsSource = items;
                lvUrls.Items.Refresh();
            }
        }
コード例 #2
0
        /// <summary>
        /// Feeds the youtube url with the specified options.
        /// </summary>
        /// <param name="videoID"></param>
        /// <param name="pl"></param>
        /// <param name="fromList"></param>
        /// <param name="stuffLol"></param>
        public void GetAudioByID(string videoID, bool pl, [Optional] bool fromList, [Optional] UrlStuffLol stuffLol)
        {
            //checks if any of the playlist options are checked and if they have empty strings. very long if
            if (((plStartNum.IsChecked ?? false) && (String.IsNullOrEmpty(plStartN) || String.IsNullOrWhiteSpace(plStartN))) || ((plEndNum.IsChecked ?? false) && (String.IsNullOrEmpty(plEndN) || String.IsNullOrWhiteSpace(plEndN))) || ((plSpecify.IsChecked ?? false) && ((String.IsNullOrEmpty(plItemN) || String.IsNullOrWhiteSpace(plItemN)))))
            {
                MessageBox.Show("Please enter values for the:\nPlaylist Start\nPlaylist End\nor\nPlaylist Items");
                return;
            }

            cmdOutput.Content = "Processing...";

            outputPath.IsEnabled    = false;
            outputPathBox.IsEnabled = false;

            //this makes cmd run in the background
            ProcessStartInfo cmdStartInfo = new ProcessStartInfo
            {
                FileName               = @"C:\Windows\System32\cmd.exe",
                WorkingDirectory       = $@"{outputPathBox.Text}",
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                UseShellExecute        = false,
                CreateNoWindow         = true
            };

            Process cmdProcess = new Process();

            cmdProcess.StartInfo           = cmdStartInfo;
            cmdProcess.ErrorDataReceived  += cmd_Error;
            cmdProcess.OutputDataReceived += cmd_DataReceived;
            cmdProcess.EnableRaisingEvents = true;
            cmdProcess.Start();
            cmdProcess.BeginOutputReadLine();
            cmdProcess.BeginErrorReadLine();

            //starts the procedure
            if (forcePlaylist.IsChecked ?? false)
            {
                //if the force playlist is checked, it passes the regex control and directly comes here (for another regex control)
                //because the regex i used there only gets video and playlist id's,
                //with video id's being the priority.
                //so i had to pass the whole url for the youtube-dl to see
                //so it can download the playlist. duh xd
                //this brings some problems of course, but i left youtube-dl to deal with them.
                string ffmpegoutput = "";
                if (ffmpegD.IsChecked ?? false)
                {
                    ffmpegoutput = $"--ffmpeg-location {Ffmpegpath}";
                }

                string geo = "--no-geo-bypass";
                if (geoBypass.IsChecked ?? false)
                {
                    geo = "--geo-bypass";
                }

                string tnail = "";
                if (thumbnail.IsChecked ?? false)
                {
                    tnail = "--embed-thumbnail";
                }

                string mdata = "";
                if (metadata.IsChecked ?? false)
                {
                    mdata = "--add-metadata";
                }

                string chDate = "--no-mtime";
                if (changeDate.IsChecked ?? false)
                {
                    chDate = "";
                }

                string RevRan = "";
                if (plReverse.IsChecked ?? false)
                {
                    RevRan = "--playlist-reverse";
                }
                else if (plRandom.IsChecked ?? false)
                {
                    RevRan = "--playlist-random";
                }

                string StartNumber = "";
                if (plStartNum.IsChecked ?? false)
                {
                    StartNumber = "--playlist-start " + plStartN;
                }

                string EndNumber = "";
                if (plEndNum.IsChecked ?? false)
                {
                    EndNumber = "--playlist-end " + plEndN;
                }

                string Items = "";
                if (plSpecify.IsChecked ?? false)
                {
                    Items = "--playlist-items " + plItemN;
                }

                if (urlBox.Text.ToLower().Contains("youtube") || urlBox.Text.ToLower().Contains("youtu.be"))
                {
                    //from stackoverflow, replaces '&'s with '^&' (i dont like regex xd)
                    string fixedamps = Regex.Replace(urlBox.Text, @" 
                            # Match & that is not part of an HTML entity.
                            &                  # Match literal &.
                            (?!                # But only if it is NOT...
                            \w+;               # an alphanumeric entity,
                            | \#[0-9]+;        # or a decimal entity,
                            | \#x[0-9A-F]+;    # or a hexadecimal entity.
                            )                  # End negative lookahead.",
                                                     "^&",
                                                     RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
                    //do it!!!
                    cmdProcess.StandardInput.WriteLine($@"youtube-dl --ignore-errors --output %(title)s.%(ext)s {geo} --extract-audio --audio-format mp3 --audio-quality 0 {RevRan} {StartNumber} {EndNumber} {Items} {tnail} {chDate} {mdata} --prefer-ffmpeg {ffmpegoutput} {fixedamps}");
                }
                else
                {
                    MessageBox.Show("Please enter a valid URL!\n(This might have happened because you ticked\n\"Force Playlist\" box. Try to download the whole playlist.)");
                }
            }
            else
            {
                string ffmpegoutput = "";
                if (ffmpegD.IsChecked ?? false)
                {
                    ffmpegoutput = $"--ffmpeg-location {Ffmpegpath}";
                }

                string geo = "--no-geo-bypass";
                if (geoBypass.IsChecked ?? false)
                {
                    geo = "--geo-bypass";
                }

                string tnail = "";
                if (thumbnail.IsChecked ?? false)
                {
                    tnail = "--embed-thumbnail";
                }

                string mdata = "";
                if (metadata.IsChecked ?? false)
                {
                    mdata = "--add-metadata";
                }

                string chDate = "--no-mtime";
                if (changeDate.IsChecked ?? false)
                {
                    chDate = "";
                }

                string RevRan = "";
                if (plReverse.IsChecked ?? false)
                {
                    RevRan = "--playlist-reverse";
                }
                else if (plRandom.IsChecked ?? false)
                {
                    RevRan = "--playlist-random";
                }

                string StartNumber = "";
                if (plStartNum.IsChecked ?? false)
                {
                    StartNumber = "--playlist-start " + plStartN;
                }

                string EndNumber = "";
                if (plEndNum.IsChecked ?? false)
                {
                    EndNumber = "--playlist-end " + plEndN;
                }

                string Items = "";
                if (plSpecify.IsChecked ?? false)
                {
                    Items = "--playlist-items " + plItemN;
                }

                if (pl == true)
                {
                    cmdProcess.StandardInput.WriteLine($@"youtube-dl --ignore-errors --output %(title)s.%(ext)s {geo} --extract-audio --audio-format mp3 --audio-quality 0 {RevRan} {StartNumber} {EndNumber} {Items} {tnail} {chDate} {mdata} --prefer-ffmpeg {ffmpegoutput} {videoID}");
                }
                else if (pl == false)
                {
                    cmdProcess.StandardInput.WriteLine($@"youtube-dl --ignore-errors --output %(title)s.%(ext)s {geo} --no-playlist --extract-audio --audio-format mp3 --audio-quality 0 {tnail} {chDate} {mdata} --prefer-ffmpeg {ffmpegoutput} {videoID}");
                }
            }

            void cmd_DataReceived(object sender1, DataReceivedEventArgs e)
            {
                //this does the checks for the status thingie
                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    //if it stays null it throws ArgumentNullException.
                    Trial = e.Data;
                    if (Trial == null)
                    {
                        Trial = "";
                    }
                    else
                    {
                        if (Trial.ToLower().Contains("adding thumbnail to"))
                        {
                            cmdOutput.Content       = "Done!";
                            outputPath.IsEnabled    = true;
                            outputPathBox.IsEnabled = true;
                            if (fromList)
                            {
                                stuffLol.Status    = "Done!";
                                lvUrls.ItemsSource = items;
                                lvUrls.Items.Refresh();
                            }
                        }
                        else if (Trial.Contains("webpage"))
                        {
                            cmdOutput.Content = "Getting information...";
                            if (fromList)
                            {
                                stuffLol.Status    = "Getting information...";
                                lvUrls.ItemsSource = items;
                                lvUrls.Items.Refresh();
                            }
                        }
                        else if (Trial.ToLower().Contains("download") == true && Trial.ToLower().Contains("downloading") == false)
                        {
                            cmdOutput.Content = "Downloading...";
                            if (fromList)
                            {
                                stuffLol.Status    = "Downloading...";
                                lvUrls.ItemsSource = items;
                                lvUrls.Items.Refresh();
                            }
                        }
                        else if (Trial.ToLower().Contains("download") == false && Trial.ToLower().Contains("downloading") == true)
                        {
                        }
                        else if (Trial.ToLower().Contains("destination:") && Trial.ToLower().Contains(".mp3"))
                        {
                            cmdOutput.Content = "Converting...";
                            if (fromList)
                            {
                                stuffLol.Status    = "Converting...";
                                lvUrls.ItemsSource = items;
                                lvUrls.Items.Refresh();
                            }
                        }
                        else if (Trial.ToLower().Contains("deleting original file") && (!thumbnail.IsChecked ?? false))
                        {
                            cmdOutput.Content       = "Done!";
                            outputPath.IsEnabled    = true;
                            outputPathBox.IsEnabled = true;
                            if (fromList)
                            {
                                stuffLol.Status    = "Done!";
                                lvUrls.ItemsSource = items;
                                lvUrls.Items.Refresh();
                            }
                        }
                    }
                }));
            }

            //this function catches errors from cmd
            void cmd_Error(object sender2, DataReceivedEventArgs e)
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    //if it stays null it throws ArgumentNullException.
                    Trial = e.Data;
                    if (Trial == null)
                    {
                        Trial = "";
                    }
                    else if (Trial.ToLower().Contains("this playlist does not exist"))
                    {
                        //this else if in here works if the force playlist is ticked.
                        //catches wrong playlist id's.
                        cmdOutput.Content       = Trial;
                        outputPath.IsEnabled    = true;
                        outputPathBox.IsEnabled = true;
                    }
                    else if (Trial.ToLower().Contains("this video is unavailable"))
                    {
                        //catches bad video id's if force playlist is checked.
                        cmdOutput.Content       = Trial;
                        outputPath.IsEnabled    = true;
                        outputPathBox.IsEnabled = true;
                    }
                    else if (Trial.ToLower().Contains("is not recognized"))
                    {
                        cmdOutput.Content = "You dont have youtube-dl installed!";
                        MessageBox.Show("You dont have youtube-dl installed.\nPlease install it from their github page.", "Error");
                    }
                    else
                    {
                        //this catches any error thrown from anything in cmd and says error. lol
                        cmdOutput.Content = Trial; //sometimes it wont fit :<
                                                   //MessageBox.Show(trial);
                        outputPath.IsEnabled    = true;
                        outputPathBox.IsEnabled = true;
                    }
                }));
            }
        }