Skip to content

Instantly share code, notes, and snippets.

@bharadwaj6
Last active February 26, 2020 16:23
Show Gist options
  • Save bharadwaj6/e601e50d1bf19dd230aaadb4a64e3bfc to your computer and use it in GitHub Desktop.
Save bharadwaj6/e601e50d1bf19dd230aaadb4a64e3bfc to your computer and use it in GitHub Desktop.
Python streaming server to metastream your local videos with friends and family (https://getmetastream.com/)
from starlette.applications import Starlette
from starlette.responses import StreamingResponse, HTMLResponse
from starlette.routing import Route
from pathlib import Path
VIDEO_PATH = Path('videos')
def stream(request):
filename = request.path_params['filename']
return StreamingResponse(open(VIDEO_PATH / filename, 'rb'), media_type='video/mp4')
def homepage(request):
html_text = []
for file in VIDEO_PATH.iterdir():
streampath = "stream/{}".format(file.name)
html_text.append("<li><a href='{streampath}'>{filename}</a></li>".format(
streampath=streampath, filename=file.name
))
html_text = '<br />'.join(html_text)
return HTMLResponse(html_text)
routes = [
Route('/', endpoint=homepage),
Route('/stream/{filename}', endpoint=stream)
]
app = Starlette(debug=True, routes=routes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment