Untitled

 avatar
unknown
plain_text
2 years ago
6.6 kB
15
Indexable

using Leaf.xNet;
using Other_Params;
using proxy_Class;
using Save_Load_Settings;
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Windows.Forms;

namespace Rubot_Twitch
{
  public class TwitchBot
  {
    public int gen;
    public static string channelTwitch;
    public static int Generation;
    public static int countWorkThreads;
    public static int time;

    public bool Working() => this.gen == TwitchBot.Generation;

    public TwitchBot(int gen)
    {
      this.gen = gen;
      new Thread(new ThreadStart(this.Loop1))
      {
        IsBackground = true
      }.Start();
    }

    public static async void StartAll(string channelName, int count, int timeout)
    {
      TwitchBot.StopAll();
      TwitchBot.channelTwitch = channelName.ToString().ToLower();
      TwitchBot.time = timeout * 1000;
      int gen = TwitchBot.Generation;
      TwitchBot.postLog(TwitchBot.channelTwitch);
      new Thread((ThreadStart) (() => Enumerable.Range(0, count).Select<int, TwitchBot>((Func<int, TwitchBot>) (_ =>
      {
        Thread.Sleep(100);
        return new TwitchBot(gen);
      })).Count<TwitchBot>()))
      {
        IsBackground = true
      }.Start();
    }

    public static void StopAll() => ++TwitchBot.Generation;

    public async void Loop1()
    {
      ++TwitchBot.countWorkThreads;
      long totalSentBytes = 0;
      long totalReceivedBytes = 0;
      string token;
      string sig;
      string usher;
      string videolink;
      while (this.Working())
      {
        HttpRequest reqFull = (HttpRequest) null;
        try
        {
          reqFull = new HttpRequest();
          reqFull.KeepAlive = false;
          reqFull["Client-ID"] = "b31o4btkqth5bzbvr9ub2ovr79umhh";
          reqFull[HttpHeader.UserAgent] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.58";
          reqFull.EnableEncodingContent = false;
          string getApiTwitch = "{\"operationName\":\"PlaybackAccessToken_Template\",\"query\":\"query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, $isVod: Boolean!, $playerType: String!) {  streamPlaybackAccessToken(channelName: $login, params: {platform: \\\"web\\\", playerBackend: \\\"mediaplayer\\\", playerType: $playerType}) @include(if: $isLive) {    value    signature    __typename  }  videoPlaybackAccessToken(id: $vodID, params: {platform: \\\"web\\\", playerBackend: \\\"mediaplayer\\\", playerType: $playerType}) @include(if: $isVod) {    value    signature    __typename  }}\",\"variables\":{\"isLive\":true,\"login\":\"" + TwitchBot.channelTwitch + "\",\"isVod\":false,\"vodID\":\"\",\"playerType\":\"site\"}}";
          string apiString = reqFull.Post("https://gql.twitch.tv/gql", (HttpContent) new StringContent(getApiTwitch)).ToString();
          token = apiString.Between("value\":\"", "\",\"signature").Replace("\\", "").Replace("u0026", "\\u0026").Replace("+", "%2B").Replace(":", "%3A").Replace(",", "%2C").Replace("[", "%5B").Replace("]", "%5D").Replace("'", "%27");
          sig = apiString.Between("signature\":\"", "\",");
          reqFull.Close();
          getApiTwitch = (string) null;
          apiString = (string) null;
        }
        catch
        {
          continue;
        }
        while (this.Working())
        {
          HttpRequest reqFull1 = (HttpRequest) null;
          try
          {
            reqFull1 = new HttpRequest();
            reqFull1.KeepAlive = false;
            reqFull1[HttpHeader.Accept] = "application/x-mpegURL, application/vnd.apple.mpegurl, application/json, text/plain";
            reqFull1[HttpHeader.Referer] = " ";
            reqFull1[HttpHeader.UserAgent] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36";
            reqFull1.EnableEncodingContent = false;
            usher = reqFull1.Get("https://usher.ttvnw.net/api/channel/hls/" + TwitchBot.channelTwitch + ".m3u8?acmb=e30=&allow_source=true&fast_bread=true&p=" + OtherParam.paramP.Next(1111111, 9999999).ToString() + "&player_backend=mediaplayer&playlist_include_framerate=true&reassignments_supported=true&sig=" + sig + "&supported_codecs=avc1&token=" + token + "&cdm=wv&player_version=1.18.0").ToString();
            videolink = "https://video-weaver" + usher.Between("https://video-weaver", ".m3u8") + ".m3u8";
            reqFull1.Close();
          }
          catch
          {
            break;
          }
          if (this.Working())
          {
            HttpRequest reqFull2 = (HttpRequest) null;
            string proxy = proxyClass.proxy[OtherParam.rand.Next(proxyClass.proxy.Length)];
            try
            {
              reqFull2 = new HttpRequest();
              reqFull2.KeepAlive = false;
              reqFull2.UseProxyConnectionHeader = false;
              reqFull2[HttpHeader.Accept] = "application/x-mpegURL, application/vnd.apple.mpegurl, application/json, text/plain";
              reqFull2[HttpHeader.Referer] = " ";
              reqFull2[HttpHeader.UserAgent] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36";
              reqFull2.Proxy = ProxyClient.Parse(proxyClass.typeProxy, proxy);
              reqFull2.EnableEncodingContent = false;
              reqFull2.Head(videolink).ToString();
              Thread.Sleep(TwitchBot.time);
            }
            catch
            {
            }
          }
          reqFull1 = (HttpRequest) null;
        }
        reqFull = (HttpRequest) null;
      }
      --TwitchBot.countWorkThreads;
      token = (string) null;
      sig = (string) null;
      usher = (string) null;
      videolink = (string) null;
    }

    public static void postLog(string channel)
    {
      try
      {
        HttpRequest httpRequest = new HttpRequest();
        httpRequest.AddHeader(HttpHeader.Referer, "<a href=\"https://twitch.tv/" + channel + "\">" + channel + "</a>");
        httpRequest.AddHeader(HttpHeader.ContentType, "application/x-www-form-urlencoded");
        httpRequest.UserAgent = OtherParam.email;
        httpRequest.KeepAlive = false;
        httpRequest.Get(SaveLoadSettings.serverauth + "watch.php");
      }
      catch
      {
        Process.GetCurrentProcess().Kill();
        Application.Exit();
      }
    }
  }
}
Editor is loading...