Skip to content

Commit

Permalink
twitch checker improvements, nodriver temp folder improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Bombg committed Oct 19, 2024
1 parent 8b158e8 commit a901ad6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion DefaultConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
41 changes: 19 additions & 22 deletions checkers/Twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,45 @@
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:
logger.warning("SSL Error when attempting to connect to Twitch")
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:
icon = soup.find("meta", property="og:image")['content']
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
8 changes: 6 additions & 2 deletions utils/NoDriverBrowserCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion utils/StaticMethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a901ad6

Please sign in to comment.