Esempio n. 1
0
        private async void DownloadBtn_Click(object sender, EventArgs e)
        {
            var fbd    = new FolderBrowserDialog();
            var result = fbd.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }
            _path         = fbd.SelectedPath;
            UseWaitCursor = true;
            _infoFrm      = new InfoFrm();
            _infoFrm.Show();
            _infoFrm.BringToFront();
            DownloadBtn.Enabled = false;
            WatchNowBtn.Enabled = false;
            var token = new CancellationToken();

            try
            {
                await Task.Run(() => DownloadAnime(token));
            }
            catch (OperationCanceledException)
            {
                //Messagebox disposed, stop doing this.
            }
            DownloadBtn.Enabled = true;
            WatchNowBtn.Enabled = true;
            UseWaitCursor       = false;
        }
        private async Task <Dictionary <string, string> > GetDownloadUrls(Dictionary <string, string> Values, string FetchMode = "")
        {
            if (_InfoFrm == null || _InfoFrm.IsDisposed)
            {
                this.Invoke((MethodInvoker)(() => _InfoFrm = new InfoFrm()));                                          //generate on main UI thread
            }
            var Dictionary = new Dictionary <string, string>();

            StaticsClass.InvokeIfRequired(this, () =>
            {
                _InfoFrm.Show();
                _InfoFrm.BringToFront();
            });
            foreach (var keyValPair in Values)
            {
                var episodeName = GetSafeFilename(keyValPair.Key);
                try
                {
                    StaticsClass.InvokeIfRequired(this, () =>
                    {
                        _InfoFrm.textBox1.Text = $"{FetchMode}: " + episodeName;
                        _InfoFrm.textBox1.Refresh();
                    });
                }
                catch (ObjectDisposedException)
                {
                    StaticsClass.InvokeIfRequired(this, () => { _InfoFrm.Dispose(); _InfoFrm = null; });
                    return(Dictionary);
                }
                var episodeUrl    = keyValPair.Value;
                var directoryPath = _path + @"\" + GetSafeFilename(AnimeName.Text);
                Directory.CreateDirectory(directoryPath);

                string redirectorLink;
                if (VariablesClass.MasterURL == VariablesClass.KissLewdURL)
                {
                    var animeurlname = _phantomObject.Url.Substring(_phantomObject.Url.LastIndexOf("/", StringComparison.Ordinal) + 1);
                    redirectorLink = WebDriverClass.RunViaDesktop(AnimeUrl, animeurlname, episodeName, episodeUrl);
                }
                else
                {
                    redirectorLink = (await GetGoogleLink(episodeUrl)).Replace("&amp;", "&");
                }
                if (redirectorLink != "no")
                {
                    if (WebDriverClass.FileDoesNotExist(redirectorLink))
                    {
                        var animeurlname = _phantomObject.Url.Substring(_phantomObject.Url.LastIndexOf("/", StringComparison.Ordinal) + 1);
                        redirectorLink = WebDriverClass.RunViaDesktop(AnimeUrl, animeurlname, episodeName, episodeUrl);
                    }
                    Dictionary.Add(AnimeName.Text + " - " + episodeName, redirectorLink);
                }
            }
            StaticsClass.InvokeIfRequired(this, () => { _InfoFrm.Dispose(); _InfoFrm = null; });
            return(Dictionary);
        }