Exemplo n.º 1
0
        private DownloadItemSettings GetCurrentSetting()
        {
            var downloadItemSettings = new DownloadItemSettings
            {
                Url              = YoutubeUrlTextBox.Text,
                SaveToPath       = SaveToTextBox.Text,
                OverrideExisting = OverrideExistingFileCheckBox.Checked,
                MaxResolution    = ((KeyValuePair <string, int>)MaxQualityComboBox.SelectedItem).Value
            };

            return(downloadItemSettings);
        }
Exemplo n.º 2
0
        private void DownloadFromQueueButton_Click(object sender, EventArgs e)
        {
            LogTextBox.Text = "";
            foreach (ListViewItem item in UrlsListView.Items)
            {
                var settings = new DownloadItemSettings
                {
                    Url        = item.SubItems[0].Text,
                    SaveToPath = item.SubItems[1].Text
                };
                item.SubItems[2].Text     = "Downloading";
                settings.MaxResolution    = int.Parse(item.SubItems[3].Text);
                settings.OverrideExisting = bool.Parse(item.SubItems[4].Text);

                DownloadItem(settings, error =>
                {
                    item.SubItems[5].Text += error;
                });

                item.SubItems[2].Text = "Downloaded";
            }

            foreach (ListViewItem item in UrlsListView.Items)
            {
                var errors = item.SubItems[5].Text;
                if (!string.IsNullOrWhiteSpace(errors))
                {
                    item.SubItems[5].Text = "Yes";
                    LogTextBox.Text      += errors;
                }
                else
                {
                    item.SubItems[5].Text = "No";
                }
            }
        }
Exemplo n.º 3
0
        private void DownloadItem(DownloadItemSettings settings, Action <string> writeLogOnError)
        {
            LogTextBox.Text = string.Empty;
            var urls = new List <string>();

            if (settings.Url.ChannelMode())
            {
                urls = settings.Url.GetChannelItemsUrls();
            }
            else if (settings.Url.ListMode())
            {
                urls = settings.Url.GetPlaylistItemsUrls();
            }
            else
            {
                urls.Add(settings.Url);
            }

            var maxResolution = ((KeyValuePair <string, int>)MaxQualityComboBox.SelectedItem).Value;

            DowloadTotalProgressBar.Maximum = urls.Count;
            DowloadTotalProgressBar.Value   = 0;
            var index = 0;

            foreach (var url in urls)
            {
                ++index;
                var count      = index + " of " + urls.Count;
                var videoInfos = new List <VideoInfo>();
                try
                {
                    videoInfos = DownloadUrlResolver.GetDownloadUrls(url, false)
                                 .Where(i => i.VideoType == VideoType.Mp4 && i.AudioType != AudioType.Unknown)
                                 .OrderByDescending(i => i.Resolution).ToList();
                    var videoInfo = videoInfos.FirstOrDefault(i => i.Resolution <= maxResolution);
                    if (videoInfo != null)
                    {
                        DowloadTotalProgressBar.Value = index;
                        DowloadTotalProgressBar.DrawText(count + " Downloading.");

                        DowloadCurrentProgressBar.Value = 0;

                        //var task = WebClient_DownloadVideo(videoInfo);
                        //task.Wait();

                        DownloadVideo(videoInfo, progress =>
                        {
                            DowloadCurrentProgressBar.Value = progress;
                            DowloadCurrentProgressBar.DrawText(videoInfo.Title);
                        });

                        DowloadCurrentProgressBar.Value = 100;
                    }
                }
                catch (Exception ex)
                {
                    var error = count + " - " + url;
                    if (videoInfos.Any())
                    {
                        error += " - " + videoInfos.First().Title;
                    }
                    error += Environment.NewLine;

                    error += ex.Message + Environment.NewLine;
                    if (ex.Message.Contains("403"))
                    {
                        error += "Looks this video contains content which is restricted from playback on certain sites or applications.Try to use https://www.clipconverter.cc/" + Environment.NewLine;
                    }
                    //if (videoInfos.Any())
                    //{
                    //	foreach (var video in videoInfos)
                    //	{
                    //		if (video.RequiresDecryption)
                    //		{
                    //			DownloadUrlResolver.DecryptDownloadUrl(video);
                    //		}
                    //	}
                    //	error += "Possible download urls: " + Environment.NewLine +
                    //	         string.Join(Environment.NewLine, videoInfos.Select(v => v.DownloadUrl + v.VideoExtension)) + Environment.NewLine;
                    //}
                    writeLogOnError?.Invoke(error);
                }
            }
            DowloadTotalProgressBar.Value = DowloadTotalProgressBar.Maximum;
            DowloadTotalProgressBar.DrawText("Download compleated!");
            DowloadTotalProgressBar.Refresh();
        }