File size: 2,032 Bytes
d639380
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import random

from curl_cffi.requests import AsyncSession


class Client:
    def __init__(self, proxy=None, timeout=15, verify=True):
        self.proxies = {
            "http": proxy,
            "https": proxy,
        }
        self.timeout = timeout
        self.verify = verify

        self.impersonate = random.choice(['safari15_3'])
        # impersonate=self.impersonate

        # self.ja3 = ""
        # self.akamai = ""
        # ja3=self.ja3, akamai=self.akamai
        self.session = AsyncSession(proxies=self.proxies, timeout=self.timeout, verify=self.verify)
        self.session2 = AsyncSession(proxies=self.proxies, timeout=self.timeout, verify=self.verify)

    async def post(self, *args, **kwargs):
        r = await self.session.post(*args, impersonate=self.impersonate, **kwargs)
        return r

    async def post_stream(self, *args, headers=None, cookies=None, **kwargs):
        if self.session:
            headers = headers or self.session.headers
            cookies = cookies or self.session.cookies
        r = await self.session2.post(*args, headers=headers, cookies=cookies, impersonate=self.impersonate, **kwargs)
        return r

    async def get(self, *args, **kwargs):
        r = await self.session.get(*args, impersonate=self.impersonate, **kwargs)
        return r

    async def request(self, *args, **kwargs):
        r = await self.session.request(*args, impersonate=self.impersonate, **kwargs)
        return r

    async def put(self, *args, **kwargs):
        r = await self.session.put(*args, impersonate=self.impersonate, **kwargs)
        return r

    async def close(self):
        if self.session:
            try:
                await self.session.close()
                del self.session
            except Exception:
                pass
        if self.session2:
            try:
                await self.session2.close()
                del self.session2
            except Exception:
                pass