#!/usr/bin/env python3
# Minimal HTTP server for the Cast CMA subsample-OOB POC.
# Serves poc.html plus any encrypted-media segments placed alongside it.
import http.server, socketserver, os, sys

PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8080
os.chdir(os.path.dirname(os.path.abspath(__file__)))

class H(http.server.SimpleHTTPRequestHandler):
    extensions_map = {
        **http.server.SimpleHTTPRequestHandler.extensions_map,
        '.mp4': 'video/mp4', '.m4s': 'video/iso.segment',
        '.html': 'text/html', '.js': 'application/javascript',
    }

socketserver.TCPServer.allow_reuse_address = True
with socketserver.TCPServer(('127.0.0.1', PORT), H) as httpd:
    print(f'serving on http://127.0.0.1:{PORT}/poc.html', flush=True)
    httpd.serve_forever()
