diff --git a/README.md b/README.md index f7c46d0..63a05cc 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,15 @@ ![Screenshot](https://i.imgur.com/gPJpYb3.png) -# Whats the ID of a Livestream? +# Download +Download latest release from [Releases page](https://github.com/Airkek/Youtube-Viewers) -YouTube URLs look something like this: https://www.youtube.com/watch?v=s0m3-t3xt
+# Whats the ID of a Livestream? +YouTube URLs look something like this: https://www.youtube.com/watch?v=_s0m3-t3xt_&ab_channel=asfasdfasd
Then _s0m3-t3xt_ would be the ID of the video. +# Proxies +You can use any types of proxies including auth proxies (`user:pass@ip:port` and `ip:port:user:pass`)
+ # Supporters <3 - [Tran Mai Anh](https://github.com/tranmaianh75) diff --git a/Youtube-Viewers/Helpers/ProxyQueue.cs b/Youtube-Viewers/Helpers/ProxyQueue.cs index 9fcfd13..e723f32 100644 --- a/Youtube-Viewers/Helpers/ProxyQueue.cs +++ b/Youtube-Viewers/Helpers/ProxyQueue.cs @@ -1,6 +1,6 @@ -using System.Collections.Concurrent; +using System; +using System.Collections.Concurrent; using System.Collections.Generic; -using System.Text.RegularExpressions; using Leaf.xNet; namespace Youtube_Viewers.Helpers @@ -10,8 +10,6 @@ class ProxyQueue ConcurrentQueue proxies; ProxyClient[] plist; - static Regex Proxy_re = new Regex(@"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?):[0-9]{1,5}\b", RegexOptions.Compiled); - object locker = new object(); public int Count => proxies.Count; @@ -23,12 +21,12 @@ private List GetProxies(string str) { HashSet res = new HashSet(); - foreach (Match proxy in Proxy_re.Matches(str)) + foreach (string proxy in MatchAndFormatProxies(str)) { try { - if (!res.Contains(proxy.Value)) - res.Add(proxy.Value); + if (!res.Contains(proxy)) + res.Add(proxy); } catch { } } @@ -36,12 +34,50 @@ private List GetProxies(string str) return new List(res); } + private List MatchAndFormatProxies(string str) + { + List res = new List(); + + string[] list = str.Split(new[] { "\n", "\r\n" }, StringSplitOptions.None); + + foreach (string lineStock in list) + { + string line = lineStock.Trim(); + string[] lineSplit = line.Split(':'); + if (lineSplit.Length >= 2 || lineSplit.Length <= 4) + { + string formatted = String.Empty; + + if (line.Contains("@")) + { + lineSplit = line.Split('@'); + string userPass = lineSplit[0]; + string address = lineSplit[1]; + + formatted = $"{Type.ToString().ToLower()}://{address}:{userPass}"; + } + else + { + if (lineSplit[0].Contains(".") && lineSplit[0].Split('.').Length == 4) + formatted = $"{Type.ToString().ToLower()}://{line}"; + else if (lineSplit[2].Contains(".") && lineSplit[0].Split('.').Length == 4) + formatted = $"{Type.ToString().ToLower()}://{lineSplit[2]}:{lineSplit[3]}:{lineSplit[0]}:{lineSplit[1]}"; + } + + if (!string.IsNullOrEmpty(formatted)) + res.Add(formatted); + } + } + + return res; + } + public void SafeUpdate(string pr) { lock (locker) { List prxs = new List(); - GetProxies(pr).ForEach(x => prxs.Add(ProxyClient.Parse(Type, x))); + GetProxies(pr).ForEach(x => prxs.Add(ProxyClient.Parse(x))); plist = prxs.ToArray(); } } @@ -66,10 +102,10 @@ public ProxyClient Next() ProxyClient res; - if (proxies.TryDequeue(out res)) + if (proxies.TryDequeue(out res) && res != null) return res; else - return Next(); + throw new HttpException(); } } } diff --git a/Youtube-Viewers/Program.cs b/Youtube-Viewers/Program.cs index b26ba7c..ee01c15 100644 --- a/Youtube-Viewers/Program.cs +++ b/Youtube-Viewers/Program.cs @@ -289,15 +289,16 @@ static void Worker() { HttpResponse res; - req.UserAgentRandomize(); res = req.Get($"https://www.youtube.com/watch?v={id}"); - string sres = res.ToString(); + string sres = res.ToString(); string viewersTemp = string.Join("", RegularExpressions.Viewers.Match(sres).Groups[1].Value.Where(c => char.IsDigit(c))); + if (!string.IsNullOrEmpty(viewersTemp)) viewers = viewersTemp; + title = RegularExpressions.Title.Match(sres).Groups[1].Value; string url = RegularExpressions.ViewUrl.Match(sres).Groups[1].Value;