Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #64 from Airkek/auth-proxies
Browse files Browse the repository at this point in the history
Implement Auth Proxies support
  • Loading branch information
Airkek authored Dec 23, 2020
2 parents 768a330 + 97d3522 commit 6d05e90
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 14 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br />
# Whats the ID of a Livestream?
YouTube URLs look something like this: https://www.youtube.com/watch?v=_s0m3-t3xt_&ab_channel=asfasdfasd <br />
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`) <br />

# Supporters <3
- [Tran Mai Anh](https://github.com/tranmaianh75)
56 changes: 46 additions & 10 deletions Youtube-Viewers/Helpers/ProxyQueue.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,8 +10,6 @@ class ProxyQueue
ConcurrentQueue<ProxyClient> 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;
Expand All @@ -23,25 +21,63 @@ private List<string> GetProxies(string str)
{
HashSet<string> res = new HashSet<string>();

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 { }
}

return new List<string>(res);
}

private List<string> MatchAndFormatProxies(string str)
{
List<string> res = new List<string>();

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<ProxyClient> prxs = new List<ProxyClient>();
GetProxies(pr).ForEach(x => prxs.Add(ProxyClient.Parse(Type, x)));
GetProxies(pr).ForEach(x => prxs.Add(ProxyClient.Parse(x)));
plist = prxs.ToArray();
}
}
Expand All @@ -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();
}
}
}
5 changes: 3 additions & 2 deletions Youtube-Viewers/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6d05e90

Please sign in to comment.