Streamline user agent and client ID access
This commit is contained in:
1 parent
d100c4b7ff
commit
28c0f8b75e
2 files changed
+33
-13
No files matched your search
+26
-6
@@ -6,6 +6,7 @@ from pathlib import Path
|
|||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from collections import namedtuple
|
||||||
from typing import Any, Dict, Literal, NewType, TYPE_CHECKING
|
from typing import Any, Dict, Literal, NewType, TYPE_CHECKING
|
||||||
|
|
||||||
from yarl import URL
|
from yarl import URL
|
||||||
@@ -69,12 +70,6 @@ MAX_CHANNELS = MAX_TOPICS // TOPICS_PER_CHANNEL
|
|||||||
# Misc
|
# Misc
|
||||||
DEFAULT_LANG = "English"
|
DEFAULT_LANG = "English"
|
||||||
BASE_URL = URL("https://twitch.tv")
|
BASE_URL = URL("https://twitch.tv")
|
||||||
CLIENT_ID = "kd1unb4b3q4t58fwlpcbzcbnm76a8fp"
|
|
||||||
# CLIENT_ID = "uo6dggojyb8d6soh92zknwmi5ej1q2"
|
|
||||||
ANDROID_USER_AGENT = (
|
|
||||||
"Dalvik/2.1.0 (Linux; U; Android 7.1.2; SM-G977N Build/LMY48Z) "
|
|
||||||
"tv.twitch.android.app/14.3.2/1403020"
|
|
||||||
)
|
|
||||||
# Intervals and Delays
|
# Intervals and Delays
|
||||||
PING_INTERVAL = timedelta(minutes=3)
|
PING_INTERVAL = timedelta(minutes=3)
|
||||||
PING_TIMEOUT = timedelta(seconds=10)
|
PING_TIMEOUT = timedelta(seconds=10)
|
||||||
@@ -90,6 +85,31 @@ FILE_FORMATTER = logging.Formatter(
|
|||||||
datefmt="%Y-%m-%d %H:%M:%S",
|
datefmt="%Y-%m-%d %H:%M:%S",
|
||||||
)
|
)
|
||||||
OUTPUT_FORMATTER = logging.Formatter("{levelname}: {message}", style='{', datefmt="%H:%M:%S")
|
OUTPUT_FORMATTER = logging.Formatter("{levelname}: {message}", style='{', datefmt="%H:%M:%S")
|
||||||
|
ClientInfo = namedtuple("ClientInfo", ["CLIENT_ID", "USER_AGENT"])
|
||||||
|
|
||||||
|
|
||||||
|
class ClientType:
|
||||||
|
WEB = ClientInfo(
|
||||||
|
"kimne78kx3ncx6brgo4mv6wki5h1ko",
|
||||||
|
(
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
||||||
|
"(KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
ANDROID = ClientInfo(
|
||||||
|
"kd1unb4b3q4t58fwlpcbzcbnm76a8fp",
|
||||||
|
(
|
||||||
|
"Dalvik/2.1.0 (Linux; U; Android 7.1.2; SM-G977N Build/LMY48Z) "
|
||||||
|
"tv.twitch.android.app/14.3.2/1403020"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
SMARTBOX = ClientInfo(
|
||||||
|
"ue6666qo983tsx6so1t0vnawi233wa",
|
||||||
|
(
|
||||||
|
"Mozilla/5.0 (Linux; Android 7.1; Smart Box C1) AppleWebKit/537.36 "
|
||||||
|
"(KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class State(Enum):
|
class State(Enum):
|
||||||
|
|||||||
@@ -56,14 +56,13 @@ from utils import (
|
|||||||
from constants import (
|
from constants import (
|
||||||
CALL,
|
CALL,
|
||||||
BASE_URL,
|
BASE_URL,
|
||||||
CLIENT_ID,
|
|
||||||
COOKIES_PATH,
|
COOKIES_PATH,
|
||||||
GQL_OPERATIONS,
|
GQL_OPERATIONS,
|
||||||
MAX_CHANNELS,
|
MAX_CHANNELS,
|
||||||
WATCH_INTERVAL,
|
WATCH_INTERVAL,
|
||||||
DROPS_ENABLED_TAG,
|
DROPS_ENABLED_TAG,
|
||||||
ANDROID_USER_AGENT,
|
|
||||||
State,
|
State,
|
||||||
|
ClientType,
|
||||||
WebsocketTopic,
|
WebsocketTopic,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -87,6 +86,7 @@ class SkipExtraJsonDecoder(json.JSONDecoder):
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
CLIENT_ID, USER_AGENT = ClientType.ANDROID
|
||||||
SAFE_LOADS = lambda s: json.loads(s, cls=SkipExtraJsonDecoder)
|
SAFE_LOADS = lambda s: json.loads(s, cls=SkipExtraJsonDecoder)
|
||||||
|
|
||||||
|
|
||||||
@@ -276,6 +276,9 @@ class _AuthState:
|
|||||||
token_kind: str = ''
|
token_kind: str = ''
|
||||||
use_chrome: bool = False
|
use_chrome: bool = False
|
||||||
payload: JsonType = {
|
payload: JsonType = {
|
||||||
|
# username and password are added later
|
||||||
|
# "username": str,
|
||||||
|
# "password": str,
|
||||||
"client_id": CLIENT_ID, # client ID to-be associated with the access token
|
"client_id": CLIENT_ID, # client ID to-be associated with the access token
|
||||||
"undelete_user": False, # purpose unknown
|
"undelete_user": False, # purpose unknown
|
||||||
"remember_me": True, # persist the session via the cookie
|
"remember_me": True, # persist the session via the cookie
|
||||||
@@ -310,7 +313,7 @@ class _AuthState:
|
|||||||
"Client-Id": CLIENT_ID,
|
"Client-Id": CLIENT_ID,
|
||||||
"Content-Type": "application/json; charset=UTF-8",
|
"Content-Type": "application/json; charset=UTF-8",
|
||||||
"Host": "passport.twitch.tv",
|
"Host": "passport.twitch.tv",
|
||||||
"User-Agent": ANDROID_USER_AGENT,
|
"User-Agent": USER_AGENT,
|
||||||
"X-Device-Id": self.device_id,
|
"X-Device-Id": self.device_id,
|
||||||
# "X-Device-Id": ''.join(random.choices('0123456789abcdef', k=32)),
|
# "X-Device-Id": ''.join(random.choices('0123456789abcdef', k=32)),
|
||||||
}
|
}
|
||||||
@@ -569,10 +572,7 @@ class Twitch:
|
|||||||
chrome_agent = random.choice(agents[7:11])
|
chrome_agent = random.choice(agents[7:11])
|
||||||
except Exception:
|
except Exception:
|
||||||
# looks like we can't rely on 3rd parties too much
|
# looks like we can't rely on 3rd parties too much
|
||||||
chrome_agent = (
|
chrome_agent = ClientType.WEB.USER_AGENT
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
|
||||||
"(KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"
|
|
||||||
)
|
|
||||||
# load in cookies
|
# load in cookies
|
||||||
cookie_jar = aiohttp.CookieJar()
|
cookie_jar = aiohttp.CookieJar()
|
||||||
if COOKIES_PATH.exists():
|
if COOKIES_PATH.exists():
|
||||||
|
|||||||
Reference in new issue
Block a user