예제 #1
0
        public void CheckAsync(List <Proxy> proxies)
        {
            if (CancellationTokenSource.IsCancellationRequested)
            {
                return;
            }

            ProxyQueue.AddRange(proxies);
            StartCheckProxiesTaskIfRequired();
        }
예제 #2
0
        private async void StartCheckProxiesTaskIfRequired()
        {
            if (ProxyQueue.Count == 0 || CheckProxiesTask != null)
            {
                return;
            }

            if (InitializationTask == null)
            {
                SetInitializationTaskIfRequired();
            }

            try
            {
                CheckProxiesTask = Task.Run(() =>
                {
                    while (CheckingProxyIfItWorksTasksCount < MaxTasksCount)
                    {
                        if (CancellationTokenSource.IsCancellationRequested)
                        {
                            break;
                        }

                        Proxy proxy = ProxyQueue.FirstOrDefault();

                        if (proxy == null)
                        {
                            break;
                        }

                        ProxyQueue.RemoveAt(0);
                        CheckProxyAsync(proxy);
                    }
                });

                await CheckProxiesTask;
            }
            finally
            {
                CheckProxiesTask = null;
                DisposeInitializationTaskIfRequired();
            }
        }
예제 #3
0
        private static void Main()
        {
            if (!File.Exists("proxy_url.txt"))
            {
                File.AppendAllText("proxy_url.txt", string.Join("\r\n", Urls));
            }

            Console.Title = $"YTViewer | {GitRepo}";
            Logo(ConsoleColor.Cyan);

            _id           = Dialog("Enter Video ID");
            _threadsCount = Convert.ToInt32(Dialog("Enter Threads Count (Comfort 2000)"));

            while (true)
            {
                Logo(ConsoleColor.Cyan);

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Select proxy type: \n1. Http`s \n2. Socks \n3. Socks5");

                Console.Write("Your choice: ");
                Console.ForegroundColor = ConsoleColor.Cyan;

                var k = Console.ReadKey().KeyChar;

                try
                {
                    var key = int.Parse(k.ToString());
                    switch (key)
                    {
                    case 1:
                        _proxyType = ProxyType.HTTP;
                        break;

                    case 2:
                        _proxyType = ProxyType.Socks4;
                        break;

                    case 3:
                        _proxyType = ProxyType.Socks5;
                        break;

                    default:
                        throw new Exception();
                    }
                }
                catch
                {
                    continue;
                }

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine($"\r\nSelected {_proxyType} proxy");

                break;
            }

            while (true)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Update proxies by urls?:\r\n1. Yes\r\n2. No");

                Console.Write("Your choice: ");

                var k = Console.ReadKey().KeyChar;

                try
                {
                    var pt = int.Parse(k.ToString());
                    switch (pt)
                    {
                    case 1:
                        _updateProxy = true;
                        break;

                    case 2:
                        break;

                    default:
                        throw new Exception();
                    }
                }
                catch
                {
                    continue;
                }

                break;
            }

reProxy:
            if (_updateProxy)
            {
                Urls = File.ReadAllText("proxy_url.txt").Trim().Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
                Console.WriteLine("\nProxy links: \n" + string.Join("\r\n", Urls));
                Console.WriteLine("You can set your own links in 'proxy_url.txt' file");

                var totalProxies = string.Empty;

                using (var req = new HttpRequest
                {
                    ConnectTimeout = 3000
                })
                {
                    foreach (var proxyUrl in Urls)
                    {
                        Console.ResetColor();
                        Console.Write($"Downloading proxies from '{proxyUrl}': ");
                        {
                            try
                            {
                                totalProxies           += req.Get(proxyUrl) + "\r\n";
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine("Success");
                                Console.ResetColor();
                            }
                            catch (Exception e)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine($"Error: \n {e.Message}");
                                Console.ResetColor();
                            }
                        }
                    }
                }

                if (totalProxies.Length == 0)
                {
                    MessageBox.Show("Couldn't update proxies by url. You will have to do manually");
                    _updateProxy = false;
                    goto reProxy;
                }

                _scraper = new ProxyQueue(totalProxies, _proxyType);
            }
            else
            {
                Console.WriteLine("Select proxy list");

                var dialog = new OpenFileDialog {
                    Filter = "Proxy list (*.txt)|*.txt"
                };

                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                _scraper = new ProxyQueue(File.ReadAllText(dialog.FileName), _proxyType);
            }

            Console.WriteLine($"\nLoaded {_scraper.Length} proxies");

            Logo(ConsoleColor.Green);

            var threads = new List <Thread>();

            var logWorker = new Thread(Log);

            logWorker.Start();
            threads.Add(logWorker);

            if (_updateProxy)
            {
                var proxyWorker = new Thread(ProxyUpdater);
                proxyWorker.Start();
                threads.Add(proxyWorker);
            }

            for (var i = 0; i < _threadsCount; i++)
            {
                var t = new Thread(Worker);
                t.Start();
                threads.Add(t);
            }

            foreach (var t in threads)
            {
                t.Join();
            }

            Console.ReadKey();
        }
예제 #4
0
        static void Main(string[] args)
        {
            if (!File.Exists("proxy_url.txt"))
            {
                File.AppendAllText("proxy_url.txt", string.Join("\r\n", Urls));
            }

            Console.Title = $"YTBot | {gitRepo}";
            Logo(ConsoleColor.Cyan);

            id           = dialog("Enter Video ID");
            threadsCount = Convert.ToInt32(dialog("Enter Threads Count"));

            while (true)
            {
                Logo(ConsoleColor.Cyan);

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Select proxy type:\r\n1. Http/s\r\n2. Socks4\r\n3. Socks5");

                Console.Write("Your choice: ");
                Console.ForegroundColor = ConsoleColor.Cyan;

                char k = Console.ReadKey().KeyChar;

                try
                {
                    int key = int.Parse(k.ToString());
                    switch (key)
                    {
                    case 1:
                        proxyType = ProxyType.HTTP;
                        break;

                    case 2:
                        proxyType = ProxyType.Socks4;
                        break;

                    case 3:
                        proxyType = ProxyType.Socks5;
                        break;

                    default:
                        throw new Exception();
                    }
                }
                catch
                {
                    continue;
                }

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine($"\r\nSelected {proxyType} proxy");

                break;
            }

            while (true)
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Update proxies by urls?:\r\n1. Yes\r\n2. No");

                Console.Write("Your choice: ");

                char k = Console.ReadKey().KeyChar;

                try
                {
                    int pt = int.Parse(k.ToString());
                    switch (pt)
                    {
                    case 1:
                        updateProxy = true;
                        break;

                    case 2:
                        break;

                    default:
                        throw new Exception();
                    }
                }
                catch
                {
                    continue;
                }
                break;
            }

            if (updateProxy)
            {
                Urls = File.ReadAllText("proxy_url.txt").Trim().Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);
                Console.WriteLine("Proxy links: \r\n" + string.Join("\r\n", Urls));
                Console.WriteLine("You can set your own links in 'proxy_url.txt' file");

                string totalProxies = String.Empty;

                foreach (string proxyUrl in Urls)
                {
                    Console.WriteLine($"Downloading proxies from '{proxyUrl}'");
                    using (HttpRequest req = new HttpRequest())
                    {
                        totalProxies += req.Get(proxyUrl).ToString() + "\r\n";
                    }
                }

                scraper = new ProxyQueue(totalProxies, proxyType);
            }
            else
            {
                Console.WriteLine("Select proxy list");

                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Filter = "Proxy list (*.txt)|*.txt";

                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                scraper = new ProxyQueue(File.ReadAllText(dialog.FileName), proxyType);
            }

            Console.WriteLine($"Loaded {scraper.Length} proxies");

            Logo(ConsoleColor.Green);

            List <Thread> threads = new List <Thread>();

            Thread logWorker = new Thread(Log);

            logWorker.Start();
            threads.Add(logWorker);

            if (updateProxy)
            {
                Thread proxyWorker = new Thread(proxyUpdater);
                proxyWorker.Start();
                threads.Add(proxyWorker);
            }

            for (int i = 0; i < threadsCount; i++)
            {
                Thread t = new Thread(Worker);
                t.Start();
                threads.Add(t);
            }

            foreach (Thread t in threads)
            {
                t.Join();
            }

            Console.ReadKey();
        }