Skip to content

Instantly share code, notes, and snippets.

@lepz0r
Last active August 9, 2020 17:57
Show Gist options
  • Save lepz0r/b2f1f731e141b79ac048bfb6c1fb48d8 to your computer and use it in GitHub Desktop.
Save lepz0r/b2f1f731e141b79ac048bfb6c1fb48d8 to your computer and use it in GitHub Desktop.
Open a YouTube livestream chat
#!/bin/python
import re
import argparse
import subprocess
try:
import sys
from PyQt5.Qt import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QApplication
except ImportError:
pyqtwebengine_installed=0
parser = argparse.ArgumentParser(description='Open YouTube Chat.')
parser.add_argument('-u','--url', dest='url',help='URL')
parser.add_argument('-b','--browser', dest='browser',help='Browser to open the URL',default='internal')
args = parser.parse_args()
video_id=re.search("(?:(?<=(watch\?v=))|(?<=(youtu\.be\/)))(([0-z]*))",args.url)
chat_url="https://www.youtube.com/live_chat?is_popout=1&v="+video_id.group()
if args.browser == 'internal':
app=QApplication(sys.argv)
web=QWebEngineView()
web.load(QUrl(chat_url))
web.show()
sys.exit(app.exec_())
else:
subprocess.run([args.browser, chat_url])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment