Beispiel #1
0
        /// <summary>
        /// Converts YouTube video to mp3 and returns the mp3 download link as string.
        /// </summary>
        /// <param name="youtubeLink">YouTube video link to be converted</param>
        /// <returns></returns>

        public string ConvertYTVideoToMp3(string youtubeLink)
        {
            cancel = false;
            if (!YTMp3OrgConverter.IsYoutubeUrl(youtubeLink))
            {
                return(null);
            }
            string id      = Regex.Split(youtubeLink, @"watch\?v=")[1];
            string address = string.Format(rawAddress, id);

            browser = new WebBrowser();
            browser.Navigate(address);
            stp.Start();
            while (browser.Document == null ||
                   browser.Document.GetElementById("download") == null ||
                   !browser.Document.GetElementById("download").GetAttribute("href").Contains("downloader"))
            {
                if (cancel)
                {
                    return(null);
                }
                if (stp.Elapsed.TotalSeconds > 4)
                {
                    return(null);
                }
                Application.DoEvents();
            }
            stp.Reset();
            string linkt = browser.Document.GetElementById("download").GetAttribute("href");

            return(linkt);
        }
Beispiel #2
0
        void listViewVideo_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            timer.Stop();
            lblCurrentAudio.Text = "";
            ListViewItem item = listViewVideo.SelectedItems[0];

            lastSelectedIndex = item.Index;
            string downloadLink = getDownloadLink(item);

            if (string.IsNullOrEmpty(downloadLink))
            {
                mp3Orgconverter = new YTMp3OrgConverter();
                return;
            }
            mediaPlayer.URL       = downloadLink;
            currentAudioFileName  = selectedTitle;
            lblTotalDuration.Text = "Buffering...";
            timer.Start();
        }
Beispiel #3
0
        void btnAddQueue_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listViewVideo.SelectedItems)
            {
                string downloadLink = getDownloadLink(item);

                if (string.IsNullOrEmpty(downloadLink))
                {
                    mp3Orgconverter = new YTMp3OrgConverter();
                    return;
                }
                listViewDwlds.Items.Add(selectedTitle).SubItems.Add("");
                foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                {
                    selectedTitle = selectedTitle.Replace(c.ToString(), "_");
                }
                string path = Path.Combine(targetDirectory, selectedTitle + ".mp3");

                listViewDwlds.Items[listViewDwlds.Items.Count - 1].SubItems.Add(path);
                listViewDwlds.Items[listViewDwlds.Items.Count - 1].SubItems.Add("");
                dldQueue.Add(downloadLink, path);
            }
        }
Beispiel #4
0
 public MainForm()
 {
     InitializeComponent();
     this.Load                               += MainForm_Load;
     mp3Orgconverter                          = new YTMp3OrgConverter();
     mp3ccConverter                           = new YT2Mp3Converter();
     dldQueue                                 = new DownloadQueue();
     dldQueue.QueueCompleted                 += dldQueue_QueueCompleted;
     dldQueue.QueueProgressChanged           += dldQueue_QueueProgressChanged;
     dldQueue.QueueElementCompleted          += dldQueue_QueueElementCompleted;
     dldQueue.QueueElementStartedDownloading += dldQueue_QueueElementStartedDownloading;
     listViewDwlds.MouseDown                 += listViewDwlds_MouseDown;
     listViewVideo.MouseDoubleClick          += listViewVideo_MouseDoubleClick;
     btnStartQueue.Click                     += btnStartQueue_Click;
     btnAddQueue.Click                       += btnAddQueue_Click;
     btnNewQueue.Click                       += btnNewQueue_Click;
     btnPauseQueue.Click                     += btnPauseQueue_Click;
     btnPath.Click                           += btnPath_Click;
     btnSearch.Click                         += btnSearch_Click;
     searchTxtBox.MouseDoubleClick           += searchTxtBox_MouseDoubleClick;
     timer.Tick                              += timer_Tick;
     mediaPlayer.PlayStateChange             += mediaPlayer_PlayStateChange;
     this.AcceptButton                        = btnSearch;
 }
Beispiel #5
0
        /// <summary>
        /// Converts youtube video to mp3 and returns download link as string
        /// </summary>
        /// <param name="youtubeLink">YouTube video link to be converted</param>
        /// <returns></returns>
        public string ConvertYTVideoToMp3(string youtubeLink)
        {
            if (!YTMp3OrgConverter.IsYoutubeUrl(youtubeLink))
            {
                throw new Exception("Url düzgün bir YouTube video adresi değil");
            }
            stpWathcher.Start();
            if (!docCompleted)
            {
                webBrowser.Navigate(siteUrl);
                while (!docCompleted)
                {
                    Application.DoEvents();
                    if (stpWathcher.Elapsed.TotalSeconds > 4)
                    {
                        stpWathcher.Reset();
                        return("");
                    }
                }
            }
            stpWathcher.Reset();
            string videoId = Regex.Split(youtubeLink, @"watch\?v=")[1];

            if (webBrowser.Document.GetElementById("youtube-url") == null)
            {
                webBrowser.Navigate(siteUrl);
                while (!docCompleted)
                {
                    Application.DoEvents();
                    if (stpWathcher.Elapsed.TotalSeconds > 4)
                    {
                        stpWathcher.Reset();
                        return("");
                    }
                }
            }
            webBrowser.Document.GetElementById("youtube-url").SetAttribute("value", youtubeLink);
            webBrowser.Document.GetElementById("submit").InvokeMember("click");
            stpWathcher.Start();
            while (webBrowser.Document.GetElementById("dl_link") == null ||
                   webBrowser.Document.GetElementById("dl_link").GetElementsByTagName("a").Count == 0 ||
                   !webBrowser.Document.GetElementById("dl_link").GetElementsByTagName("a")[0].GetAttribute("href").Contains(videoId))
            {
                if (!string.IsNullOrEmpty(webBrowser.Document.GetElementById("error_text").InnerText))
                {
                    return("");
                }

                Application.DoEvents();
            }
            stpWathcher.Reset();
            HtmlElementCollection elCol = webBrowser.Document.GetElementById("dl_link").GetElementsByTagName("a");

            string downloadLink = "";

            foreach (HtmlElement item in elCol)
            {
                if (item.GetAttribute("href").Contains("create"))
                {
                    downloadLink = item.GetAttribute("href");
                }
            }
            return(downloadLink);
        }