вавававава

вавававава
 avatar
unknown
csharp
a year ago
7.5 kB
3
Indexable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
using Leaf.xNet;
using OutherParam;
using proxyClass;
using StringHelper;


namespace TwitchBot
{
    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 == global::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)
        {
            global::TwitchBot.StopAll();
            global::TwitchBot.channelTwitch = channelName.ToString().ToLower();
            global::TwitchBot.time = timeout * 1000;
            int gen = global::TwitchBot.Generation;
            global::TwitchBot.postLog(global::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() => ++global::TwitchBot.Generation;

        public async void Loop1()
        {
            ++global::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\":\"" + global::TwitchBot.channelTwitch + "\",\"isVod\":false,\"vodID\":\"\",\"playerType\":\"site\"}}";
                    System.Net.Http.HttpContent httpContent = new System.Net.Http.StringContent(getApiTwitch);
                    string apiString = reqFull.Post("https://gql.twitch.tv/gql", httpContent).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/" + global::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;
                        try
                        {
                            reqFull2 = new HttpRequest();
                            reqFull2.KeepAlive = 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.EnableEncodingContent = false;
                            reqFull2.Head(videolink).ToString();
                            Thread.Sleep(global::TwitchBot.time);
                        }
                        catch
                        {
                        }
                    }
                    reqFull1 = (HttpRequest)null;
                }
                reqFull = (HttpRequest)null;
            }
            --global::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");

            }
            catch
            {
                Process.GetCurrentProcess().Kill();
            }
        }
    }
}
Leave a Comment