Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string vname = Unkdevt.StringHelpers.RemoveIllegalPathCharacters(TubeDlHelpers.video.Title)
                               + " " + (TubeDlHelpers.video.Resolution == 0 ? "" : TubeDlHelpers.video.Resolution.ToString() + "p") + TubeDlHelpers.Extention();

                TubeDlHelpers.customSavePath = "";
                saveFileDialog1.FileName     = vname;
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    TubeDlHelpers.Custome             = true;
                    textBox1.Text                     = Path.GetFullPath(TubeDlHelpers.customSavePath = saveFileDialog1.FileName);
                    TubeDlHelpers.customeSavefileName = Path.GetFileName(saveFileDialog1.FileName);
                    MessageBox.Show(TubeDlHelpers.customSavePath + "\n" + TubeDlHelpers.customeSavefileName);
                }
                else
                {
                    TubeDlHelpers.Custome = false;
                }
            }
            catch { }
        }
Beispiel #2
0
        public async void catchlink()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(url_))
                {
                    return;
                }
                else
                {
                    cmbQuality.Enabled = false;
                    btnCancel.Enabled  = false;
                    btnOk.Enabled      = false;
                    button1.Enabled    = false;
                    button2.Enabled    = false;
                    textBox1.Enabled   = false;
                    //    pbdown.Value = 0;
                    string link = url_;
                    pictureBox1.Image = Properties.Resources.loading;

                    /*
                     * Get the available video formats.
                     * We'll work with them in the video and audio download examples.
                     */
                    IEnumerable <VideoInfo> videoInfos = await DownloadUrlResolver.GetDownloadUrlsAsync(link);

                    /*
                     * download selected quality video or extract audio
                     */
                    if (cmbQuality.SelectedItem.ToString().Trim().Contains("Mp3"))
                    {
                        TubeDlHelpers.video = videoInfos.First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 0 && info.AudioBitrate == 128);
                    }
                    else
                    {
                        int vres;
                        switch (cmbQuality.SelectedItem.ToString().Trim())
                        {
                        case "1080p: 1920x1080 (no audio)":
                            vres = 1080;
                            break;

                        case "720p: 1280x720":
                            vres = 720;
                            break;

                        case "480p: 854x480":
                            vres = 480;
                            break;

                        case "360p: 640x360":
                            vres = 360;
                            break;

                        case "240p: 426x240":
                            vres = 240;
                            break;

                        default:
                            vres = 720;
                            break;

                            /*1080p: 1920x1080
                             * 720p: 1280x720
                             * 480p: 854x480
                             * 360p: 640x360
                             * 240p: 426x240*/
                        }
                        TubeDlHelpers.video = videoInfos
                                              .First(info => info.VideoType == VideoType.Mp4 && info.Resolution == vres);
                    }
#if DEBUG
                    //  MessageBox.Show(TubeDlMethods.video.CanExtractAudio.ToString());
#endif

                    /*
                     * If the video has a decrypted signature, decipher it
                     */
                    if (TubeDlHelpers.video.RequiresDecryption)
                    {
                        DownloadUrlResolver.DecryptDownloadUrl(TubeDlHelpers.video);
                    }

                    /*
                     * show video info
                     * */
                    lbltitle.Text = TubeDlHelpers.video.Title;
                    if (TubeDlHelpers.video.Resolution.ToString() == ("0"))
                    {
                        lblformat.Text = "Mp3";
                    }
                    else
                    {
                        lblformat.Text = "Mp4";
                    }
                    lblquality.Text = TubeDlHelpers.video.Resolution.ToString() == ("0")
                        ? "Audio" : TubeDlHelpers.video.Resolution.ToString() + "p";
                    lblsize.Text  = TubeDlHelpers.GetFileSize(new Uri(TubeDlHelpers.video.DownloadUrl));
                    lblaudio.Text = TubeDlHelpers.video.AudioType.ToString() + " " + TubeDlHelpers.video.AudioBitrate.ToString() + "kHz";
                    var imgurl = "https://img.youtube.com/vi/" +
                                 url_.Replace("http://", "").Replace("https://", "").Replace("www", "").Replace("youtube.com/watch?v=", "").Trim()
                                 + "/0.jpg";
                    pictureBox1.ImageLocation = imgurl;
                    string vname = Unkdevt.StringHelpers.RemoveIllegalPathCharacters(TubeDlHelpers.video.Title)
                                   + " " + (TubeDlHelpers.video.Resolution == 0 ? "" : TubeDlHelpers.video.Resolution.ToString() + "p") + TubeDlHelpers.Extention();

                    TubeDlHelpers.downloadurl = TubeDlHelpers.video.DownloadUrl;
                    textBox1.Text             = Path.Combine(TubeDlHelpers.SavePath, vname);
                    cmbQuality.Enabled        = true;
                    btnCancel.Enabled         = true;
                    btnOk.Enabled             = true;
                    button1.Enabled           = true;
                    button2.Enabled           = true;
                    textBox1.Enabled          = true;
                }
            }
            catch (YoutubeParseException)
            {
                //btndownload.Enabled = false;
                if (MessageBox.Show("Error while parse URL \n" + exTextBox1.Text, Text, MessageBoxButtons.RetryCancel) == DialogResult.Retry)
                {
                    catchlink();
                }
                else
                {
                    Close();
                }
            }

            catch (Exception ex)
            {
                if (ex.Message.Contains("youtube.com"))
                {
                    MessageBox.Show("Check internet connection");
                }
                else
                {
                    MessageBox.Show(ex.Message + "\ntry again with low quality");
                }
                cmbQuality.Enabled = true;
                pictureBox1.Image  = null;

                //Close();
            }
        }
