3
3
import re
4
4
import sys
5
5
import json
6
- import random
7
6
import asyncio
8
7
import logging
9
8
from time import time
@@ -91,7 +90,7 @@ def decode(self, s: str, *args):
91
90
return obj
92
91
93
92
94
- CLIENT_ID , USER_AGENT = ClientType .SMARTBOX
93
+ CLIENT_ID , USER_AGENT = ClientType .MOBILE_WEB
95
94
SAFE_LOADS = lambda s : json .loads (s , cls = SkipExtraJsonDecoder )
96
95
97
96
@@ -499,8 +498,8 @@ def headers(
499
498
headers ["User-Agent" ] = user_agent
500
499
if hasattr (self , "session_id" ):
501
500
headers ["Client-Session-Id" ] = self .session_id
502
- if hasattr (self , "client_version" ):
503
- headers ["Client-Version" ] = self .client_version
501
+ # if hasattr(self, "client_version"):
502
+ # headers["Client-Version"] = self.client_version
504
503
if hasattr (self , "device_id" ):
505
504
headers ["X-Device-Id" ] = self .device_id
506
505
if gql :
@@ -526,10 +525,11 @@ async def _validate(self):
526
525
"GET" , BASE_URL , headers = self .headers ()
527
526
) as response :
528
527
page_html = await response .text ("utf8" )
529
- match = re .search (r'twilightBuildID="([-a-z0-9]+)"' , page_html )
530
- if match is None :
531
- raise MinerException ("Unable to extract client_version" )
532
- self .client_version = match .group (1 )
528
+ assert page_html is not None
529
+ # match = re.search(r'twilightBuildID="([-a-z0-9]+)"', page_html)
530
+ # if match is None:
531
+ # raise MinerException("Unable to extract client_version")
532
+ # self.client_version = match.group(1)
533
533
# doing the request ends up setting the "unique_id" value in the cookie
534
534
cookie = jar .filter_cookies (BASE_URL )
535
535
self .device_id = cookie ["unique_id" ].value
@@ -639,21 +639,6 @@ async def get_session(self) -> aiohttp.ClientSession:
639
639
if session .closed :
640
640
raise RuntimeError ("Session is closed" )
641
641
return session
642
- # try to obtain the latest Chrome user agent from a Github project
643
- try :
644
- async with aiohttp .request (
645
- "GET" ,
646
- "https://jnrbsn.github.io/user-agents/user-agents.json" ,
647
- proxy = self .settings .proxy or None ,
648
- ) as response :
649
- agents = await response .json ()
650
- if sys .platform == "win32" :
651
- chrome_agent = random .choice (agents [:3 ])
652
- elif sys .platform == "linux" :
653
- chrome_agent = random .choice (agents [7 :11 ])
654
- except Exception :
655
- # looks like we can't rely on 3rd parties too much
656
- chrome_agent = ClientType .WEB .USER_AGENT
657
642
# load in cookies
658
643
cookie_jar = aiohttp .CookieJar ()
659
644
try :
@@ -668,7 +653,7 @@ async def get_session(self) -> aiohttp.ClientSession:
668
653
self ._session = aiohttp .ClientSession (
669
654
connector = connector ,
670
655
cookie_jar = cookie_jar ,
671
- headers = {"User-Agent" : chrome_agent },
656
+ headers = {"User-Agent" : USER_AGENT },
672
657
timeout = aiohttp .ClientTimeout (connect = 5 , total = 10 ),
673
658
)
674
659
return self ._session
0 commit comments