예제 #1
0
        private async void button_mp3_Click(object sender, EventArgs e)
        {
            string link = txtBox_link.Text;

            txtBox_link.Clear();
            var          items = list_queue.Items;
            ListViewItem item  = null;

            string prefix = comboBox_pick.SelectedItem.ToString();

            if (prefix == "mp3" || prefix == "mp4")
            {
                string compoundString = comboBox_pick.SelectedItem + " " + txtBox_link.Text;

                if (link.Contains("playlist"))
                {
                    string playlistId = link.Substring(link.LastIndexOf("=") + 1);
                    await LoadPlayList(playlistId, toType(prefix));

                    button_download.Enabled = true;
                    return;
                }
                else if (link.Contains("user"))
                {
                    int    indexstart = link.IndexOf("user/") + "user/".Length;
                    string username   = link.Substring(indexstart, link.IndexOf("/", indexstart + 1) - indexstart);
                    await LoadChannel(username, toType(prefix), false);

                    button_download.Enabled = true;

                    return;
                }
                else if (link.Contains("channel"))
                {
                    int indexStart = link.IndexOf("channel") + "channel/".Length;
                    int end        = link.IndexOf("/", indexStart);
                    if (end == -1)
                    {
                        end = link.Length;
                    }
                    string channelID = link.Substring(indexStart, end - indexStart);
                    await LoadChannel(channelID, toType(prefix), true);

                    button_download.Enabled = true;
                }
                if (!isFound(compoundString, items))
                {
                    var videoRequest = _youtubeService.Videos.List("contentDetails, id, snippet");

                    string videoID = link.Substring(link.LastIndexOf("=") + 1);
                    videoRequest.Id = videoID;

                    var videoResponse = await videoRequest.ExecuteAsync();

                    foreach (var video in videoResponse.Items)
                    {
                        string[] str = new string[5];
                        str[0] = video.Snippet.ChannelTitle;
                        str[1] = video.Snippet.Title;
                        str[2] = prefix;
                        str[3] = link;
                        str[4] = cmbQualitySetting.Text;
                        if (cmbQualitySetting.Text == "")
                        {
                            str[4] = "Low";
                        }


                        item = list_queue.Items.Add(new ListViewItem(str));
                    }
                }
            }

            try
            {
                using (var client = new MyClient())
                {
                    client.HeadOnly = true;
                    string s1 = client.DownloadString(link);
                }
            }
            catch (Exception ek)
            {
                MessageBox.Show(ek.Message);
                list_queue.Items.Remove(item);
                return;
            }
            label_Items.Text        = list_queue.Items.Count.ToString();
            button_download.Enabled = true;
        }
예제 #2
0
        private async void button_mp3_Click(object sender, EventArgs e)
        {
            string link = txtBox_link.Text;
            txtBox_link.Clear();
            var items = list_queue.Items;
            ListViewItem item = null;

            string prefix = comboBox_pick.SelectedItem.ToString();

            if (prefix == "mp3" || prefix == "mp4")
            {
                string compoundString = comboBox_pick.SelectedItem + " " + txtBox_link.Text;

                if (link.Contains("playlist"))
                {
                    string playlistId = link.Substring(link.LastIndexOf("=") + 1);
                    await LoadPlayList(playlistId, toType(prefix));
                    button_download.Enabled = true;
                    return;
                }
                else if (link.Contains("user"))
                {
                    int indexstart = link.IndexOf("user/") + "user/".Length;
                    string username = link.Substring(indexstart, link.IndexOf("/", indexstart + 1) - indexstart);
                    await LoadChannel(username, toType(prefix), false);
                    button_download.Enabled = true;

                    return;
                }
                else if (link.Contains("channel"))
                {
                    int indexStart = link.IndexOf("channel") + "channel/".Length;
                    int end = link.IndexOf("/", indexStart);
                    if (end == -1)
                    {
                        end = link.Length;
                    }
                    string channelID = link.Substring(indexStart,end - indexStart);
                    await LoadChannel(channelID, toType(prefix), true);
                    button_download.Enabled = true;
                }
                if (!isFound(compoundString, items))
                {
                    var videoRequest = _youtubeService.Videos.List("contentDetails, id, snippet");

                    string videoID = link.Substring(link.LastIndexOf("=")+1);
                    videoRequest.Id = videoID;

                    var videoResponse = await videoRequest.ExecuteAsync();
                    foreach (var video in videoResponse.Items)
                    {
                        string[] str = new string[5];
                        str[0] = video.Snippet.ChannelTitle;
                        str[1] = video.Snippet.Title;
                        str[2] = prefix;
                        str[3] = link;
						str[4] = cmbQualitySetting.Text;
						if (cmbQualitySetting.Text == "")
						{
							str[4] = "Low";
						}
	                    

                        item = list_queue.Items.Add(new ListViewItem(str));
                    }
                    
                }
            }

            try
            {
                using (var client = new MyClient())
                {
                    client.HeadOnly = true;
                    string s1 = client.DownloadString(link);
                }
            }
            catch (Exception ek)
            {
                MessageBox.Show(ek.Message);
                list_queue.Items.Remove(item);
                return;
            }
            label_Items.Text = list_queue.Items.Count.ToString();
            button_download.Enabled = true;
        }