diff --git a/DefaultConstants.py b/DefaultConstants.py index 0511f25..b92d29b 100644 --- a/DefaultConstants.py +++ b/DefaultConstants.py @@ -171,7 +171,7 @@ class Constants: # Titles for platforms that have optional titles or no titles at all # You can also use the /title command to create temporary titles for a platform on the fly, but once the TEMP_TITLE_UPTIME time is up then it defaults back to these titles # If the titles contain any variation of RR/Rerun/not live then it will be detected by rerun detection - fansDefaultTitle = "Naughty Fansly stream? =)" + fansDefaultTitle = "🍑💦Now taking good vibes on stream! =)🍑💦" ofDefaultTitle = "Naughty time? =)" cam4DefaultTitle = "Cam4 Naughty Time." mfcDefaultTitle = "MFC Fun Time." diff --git a/checkers/Twitch.py b/checkers/Twitch.py index efea9d7..beb97df 100644 --- a/checkers/Twitch.py +++ b/checkers/Twitch.py @@ -12,28 +12,26 @@ logger = logging.getLogger(__name__) logger.setLevel(Constants.SASSBOT_LOG_LEVEL) -def isModelOnline(twitchChannelName): +def isModelOnline(twitchChannelName: str): + twitchChannelName = twitchChannelName.lower() title = "placeholder twitch title" tempThumbUrl = '' isOnline = False icon = Constants.defaultIcon try: - page = requests.get(f'https://www.twitch.tv/{twitchChannelName}') + tempThumbUrl = f'https://static-cdn.jtvnw.net/previews-ttv/live_user_{twitchChannelName}-640x360.jpg' + thumbUrlReq = requests.get(tempThumbUrl,allow_redirects=True) time.sleep(1) - soup = BeautifulSoup(page.content, "html.parser") - twitchJson = getTwitchJson(soup) - if twitchJson: - title = twitchJson['@graph'][0]['description'] - tempThumbUrl = twitchJson['@graph'][0]['thumbnailUrl'][2] + if tempThumbUrl == thumbUrlReq.url: + isOnline = True + page = requests.get(f'https://www.twitch.tv/{twitchChannelName}') + time.sleep(1) + soup = BeautifulSoup(page.content, "html.parser") + title = getTitle(soup) reticon = getIcon(soup) if reticon: icon = reticon - thumbUrlReq = requests.get(tempThumbUrl,allow_redirects=True) - time.sleep(1) - isOnlineJson = twitchJson['@graph'][0]['publication']['isLiveBroadcast'] - if isOnlineJson and tempThumbUrl == thumbUrlReq.url: - tempThumbUrl = tempThumbUrl + "?" + str(int(time.time())) - isOnline = True + tempThumbUrl = tempThumbUrl + "?" + str(int(time.time())) except requests.exceptions.ConnectTimeout: logger.warning("connection timed out to Twitch. Bot detection or rate limited?") except requests.exceptions.SSLError: @@ -41,15 +39,6 @@ def isModelOnline(twitchChannelName): thumbUrl = GetThumbnail(tempThumbUrl, Constants.twitchThumbnail) return isOnline, title, thumbUrl, icon -def getTwitchJson(soup): - twitchJson = 0 - try: - twitchJson = soup.find_all("script", type="application/ld+json") - twitchJson = json.loads(twitchJson[0].text) - except IndexError: - pass - return twitchJson - def getIcon(soup): icon = 0 try: @@ -57,3 +46,11 @@ def getIcon(soup): except IndexError: pass return icon + +def getTitle(soup): + title = "placeholder twitch title" + try: + title = soup.find("meta", property="og:description")['content'] + except IndexError: + pass + return title diff --git a/utils/NoDriverBrowserCreator.py b/utils/NoDriverBrowserCreator.py index e4548a4..90e12f2 100644 --- a/utils/NoDriverBrowserCreator.py +++ b/utils/NoDriverBrowserCreator.py @@ -58,11 +58,15 @@ async def GetBrowser(proxy=""): browser = await uc.start(sandbox=toSandbox, headless=toHeadless, browser_args=[f'--proxy-server={proxy}','--mute-audio','--disable-3d-apis','--disable-dev-shm-usage','--disable-gpu','--disable-blink-features=AutomationControlled'], - retries = Constants.NODRIVER_BROWSER_CONNECT_RETRIES) + retries = Constants.NODRIVER_BROWSER_CONNECT_RETRIES, + user_data_dir="/ndTemp" + ) else: browser = await uc.start(sandbox=toSandbox, headless=toHeadless, - retries = Constants.NODRIVER_BROWSER_CONNECT_RETRIES) + retries = Constants.NODRIVER_BROWSER_CONNECT_RETRIES, + user_data_dir="/ndTemp" + ) except Exception as e: logger.warning(f"error creating browser in GetBrowser: {e}") await asyncio.sleep(1 * Constants.NODRIVER_WAIT_MULTIPLIER) diff --git a/utils/StaticMethods.py b/utils/StaticMethods.py index f9a551c..813093b 100644 --- a/utils/StaticMethods.py +++ b/utils/StaticMethods.py @@ -265,8 +265,8 @@ def rebootServer() -> None: os.system('reboot') def safeRebootServer() -> None: - time.sleep(300) logger.warning("Scheduled restart is happening.\nSleeping for 300 seconds before restart, in case something goes horribly wrong") + time.sleep(300) rebootServer() def GetThumbnail(tempThumbUrl, constantsThumbnail):