Beispiel #3
0
        public void Download(string link, bool custome, string path, string filename)
        {
            try
            {
                var ext = TubeDlHelpers.Extention();


                string vname = TubeDlHelpers.Combine ? filename :

                               StringHelpers.RemoveIllegalPathCharacters(custome ? filename : TubeDlHelpers.video.Title)
                               + " " + (TubeDlHelpers.video.Resolution == 0 ? "" : TubeDlHelpers.video.Resolution.ToString() + "p") + TubeDlHelpers.Extention();

                path_ = (custome ? path : TubeDlHelpers.SavePath);
                ListViewItem item = list_Items.FindItemWithText(vname);

                if (item != null)
                {
                    MessageBox.Show(TubeDlHelpers.video.Resolution == 0 ? "Audio" : "Video" + " already in download list",
                                    Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                }
                // video exists

                else
                {
                    // doesn't exist

                    if (File.Exists(Path.Combine(custome ? path : path_, vname)))
                    {
                        var msg = new MsgBox("\'" + vname + "\' Already exist in " + path_ +
                                             "\r\nReplace file in destination ? ", Text, "Replace", "Add duplicate", DialogResult.Yes, DialogResult.No);
                        switch (msg.ShowDialog())
                        {
                        case DialogResult.Yes:
                            File.Delete(Path.Combine(path_, vname));
                            break;

                        case DialogResult.No:
                            int    count = 0;
                            string added;

                            do
                            {
                                count++;
                                added = "(" + count + ")";
                            } while (File.Exists(Path.Combine(custome ? path : path_, vname.Replace(ext, " " + added + ext))));

                            vname = vname.Replace(ext, " " + added + ext);
                            break;
                        }
                    }
                    int indx = list_Items.Items.Count;
                    list_Items.Items.Add(vname);
                    for (int i = 1; i < 7; i++)
                    {
                        list_Items.Items[indx].SubItems.Add("");
                    }
                    list_Items.Items[indx].SubItems[5].Text = DateTime.Now.ToString();
                    if (TubeDlHelpers.Combine)
                    {
                        list_Items.Items[indx].SubItems[6].Text = combineid.ToString();
                    }
                    DownloadHelper.downloadFile d = new DownloadHelper.downloadFile(link, Path.Combine(path_, vname));
                    TubeDlHelpers.ldf.Add(d);

                    Action <int, int, object> act1 = new Action <int, int, object>(delegate(int idx, int sidx, object obj)
                    {
                        list_Items.Invoke(new Action(() => list_Items.Items[idx].SubItems[sidx].Text = obj.ToString()));
                    });

                    d.eSize           += (object s1, string size) => act1.Invoke(indx, 1, size);
                    d.eDownloadedSize += (object s1, string size) => act1.Invoke(indx, 2, String.Format("{0} ({1})", size,
                                                                                                        Math.Round((TubeDlHelpers.ldf[indx].DownloadedLength / TubeDlHelpers.filesize) * 100) + "%"));
                    d.eSpeed         += (object s1, string size) => act1.Invoke(indx, 3, size);
                    d.eDownloadState += (object s1, string size) => act1.Invoke(indx, 4, size);
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
#endif
                /// btndownload.Enabled = true;
                //btnPause.Enabled = false;
            }
        }