|
| 1 | +import aiohttp, asyncio |
| 2 | +from re import search |
| 3 | +from aiohttp_socks import ProxyConnector |
| 4 | +from argparse import ArgumentParser |
| 5 | +from re import compile |
| 6 | +from os import system, name |
| 7 | +from threading import Thread |
| 8 | +from time import sleep |
| 9 | + |
| 10 | + |
| 11 | +user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36" |
| 12 | +REGEX = compile( |
| 13 | + r"(?:^|\D)?(("+ r"(?:[1-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])" |
| 14 | + + r"\." + r"(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])" |
| 15 | + + r"\." + r"(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])" |
| 16 | + + r"\." + r"(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])" |
| 17 | + + r"):" + (r"(?:\d|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}" |
| 18 | + + r"|65[0-4]\d{2}|655[0-2]\d|6553[0-5])") |
| 19 | + + r")(?:\D|$)" |
| 20 | +) |
| 21 | + |
| 22 | + |
| 23 | +class Telegram: |
| 24 | + def __init__(self, channel: str, post: int) -> None: |
| 25 | + self.tasks = 500 |
| 26 | + self.channel = channel |
| 27 | + self.post = post |
| 28 | + |
| 29 | + self.cookie_error = 0 |
| 30 | + self.sucsess_sent = 0 |
| 31 | + self.failled_sent = 0 |
| 32 | + self.unkown_error = 0 |
| 33 | + self.token_error = 0 |
| 34 | + self.proxy_error = 0 |
| 35 | + |
| 36 | + |
| 37 | + async def request(self, proxy: str, proxy_type: str): |
| 38 | + if proxy_type == 'socks4': connector = ProxyConnector.from_url(f'socks4://{proxy}') |
| 39 | + elif proxy_type == 'socks5': connector = ProxyConnector.from_url(f'socks5://{proxy}') |
| 40 | + elif proxy_type == 'https': connector = ProxyConnector.from_url(f'https://{proxy}') |
| 41 | + else: connector = ProxyConnector.from_url(f'http://{proxy}') |
| 42 | + |
| 43 | + jar = aiohttp.CookieJar(unsafe=True) |
| 44 | + async with aiohttp.ClientSession(cookie_jar=jar, connector=connector) as session: |
| 45 | + try: |
| 46 | + async with session.get( |
| 47 | + f'https://t.me/{self.channel}/{self.post}?embed=1&mode=tme', |
| 48 | + headers={ |
| 49 | + 'referer': f'https://t.me/{self.channel}/{self.post}', |
| 50 | + 'user-agent': user_agent |
| 51 | + }, timeout=aiohttp.ClientTimeout(total=5) |
| 52 | + ) as embed_response: |
| 53 | + if jar.filter_cookies(embed_response.url).get('stel_ssid'): |
| 54 | + views_token = search('data-view="([^"]+)"', await embed_response.text()) |
| 55 | + if views_token: |
| 56 | + views_response = await session.post( |
| 57 | + 'https://t.me/v/?views=' + views_token.group(1), |
| 58 | + headers={ |
| 59 | + 'referer': f'https://t.me/{self.channel}/{self.post}?embed=1&mode=tme', |
| 60 | + 'user-agent': user_agent, 'x-requested-with': 'XMLHttpRequest' |
| 61 | + }, timeout=aiohttp.ClientTimeout(total=5) |
| 62 | + ) |
| 63 | + if ( |
| 64 | + await views_response.text() == "true" |
| 65 | + and views_response.status == 200 |
| 66 | + ): self.sucsess_sent += 1 |
| 67 | + else: self.failled_sent += 1 |
| 68 | + else: self.token_error += 1 |
| 69 | + else: self.cookie_error += 1 |
| 70 | + except: self.proxy_error += 1 |
| 71 | + finally: jar.clear() |
| 72 | + |
| 73 | + |
| 74 | + def run_proxies_tasks(self, lines: list, proxy_type): |
| 75 | + async def inner(proxies: list): |
| 76 | + await asyncio.wait( |
| 77 | + [asyncio.create_task(self.request(proxy, proxy_type)) |
| 78 | + for proxy in proxies] |
| 79 | + ) |
| 80 | + |
| 81 | + chunks = [lines[i:i+self.tasks] for i in range(0, len(lines), self.tasks)] |
| 82 | + for chunk in chunks: asyncio.run(inner(chunk)) |
| 83 | + |
| 84 | + |
| 85 | + def run_auto_tasks(self): |
| 86 | + while True: |
| 87 | + async def inner(proxies: tuple): |
| 88 | + await asyncio.wait( |
| 89 | + [asyncio.create_task(self.request(proxy, proxy_type)) |
| 90 | + for proxy_type, proxy in proxies] |
| 91 | + ) |
| 92 | + |
| 93 | + auto = Auto() |
| 94 | + chunks = [auto.proxies[i:i+self.tasks] for i in range(0, len(auto.proxies), self.tasks)] |
| 95 | + for chunk in chunks: asyncio.run(inner(chunk)) |
| 96 | + |
| 97 | + |
| 98 | + async def run_rotated_task(self, proxy, proxy_type): |
| 99 | + while True: |
| 100 | + await asyncio.wait( |
| 101 | + [asyncio.create_task(self.request(proxy, proxy_type)) |
| 102 | + for _ in range(self.tasks)] |
| 103 | + ) |
| 104 | + |
| 105 | + |
| 106 | + def cli(self): |
| 107 | + logo = ''' |
| 108 | + ~ Telegram Auto Views V4 ~ |
| 109 | + ~ github.com/TeaByte ~ |
| 110 | + ~ @TeaByte ~ |
| 111 | + ''' |
| 112 | + while not self.sucsess_sent: |
| 113 | + print(logo) |
| 114 | + print('\n\n [ Waiting... ]\r') |
| 115 | + sleep(0.3);system('cls' if name=='nt' else 'clear') |
| 116 | + |
| 117 | + while True: |
| 118 | + print(logo) |
| 119 | + print(f''' |
| 120 | + DATA: |
| 121 | + @{self.channel}/{self.post} |
| 122 | + Sent: {self.sucsess_sent} |
| 123 | + Fail: {self.failled_sent} |
| 124 | +
|
| 125 | + ERRORS: |
| 126 | + Proxy Error: {self.proxy_error} |
| 127 | + Token Error: {self.token_error} |
| 128 | + Cookie Error: {self.cookie_error} |
| 129 | + Unkown Error: {self.unkown_error} |
| 130 | + ''') |
| 131 | + sleep(0.3);system('cls' if name=='nt' else 'clear') |
| 132 | + |
| 133 | + |
| 134 | +class Auto: |
| 135 | + def __init__(self): |
| 136 | + self.proxies = [] |
| 137 | + try: |
| 138 | + with open(f'auto/http.txt', 'r') as file: |
| 139 | + self.http_sources = file.read().splitlines() |
| 140 | + |
| 141 | + with open(f'auto/socks4.txt', 'r') as file: |
| 142 | + self.socks4_sources = file.read().splitlines() |
| 143 | + |
| 144 | + with open(f'auto/http.txt', 'r') as file: |
| 145 | + self.socks5_sources = file.read().splitlines() |
| 146 | + |
| 147 | + except FileNotFoundError: |
| 148 | + print(' [ Error ] auto file not found!') |
| 149 | + exit() |
| 150 | + |
| 151 | + print(' [ WAIT ] Scraping proxies... ') |
| 152 | + asyncio.run(self.init()) |
| 153 | + |
| 154 | + |
| 155 | + async def scrap(self, source_url, proxy_type): |
| 156 | + try: |
| 157 | + async with aiohttp.ClientSession() as session: |
| 158 | + async with session.get( |
| 159 | + source_url, |
| 160 | + headers={'user-agent': user_agent}, |
| 161 | + timeout=aiohttp.ClientTimeout(total=15) |
| 162 | + ) as response: |
| 163 | + html = await response.text() |
| 164 | + if tuple(REGEX.finditer(html)): |
| 165 | + for proxy in tuple(REGEX.finditer(html)): |
| 166 | + self.proxies.append( (proxy_type, proxy.group(1)) ) |
| 167 | + except Exception as e: |
| 168 | + with open('error.txt', 'a', encoding='utf-8', errors='ignore') as f: |
| 169 | + f.write(f'{source_url} -> {e}\n') |
| 170 | + |
| 171 | + |
| 172 | + async def init(self): |
| 173 | + tasks = [] |
| 174 | + self.proxies.clear() |
| 175 | + for sources in ( |
| 176 | + (self.http_sources, 'http'), |
| 177 | + (self.socks4_sources, 'socks4'), |
| 178 | + (self.socks5_sources, 'socks5') |
| 179 | + ): |
| 180 | + srcs, proxy_type = sources |
| 181 | + for source_url in srcs: |
| 182 | + task = asyncio.create_task( |
| 183 | + self.scrap(source_url, proxy_type) |
| 184 | + ) |
| 185 | + tasks.append(task) |
| 186 | + await asyncio.wait(tasks) |
| 187 | + |
| 188 | + |
| 189 | +parser = ArgumentParser() |
| 190 | +parser.add_argument('-c', '--channel', dest='channel', help='Channel user', type=str, required=True) |
| 191 | +parser.add_argument('-pt', '--post', dest='post', help='Post number', type=int, required=True) |
| 192 | +parser.add_argument('-t', '--type', dest='type', help='Proxy type', type=str, required=False) |
| 193 | +parser.add_argument('-m', '--mode', dest='mode', help='Proxy mode', type=str, required=True) |
| 194 | +parser.add_argument('-p', '--proxy', dest='proxy', help='Proxy file path or user:password@host:port', type=str, required=False) |
| 195 | +args = parser.parse_args() |
| 196 | + |
| 197 | +api = Telegram(args.channel, args.post) |
| 198 | +Thread(target=api.cli).start() |
| 199 | + |
| 200 | +if args.mode[0] == "l": |
| 201 | + with open(args.proxy, 'r') as file: |
| 202 | + lines = file.read().splitlines() |
| 203 | + api.run_proxies_tasks(lines, args.type) |
| 204 | + |
| 205 | +elif args.mode[0] == "r": |
| 206 | + asyncio.run(api.run_rotated_task(args.proxy, args.type)) |
| 207 | + |
| 208 | +else: api.run_auto_tasks() |
0 commit comments