Nem4 / viewerbot

Twitch Viewer Bot (Python + proxies)
305 stars 135 forks source link

Valid main code #63

Open NjProVk opened 2 years ago

NjProVk commented 2 years ago
"""
   Update from NjProVk
"""

import requests
from streamlink import Streamlink
import sys
import time
import random
from random import shuffle
from fake_useragent import UserAgent
import linecache

from threading import Thread

channel_urls = f"https://www.twitch.tv/{sys.argv[1]}"
proxies_file = "Proxies_txt/good_proxy.txt"
processes = []
max_nb_of_threads = int(sys.argv[2])

all_proxies = []
nb_of_proxies = 0

# Session creating for request
ua = UserAgent()
session = Streamlink()
session.set_option("http-headers", {'User-Agent': ua.random, "Client-ID": "ewvlchtxgqq88ru9gmfp1gmyt6h2b93"})

class ViewerBot:
    def print_exception(self):
        exc_type, exc_obj, tb = sys.exc_info()
        f = tb.tb_frame
        lineno = tb.tb_lineno
        filename = f.f_code.co_filename
        linecache.checkcache(filename)
        line = linecache.getline(filename, lineno, f.f_globals)
        print('EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj))

    def get_proxies(self):
        # Reading the list of proxies
        global nb_of_proxies
        try:
            lines = [line.rstrip("\n") for line in open(proxies_file)]
        except IOError as e:
            print("An error has occurred while trying to read the list of proxies: %s" % e.strerror)
            sys.exit(1)

        nb_of_proxies = len(lines)
        return lines

    def get_url(self):
        url = ""
        try:
            streams = session.streams(self.channel_url)
            try:
                url = streams['audio_only'].url
                print(f"URL : {url[:30]}...\n")
            except:
                url = streams['worst'].url
                print(f"URL : {url[:30]}...\n")

        except:
            pass
        return url

    def open_url(self,proxy_data):
        try:
            global all_proxies
            headers = {'User-Agent': ua.random}
            current_index = all_proxies.index(proxy_data)

            if proxy_data['url'] == "":
                proxy_data['url'] = self.get_url()
            current_url = proxy_data['url']
            try:
                if time.time() - proxy_data['time'] >= random.randint(1, 5):
                    current_proxy = {"http": f"https://{proxy_data['proxy']}", "https": f"http://{proxy_data['proxy']}"}
                    with requests.Session() as s:
                        response = s.head(current_url, proxies=current_proxy, headers=headers)
                    print(f"Sent HEAD request with {current_proxy['http']} | {response.status_code} | {response.request} | {response}")
                    proxy_data['time'] = time.time()
                    all_proxies[current_index] = proxy_data
            except:
                print("Connection Error!")

        except (KeyboardInterrupt, SystemExit):
            sys.exit()

    def mainmain(self):
        self.channel_url = channel_urls
        proxies = self.get_proxies()

        for p in proxies:
            all_proxies.append({'proxy': p, 'time': time.time(), 'url': ""})

        shuffle(all_proxies)
        list_of_all_proxies = all_proxies
        current_proxy_index = 0

        while True:
            try:
                for i in range(0, max_nb_of_threads):
                    threaded = Thread(target=self.open_url, args=(all_proxies[random.randint(0, len(all_proxies))],))
                    threaded.daemon = True  # This thread dies when main thread (only non-daemon thread) exits.
                    threaded.start()
            except:
                self.print_exception()
            shuffle(all_proxies)
            time.sleep(5)

ViewerBot = ViewerBot()
ViewerBot.mainmain()

image

NjProVk commented 2 years ago

It cod worked on 100%

Example: python3 threads_viewer.py CHANELNAME COUNT

zerodoxxx commented 2 years ago

Not able to install requirements fully, getting some error related to streamlink. Can you share a step-by-step guide on how to use it. Thanks in advance! getting this error image

NjProVk commented 2 years ago

Not able to install requirements fully, getting some error related to streamlink. Can you share a step-by-step guide on how to use it. Thanks in advance! getting this error image

fake-useragent==0.1.11 requests>=2.21.0 streamlink==1.0.0

Use command in console: pip install fake-useragent==0.1.11 pip install requests>=2.21.0 pip install streamlink==1.0.0

Or install: pip3 install fake-useragent==0.1.11 pip3 install requests>=2.21.0 pip3 install streamlink==1.0.0

The error field says that you do not have python installed!

zoptein commented 2 years ago
"""
   Update from NjProVk
"""

import requests
from streamlink import Streamlink
import sys
import time
import random
from random import shuffle
from fake_useragent import UserAgent
import linecache

from threading import Thread

channel_urls = f"https://www.twitch.tv/{sys.argv[1]}"
proxies_file = "Proxies_txt/good_proxy.txt"
processes = []
max_nb_of_threads = int(sys.argv[2])

all_proxies = []
nb_of_proxies = 0

# Session creating for request
ua = UserAgent()
session = Streamlink()
session.set_option("http-headers", {'User-Agent': ua.random, "Client-ID": "ewvlchtxgqq88ru9gmfp1gmyt6h2b93"})

class ViewerBot:
    def print_exception(self):
        exc_type, exc_obj, tb = sys.exc_info()
        f = tb.tb_frame
        lineno = tb.tb_lineno
        filename = f.f_code.co_filename
        linecache.checkcache(filename)
        line = linecache.getline(filename, lineno, f.f_globals)
        print('EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj))

    def get_proxies(self):
        # Reading the list of proxies
        global nb_of_proxies
        try:
            lines = [line.rstrip("\n") for line in open(proxies_file)]
        except IOError as e:
            print("An error has occurred while trying to read the list of proxies: %s" % e.strerror)
            sys.exit(1)

        nb_of_proxies = len(lines)
        return lines

    def get_url(self):
        url = ""
        try:
            streams = session.streams(self.channel_url)
            try:
                url = streams['audio_only'].url
                print(f"URL : {url[:30]}...\n")
            except:
                url = streams['worst'].url
                print(f"URL : {url[:30]}...\n")

        except:
            pass
        return url

    def open_url(self,proxy_data):
        try:
            global all_proxies
            headers = {'User-Agent': ua.random}
            current_index = all_proxies.index(proxy_data)

            if proxy_data['url'] == "":
                proxy_data['url'] = self.get_url()
            current_url = proxy_data['url']
            try:
                if time.time() - proxy_data['time'] >= random.randint(1, 5):
                    current_proxy = {"http": f"https://{proxy_data['proxy']}", "https": f"http://{proxy_data['proxy']}"}
                    with requests.Session() as s:
                        response = s.head(current_url, proxies=current_proxy, headers=headers)
                    print(f"Sent HEAD request with {current_proxy['http']} | {response.status_code} | {response.request} | {response}")
                    proxy_data['time'] = time.time()
                    all_proxies[current_index] = proxy_data
            except:
                print("Connection Error!")

        except (KeyboardInterrupt, SystemExit):
            sys.exit()

    def mainmain(self):
        self.channel_url = channel_urls
        proxies = self.get_proxies()

        for p in proxies:
            all_proxies.append({'proxy': p, 'time': time.time(), 'url': ""})

        shuffle(all_proxies)
        list_of_all_proxies = all_proxies
        current_proxy_index = 0

        while True:
            try:
                for i in range(0, max_nb_of_threads):
                    threaded = Thread(target=self.open_url, args=(all_proxies[random.randint(0, len(all_proxies))],))
                    threaded.daemon = True  # This thread dies when main thread (only non-daemon thread) exits.
                    threaded.start()
            except:
                self.print_exception()
            shuffle(all_proxies)
            time.sleep(5)

ViewerBot = ViewerBot()
ViewerBot.mainmain()

image

teach me how to use it

zoptein commented 2 years ago

teach me how to use it bro pls

zoptein commented 2 years ago

who makes a video please my head hurts I already did everything it doesn't work for me please

zerodoxxx commented 2 years ago

Not able to install requirements fully, getting some error related to streamlink. Can you share a step-by-step guide on how to use it. Thanks in advance! getting this error image

fake-useragent==0.1.11 requests>=2.21.0 streamlink==1.0.0

Use command in console: pip install fake-useragent==0.1.11 pip install requests>=2.21.0 pip install streamlink==1.0.0

Or install: pip3 install fake-useragent==0.1.11 pip3 install requests>=2.21.0 pip3 install streamlink==1.0.0

The error field says that you do not have python installed!

I ran it using Anaconda command prompt, python should be considered installed i guess? Let me try what you've mentioned. Thanks!

NjProVk commented 2 years ago

teach me how to use it bro pls

Copy cod and paste in file threads_viewer.py and run!

zerodoxxx commented 2 years ago

Not able to install requirements fully, getting some error related to streamlink. Can you share a step-by-step guide on how to use it. Thanks in advance! getting this error image

fake-useragent==0.1.11 requests>=2.21.0 streamlink==1.0.0

Use command in console: pip install fake-useragent==0.1.11 pip install requests>=2.21.0 pip install streamlink==1.0.0

Or install: pip3 install fake-useragent==0.1.11 pip3 install requests>=2.21.0 pip3 install streamlink==1.0.0

The error field says that you do not have python installed!

Getting "Connection error" now, any idea why? image

NjProVk commented 2 years ago

What proxies are you using? The code I posted uses http(s)

zoptein commented 2 years ago

What proxies are you using? The code I posted uses http(s)

whenever it executed the normal code it redirects me what do i do

zoptein commented 2 years ago

teach me how to use it bro pls

Copy cod and paste in file threads_viewer.py and run!

I already did everything I downloaded all the libraries everything at the time of executing it in its folder it executed it and it redirects me to a program I don't know what to do there

zerodoxxx commented 2 years ago

What proxies are you using? The code I posted uses http(s)

Tried changing the proxies to working proxies in India, now i am getting this: image

zoptein commented 2 years ago

What proxies are you using? The code I posted uses http(s)

Tried changing the proxies to working proxies in India, now i am getting this: image

you explain to me how to use it better it is not well explained I have all the requirements and VLC I do not know what I am missing it ran and sends me a link to open with a program

zoptein commented 2 years ago

I already learned a lot, thank you, only the proxies are missing, I recommend that we make this use cookies so that the proxies are not railings, and thank you very much for your attention

zoptein commented 2 years ago
"""
   Update from NjProVk
"""

import requests
from streamlink import Streamlink
import sys
import time
import random
from random import shuffle
from fake_useragent import UserAgent
import linecache

from threading import Thread

channel_urls = f"https://www.twitch.tv/{sys.argv[1]}"
proxies_file = "Proxies_txt/good_proxy.txt"
processes = []
max_nb_of_threads = int(sys.argv[2])

all_proxies = []
nb_of_proxies = 0

# Session creating for request
ua = UserAgent()
session = Streamlink()
session.set_option("http-headers", {'User-Agent': ua.random, "Client-ID": "ewvlchtxgqq88ru9gmfp1gmyt6h2b93"})

class ViewerBot:
    def print_exception(self):
        exc_type, exc_obj, tb = sys.exc_info()
        f = tb.tb_frame
        lineno = tb.tb_lineno
        filename = f.f_code.co_filename
        linecache.checkcache(filename)
        line = linecache.getline(filename, lineno, f.f_globals)
        print('EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj))

    def get_proxies(self):
        # Reading the list of proxies
        global nb_of_proxies
        try:
            lines = [line.rstrip("\n") for line in open(proxies_file)]
        except IOError as e:
            print("An error has occurred while trying to read the list of proxies: %s" % e.strerror)
            sys.exit(1)

        nb_of_proxies = len(lines)
        return lines

    def get_url(self):
        url = ""
        try:
            streams = session.streams(self.channel_url)
            try:
                url = streams['audio_only'].url
                print(f"URL : {url[:30]}...\n")
            except:
                url = streams['worst'].url
                print(f"URL : {url[:30]}...\n")

        except:
            pass
        return url

    def open_url(self,proxy_data):
        try:
            global all_proxies
            headers = {'User-Agent': ua.random}
            current_index = all_proxies.index(proxy_data)

            if proxy_data['url'] == "":
                proxy_data['url'] = self.get_url()
            current_url = proxy_data['url']
            try:
                if time.time() - proxy_data['time'] >= random.randint(1, 5):
                    current_proxy = {"http": f"https://{proxy_data['proxy']}", "https": f"http://{proxy_data['proxy']}"}
                    with requests.Session() as s:
                        response = s.head(current_url, proxies=current_proxy, headers=headers)
                    print(f"Sent HEAD request with {current_proxy['http']} | {response.status_code} | {response.request} | {response}")
                    proxy_data['time'] = time.time()
                    all_proxies[current_index] = proxy_data
            except:
                print("Connection Error!")

        except (KeyboardInterrupt, SystemExit):
            sys.exit()

    def mainmain(self):
        self.channel_url = channel_urls
        proxies = self.get_proxies()

        for p in proxies:
            all_proxies.append({'proxy': p, 'time': time.time(), 'url': ""})

        shuffle(all_proxies)
        list_of_all_proxies = all_proxies
        current_proxy_index = 0

        while True:
            try:
                for i in range(0, max_nb_of_threads):
                    threaded = Thread(target=self.open_url, args=(all_proxies[random.randint(0, len(all_proxies))],))
                    threaded.daemon = True  # This thread dies when main thread (only non-daemon thread) exits.
                    threaded.start()
            except:
                self.print_exception()
            shuffle(all_proxies)
            time.sleep(5)

ViewerBot = ViewerBot()
ViewerBot.mainmain()

image

Bro line 107 of threader is problem

zaeboba commented 2 years ago
"""
   Update from NjProVk
"""

import requests
from streamlink import Streamlink
import sys
import time
import random
from random import shuffle
from fake_useragent import UserAgent
import linecache

from threading import Thread

channel_urls = f"https://www.twitch.tv/{sys.argv[1]}"
proxies_file = "Proxies_txt/good_proxy.txt"
processes = []
max_nb_of_threads = int(sys.argv[2])

all_proxies = []
nb_of_proxies = 0

# Session creating for request
ua = UserAgent()
session = Streamlink()
session.set_option("http-headers", {'User-Agent': ua.random, "Client-ID": "ewvlchtxgqq88ru9gmfp1gmyt6h2b93"})

class ViewerBot:
    def print_exception(self):
        exc_type, exc_obj, tb = sys.exc_info()
        f = tb.tb_frame
        lineno = tb.tb_lineno
        filename = f.f_code.co_filename
        linecache.checkcache(filename)
        line = linecache.getline(filename, lineno, f.f_globals)
        print('EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj))

    def get_proxies(self):
        # Reading the list of proxies
        global nb_of_proxies
        try:
            lines = [line.rstrip("\n") for line in open(proxies_file)]
        except IOError as e:
            print("An error has occurred while trying to read the list of proxies: %s" % e.strerror)
            sys.exit(1)

        nb_of_proxies = len(lines)
        return lines

    def get_url(self):
        url = ""
        try:
            streams = session.streams(self.channel_url)
            try:
                url = streams['audio_only'].url
                print(f"URL : {url[:30]}...\n")
            except:
                url = streams['worst'].url
                print(f"URL : {url[:30]}...\n")

        except:
            pass
        return url

    def open_url(self,proxy_data):
        try:
            global all_proxies
            headers = {'User-Agent': ua.random}
            current_index = all_proxies.index(proxy_data)

            if proxy_data['url'] == "":
                proxy_data['url'] = self.get_url()
            current_url = proxy_data['url']
            try:
                if time.time() - proxy_data['time'] >= random.randint(1, 5):
                    current_proxy = {"http": f"https://{proxy_data['proxy']}", "https": f"http://{proxy_data['proxy']}"}
                    with requests.Session() as s:
                        response = s.head(current_url, proxies=current_proxy, headers=headers)
                    print(f"Sent HEAD request with {current_proxy['http']} | {response.status_code} | {response.request} | {response}")
                    proxy_data['time'] = time.time()
                    all_proxies[current_index] = proxy_data
            except:
                print("Connection Error!")

        except (KeyboardInterrupt, SystemExit):
            sys.exit()

    def mainmain(self):
        self.channel_url = channel_urls
        proxies = self.get_proxies()

        for p in proxies:
            all_proxies.append({'proxy': p, 'time': time.time(), 'url': ""})

        shuffle(all_proxies)
        list_of_all_proxies = all_proxies
        current_proxy_index = 0

        while True:
            try:
                for i in range(0, max_nb_of_threads):
                    threaded = Thread(target=self.open_url, args=(all_proxies[random.randint(0, len(all_proxies))],))
                    threaded.daemon = True  # This thread dies when main thread (only non-daemon thread) exits.
                    threaded.start()
            except:
                self.print_exception()
            shuffle(all_proxies)
            time.sleep(5)

ViewerBot = ViewerBot()
ViewerBot.mainmain()

изображение

Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! ^CTraceback (most recent call last): File "threads_viewer.py", line 113, in ViewerBot.mainmain() File "threads_viewer.py", line 109, in mainmain time.sleep(5) KeyboardInterrupt

???

NjProVk commented 2 years ago
"""
   Update from NjProVk
"""

import requests
from streamlink import Streamlink
import sys
import time
import random
from random import shuffle
from fake_useragent import UserAgent
import linecache

from threading import Thread

channel_urls = f"https://www.twitch.tv/{sys.argv[1]}"
proxies_file = "Proxies_txt/good_proxy.txt"
processes = []
max_nb_of_threads = int(sys.argv[2])

all_proxies = []
nb_of_proxies = 0

# Session creating for request
ua = UserAgent()
session = Streamlink()
session.set_option("http-headers", {'User-Agent': ua.random, "Client-ID": "ewvlchtxgqq88ru9gmfp1gmyt6h2b93"})

class ViewerBot:
    def print_exception(self):
        exc_type, exc_obj, tb = sys.exc_info()
        f = tb.tb_frame
        lineno = tb.tb_lineno
        filename = f.f_code.co_filename
        linecache.checkcache(filename)
        line = linecache.getline(filename, lineno, f.f_globals)
        print('EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj))

    def get_proxies(self):
        # Reading the list of proxies
        global nb_of_proxies
        try:
            lines = [line.rstrip("\n") for line in open(proxies_file)]
        except IOError as e:
            print("An error has occurred while trying to read the list of proxies: %s" % e.strerror)
            sys.exit(1)

        nb_of_proxies = len(lines)
        return lines

    def get_url(self):
        url = ""
        try:
            streams = session.streams(self.channel_url)
            try:
                url = streams['audio_only'].url
                print(f"URL : {url[:30]}...\n")
            except:
                url = streams['worst'].url
                print(f"URL : {url[:30]}...\n")

        except:
            pass
        return url

    def open_url(self,proxy_data):
        try:
            global all_proxies
            headers = {'User-Agent': ua.random}
            current_index = all_proxies.index(proxy_data)

            if proxy_data['url'] == "":
                proxy_data['url'] = self.get_url()
            current_url = proxy_data['url']
            try:
                if time.time() - proxy_data['time'] >= random.randint(1, 5):
                    current_proxy = {"http": f"https://{proxy_data['proxy']}", "https": f"http://{proxy_data['proxy']}"}
                    with requests.Session() as s:
                        response = s.head(current_url, proxies=current_proxy, headers=headers)
                    print(f"Sent HEAD request with {current_proxy['http']} | {response.status_code} | {response.request} | {response}")
                    proxy_data['time'] = time.time()
                    all_proxies[current_index] = proxy_data
            except:
                print("Connection Error!")

        except (KeyboardInterrupt, SystemExit):
            sys.exit()

    def mainmain(self):
        self.channel_url = channel_urls
        proxies = self.get_proxies()

        for p in proxies:
            all_proxies.append({'proxy': p, 'time': time.time(), 'url': ""})

        shuffle(all_proxies)
        list_of_all_proxies = all_proxies
        current_proxy_index = 0

        while True:
            try:
                for i in range(0, max_nb_of_threads):
                    threaded = Thread(target=self.open_url, args=(all_proxies[random.randint(0, len(all_proxies))],))
                    threaded.daemon = True  # This thread dies when main thread (only non-daemon thread) exits.
                    threaded.start()
            except:
                self.print_exception()
            shuffle(all_proxies)
            time.sleep(5)

ViewerBot = ViewerBot()
ViewerBot.mainmain()

изображение

Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! Connection Error! ^CTraceback (most recent call last): File "threads_viewer.py", line 113, in ViewerBot.mainmain() File "threads_viewer.py", line 109, in mainmain time.sleep(5) KeyboardInterrupt

???

Proxy http(s)?

NjProVk commented 2 years ago

I already learned a lot, thank you, only the proxies are missing, I recommend that we make this use cookies so that the proxies are not railings, and thank you very much for your attention

This proxy http(s), cookies can be completed!

NjProVk commented 2 years ago

What proxies are you using? The code I posted uses http(s)

Tried changing the proxies to working proxies in India, now i am getting this: image

you explain to me how to use it better it is not well explained I have all the requirements and VLC I do not know what I am missing it ran and sends me a link to open with a program

You have a file in which you will need to have a proxy like http (s), with line separation!

NjProVk commented 2 years ago

What proxies are you using? The code I posted uses http(s)

Tried changing the proxies to working proxies in India, now i am getting this: image

Proxies must be separated by a new line: ip:port ip:port ip:port

zaeboba commented 2 years ago

Proxy http(s)?

Yes, http I also tried socks4\socks5 from the address https://github.com/monosans/proxy-list

RiRaNerd commented 2 years ago

I have the same Problem with the Proxys. Connection error with all seperat Proxys. Any idea?