Skip to content

Instantly share code, notes, and snippets.

@fifty-six
Created July 10, 2020 19:17
Show Gist options
  • Save fifty-six/ea7b31944a08b5ac65bf6832b2b634de to your computer and use it in GitHub Desktop.
Save fifty-six/ea7b31944a08b5ac65bf6832b2b634de to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from twitch import Helix
from requests import post
from time import sleep
from subprocess import call
import os
import creds
def main():
USER = "ax2u"
use_shell = False
ffox = ["firefox"]
# On windows, firefox isn't in the path so we do 'start firefox' (cmd builtin)
if os.name == "nt":
use_shell = True
ffox = ["start"] + ffox
oauth_token = post(
f"https://id.twitch.tv/oauth2/token"
f"?client_id={creds.client_id}"
f"&client_secret={creds.client_secret}"
f"&grant_type=client_credentials"
).json()["access_token"]
helix = Helix(creds.client_id, creds.client_secret, bearer_token=oauth_token)
opened_tab = False
while True:
# re-request
usr = helix.user(USER)
# note the ?b=b
# I'm using "MuteLinks" (firefox addon) with the blacklist regex ".*twitch.tv/ax2u\?b=b"
# So if it's opened automatically, the tab will be muted.
# Not necessarily needed as twitch links start muted, but just in case.
live = usr.is_live
if live and not opened_tab:
call(ffox + ["-new-tab", f"https://twitch.tv/{USER}?b=b"], shell=use_shell)
# Prevent additional tabs from being opened.
opened_tab = True
elif not live:
# Reset the tab state so it'll open once they go live again.
opened_tab = False
sleep(8 * 60)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment