rdavydov / Twitch-Channel-Points-Miner-v2

A simple script that will watch a stream for you and earn the channel points.
GNU General Public License v3.0
1.21k stars 352 forks source link

Regex to extract the client version can't extract the current client version #524

Closed hingston closed 3 months ago

hingston commented 4 months ago

Describe the bug

The current Twitch Client version is 9dbe3596-5fee-4273-a87d-7a40b484f587 and the regex used to extract it fails.

Steps to reproduce

Using the current regex results with Error with update_client_version: no match:

import re

# Adjusted pattern to be more robust
twilight_build_id_pattern = re.compile(
    r"window\.__twilightBuildID=\"([0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12})\";"
)

# Given response text
response_text = '''src="https://assets.twitch.tv/config/settings.9572a8af59705166e482a9b48096757e.js" crossorigin="anonymous"></script><script>try{var defaultSpadeEndpoint="https://spade.twitch.tv/track";window.__twilightBuildID="9dbe3596-5fee-4273-a87d-7a40b484f587",window.__twilightSubsite="www";for(var entries=document.cookie.split("; "),cookies={},i=entries.length-1;i>=0;i--){var entry=entries[i].split("=",2);cookies[entry[0]]=entry[1]}function fetchlike(e){retur'''

# Search for pattern in the text
matcher = re.search(twilight_build_id_pattern, response_text)
if not matcher:
    print("Error with update_client_version: no match")
else:
    twilight_build_id = matcher.group(1)
    print(f"Matched Build ID: {twilight_build_id}")

This updated regex outputs Matched Build ID: 9dbe3596-5fee-4273-a87d-7a40b484f587:

import re

# Adjusted pattern to be more robust
twilight_build_id_pattern = re.compile(
    r'window\.__twilightBuildID\s*=\s*"([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})"'
)

# Given response text
response_text = '''src="https://assets.twitch.tv/config/settings.9572a8af59705166e482a9b48096757e.js" crossorigin="anonymous"></script><script>try{var defaultSpadeEndpoint="https://spade.twitch.tv/track";window.__twilightBuildID="9dbe3596-5fee-4273-a87d-7a40b484f587",window.__twilightSubsite="www";for(var entries=document.cookie.split("; "),cookies={},i=entries.length-1;i>=0;i--){var entry=entries[i].split("=",2);cookies[entry[0]]=entry[1]}function fetchlike(e){retur'''

# Search for pattern in the text
matcher = re.search(twilight_build_id_pattern, response_text)
if not matcher:
    print("Error with update_client_version: no match")
else:
    twilight_build_id = matcher.group(1)
    print(f"Matched Build ID: {twilight_build_id}")

Expected behavior

The regex extracts the client version.

Operating system

Windows 11

Python version

3.12.3

Miner version

Twitch Channel Points Miner v2-1.9.5 (fork by rdavydov)

Other relevant software versions

No response

Logs

logger_settings=LoggerSettings(save=True)

Additional context

No response