--- /dev/null
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+pip-wheel-metadata/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py,cover
+.hypothesis/
+.pytest_cache/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+.python-version
+
+# pipenv
+# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+# However, in case of collaboration, if having platform-specific dependencies or dependencies
+# having no cross-platform support, pipenv may install dependencies that don't work, or not
+# install all needed dependencies.
+#Pipfile.lock
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
--- /dev/null
+BSD Zero Clause License
+
+Copyright (c) 2022 Georgios Atheridis <georgios@atheridis.com>
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
--- /dev/null
+Random Twitch Clip Viewer
+-------------------------
+
+Requirements:
+
+uvicorn[standard]
+fastapi
+python-dotenv
+
+or
+$ pip install -r "requirements.txt"
+-------------------------
+
+Install the packages
+$ python -m pip install python-dotenv fastapi uvicorn[standard]
+
+create a .env file in the project's root and add the following
+BROADCASTER_ID=00000000
+CLIENT_ID="yourclientidgoeshere"
+OAUTH="youroauthtokengoeshere"
+
+then if using locally, run
+$ uvicorn server:app --host 127.0.0.1 --port 8888
+
+open client.html in your browser, or open it using OBS.
+
+
+If running it on a server, change the IP value in client.html
+to your server's IP and run
+$ uvicorn server:app --host 0.0.0.0 --port 8888
--- /dev/null
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>clips</title>
+ <style>
+body {
+ background: rgba(0, 0, 0, 0);
+}
+
+#video {
+ position: absolute;
+ top:0px;
+ left:0px;
+ width: 100%;
+ height: 100%;
+}
+ </style>
+ </head>
+ <body>
+ <video id='video' autoplay >
+ <source src="" type="video/mp4">
+ Your browser does not support the video tag.
+ </video>
+ <script type='text/javascript'>
+ function httpGet()
+ {
+ var xmlHttp = new XMLHttpRequest();
+ xmlHttp.open( "GET", "http://127.0.0.1:8888/clip", false ); // false for synchronous request
+ xmlHttp.send( null );
+ return xmlHttp.responseText.slice(1, -1);
+ }
+
+ function play() {
+ document.getElementById('video').setAttribute('src', httpGet());
+ }
+
+ document.getElementById('video').addEventListener('ended',play);
+
+ play();
+ </script>
+ </body>
+</html>
--- /dev/null
+anyio==3.6.2
+certifi==2022.12.7
+charset-normalizer==2.1.1
+click==8.1.3
+fastapi==0.88.0
+h11==0.14.0
+httptools==0.5.0
+idna==3.4
+pydantic==1.10.2
+python-dotenv==0.21.0
+PyYAML==6.0
+requests==2.28.1
+sniffio==1.3.0
+starlette==0.22.0
+typing_extensions==4.4.0
+urllib3==1.26.13
+uvicorn==0.20.0
+uvloop==0.17.0
+watchfiles==0.18.1
+websockets==10.4
--- /dev/null
+import os
+import random
+import requests
+import dotenv
+from fastapi import FastAPI
+from fastapi.middleware.cors import CORSMiddleware
+
+dotenv.load_dotenv()
+
+broadcaster_id = os.getenv("BROADCASTER_ID")
+client_id = os.getenv("CLIENT_ID")
+oauth = os.getenv("OAUTH")
+
+if not (broadcaster_id and client_id and oauth):
+ exit(1)
+
+response = requests.get(
+ "https://api.twitch.tv/helix/clips",
+ params={
+ "broadcaster_id": broadcaster_id,
+ "first": 100,
+ },
+ headers={
+ "Authorization": f"Bearer {oauth}",
+ "Client-Id": client_id,
+ }
+)
+
+if response.status_code != 200:
+ exit(1)
+
+data = response.json()["data"]
+for d in data:
+ d["video_mp4"] = \
+ d["thumbnail_url"][:d["thumbnail_url"].find("-preview")] + ".mp4"
+
+app = FastAPI()
+
+origins = ["*"]
+
+app.add_middleware(
+ CORSMiddleware,
+ allow_origins=origins,
+ allow_credentials=True,
+ allow_methods=["*"],
+ allow_headers=["*"],
+)
+
+
+@app.get("/clip")
+async def root():
+ clip = random.choice(data)["video_mp4"]
+ return clip