Mercurial > code > home > repos > video
changeset 0:3f2da406c788
start
author | drewp@bigasterisk.com |
---|---|
date | Tue, 21 Jul 2020 23:28:04 -0700 |
parents | |
children | f036a4955ad2 |
files | Dockerfile Dockerfile.vids index.html package.json requirements.txt rollup.config.js serv.n3 src/index.ts tasks.py tsconfig.json video.py |
diffstat | 11 files changed, 340 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Dockerfile Tue Jul 21 23:28:04 2020 -0700 @@ -0,0 +1,16 @@ +FROM bang6:5000/base_x86 + +WORKDIR /opt + +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata vim + +COPY requirements.txt ./ +RUN pip3 install --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -r requirements.txt +RUN pip3 install -U 'https://github.com/drewp/cyclone/archive/python3.zip?v3' + +COPY shaka-player/dist/shaka-player.compiled.* ./shaka-player/dist/ + +COPY *.py *.html *.css *.js *.n3 ./ +COPY build/* build/ + +CMD [ "python3", "./video.py" ]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Dockerfile.vids Tue Jul 21 23:28:04 2020 -0700 @@ -0,0 +1,8 @@ +FROM bang6:5000/base_x86 + +WORKDIR /opt + +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata vim +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y webfs + +CMD [ "webfsd", "-Fp", "9054", "-r", "/vids/" ]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/index.html Tue Jul 21 23:28:04 2020 -0700 @@ -0,0 +1,23 @@ +<!DOCTYPE html> +<html> + <head> + <script src="shaka-player/dist/shaka-player.compiled.debug.js"></script> + <script type="module" src="build/bundle.js"></script> + <style> + body { + margin: 0; + height: 100vh; + background: radial-gradient( + ellipse at center, + #162c4a 0%, + #0c2236 36%, + #020f16 100% + ); + } + + </style> + </head> + <body> + <video-page></video-page> + </body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/package.json Tue Jul 21 23:28:04 2020 -0700 @@ -0,0 +1,31 @@ +{ + "name": "video", + "version": "0.0.1", + "scripts": { + "build": "rollup -c", + "build_forever": "rollup -cw", + "test": "jest", + "test_forever": "jest --watch" + }, + "dependencies": { + "lit-element": "^2.2.1" + }, + "devDependencies": { + "@rollup/plugin-commonjs": "^11.0.2", + "@rollup/plugin-node-resolve": "^7.1.1", + "@rollup/plugin-replace": "^2.3.1", + "@types/jest": "^25.1.2", + "@types/rollup-plugin-postcss": "^2.0.0", + "jest": "^25.1.0", + "node-globals": "^0.1.5", + "rollup": "^1.31.1", + "rollup-plugin-node-builtins": "^2.1.2", + "rollup-plugin-postcss": "^2.0.6", + "rollup-plugin-terser": "^5.2.0", + "rollup-plugin-typescript2": "^0.26.0", + "stylus": "^0.54.7", + "ts-jest": "^25.2.0", + "tslib": "^1.10.0", + "typescript": "^3.7.5" + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/requirements.txt Tue Jul 21 23:28:04 2020 -0700 @@ -0,0 +1,11 @@ +cyclone +docopt +pymongo==3.10.1 +python-dateutil==2.8.1 + +cycloneerr +patchablegraph==0.11.0 +rdfdb==0.21.0 +standardservice==0.6.0 + +git+http://github.com/drewp/scales.git@448d59fb491b7631877528e7695a93553bfaaa93#egg=scales
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rollup.config.js Tue Jul 21 23:28:04 2020 -0700 @@ -0,0 +1,40 @@ +import builtins from "rollup-plugin-node-builtins"; +import commonjs from "@rollup/plugin-commonjs"; +import postcss from "rollup-plugin-postcss"; +import resolve from "@rollup/plugin-node-resolve"; +import typescript from "rollup-plugin-typescript2"; +import { terser } from "rollup-plugin-terser"; + +const workaround_jsonld_module_system_picker = "process = {version: '1.0.0'}"; +const workaround_some_browser_detector = "global = window"; + +const workaround_jsonld_expand_issue = { + namedExports: { + "../streamed-graph/node_modules/jsonld/lib/index.js": ["expand"], // fixes "expand is not exported by node_modules/jsonld/lib/index.js" + }, +}; + +export default [ + { + input: "src/index.ts", + output: { + file: "build/bundle.js", + format: "esm", + intro: `const ${workaround_some_browser_detector}, ${workaround_jsonld_module_system_picker};`, + }, + + plugins: [ + builtins(), + resolve({ + extensions: [".js", ".ts"], + browser: true, + }), + typescript(), + postcss({ + inject: false, + }), + commonjs(workaround_jsonld_expand_issue), + //terser() // 1500 -> 500kB, but slow. put it in the docker builder only. + ], + }, +];
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serv.n3 Tue Jul 21 23:28:04 2020 -0700 @@ -0,0 +1,40 @@ +@prefix : <http://bigasterisk.com/ns/serv#> . +@prefix auth: <http://bigasterisk.com/ns/serv/auth#> . +@prefix serv: <http://bigasterisk.com/services/> . + + +serv:video_image a :DockerImage; + :internalPort 9053; + :prodDockerFlags ("--net=host"); + :localRunDockerFlags ( + "-v" "`pwd`:/opt" + "-v" "/home/drewp/vidcap:/home/drewp/vidcap" + ); + :localRunCmdline ("python3" "video.py" "-v"); + :dockerFile "Dockerfile" +. + +serv:video_files_image a :DockerImage; + :internalPort 9054; + :prodDockerFlags ( + "-v" "/my/serv/video/vids:/vids" + ); + :dockerFile "Dockerfile.vids" +. + + +serv:video a :Service, :NpmPackage; + :image serv:video_image; + :port 9053; + :path "/video/"; + :openid auth:admin; + :serverHost "bang"; +. + +serv:video_files a :Service; + :port 9054; + :image serv:video_files_image; + :path "/vids/"; + :openid auth:admin; + :serverHost "bang"; +.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/index.ts Tue Jul 21 23:28:04 2020 -0700 @@ -0,0 +1,69 @@ +import { + LitElement, + html, + customElement, + property, + unsafeCSS, + PropertyValues, +} from "lit-element"; + +const shaka = (window as any).shaka! as any; + +@customElement("video-page") +export class VideoPage extends LitElement { + render() { + return html` + <video-section + title="Henry Sugar" + manifest="/vids/henry-sugar/manifest.mpd" + ></video-section> + <video-section + title="Henry Sugar bloopers" + manifest="/vids/henry-sugar-bloopers/manifest.mpd" + ></video-section> + `; + } +} + +@customElement("video-section") +export class VideoSection extends LitElement { + @property({ type: String }) manifest: string | undefined; + @property({ type: String }) title: string = "(unknown)"; + render() { + return html` + <style> + section { + background: #ffffff14; + display: inline-block; + padding: 10px; + color: white; + } + </style> + <section> + <h1>${this.title}</h1> + <video id="video" width="720" height="480" controls></video> + </section> + `; + } + + updated(changedProperties: Map<string, any>) { + if (!this.manifest) { + return; + } + var video = this.shadowRoot!.querySelector("#video"); + var player = new shaka.Player(video); + + player.addEventListener("error", onErrorEvent); + player.load(this.manifest).catch(onError); + function onErrorEvent(event: any) { + const error = event.detail; + onError(event.detail); + } + + function onError(error: any) { + console.error("Error code", error.code, "object", error); + } + } +} + +document.addEventListener("DOMContentLoaded", shaka.polyfill.installAll);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tasks.py Tue Jul 21 23:28:04 2020 -0700 @@ -0,0 +1,8 @@ +from invoke import task, Collection + +import sys +sys.path.append('/my/proj/release') +from serv_tasks import serv_tasks + +ns = Collection() +serv_tasks(ns, 'serv.n3', 'video')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tsconfig.json Tue Jul 21 23:28:04 2020 -0700 @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "strict": true, + "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "strictPropertyInitialization": true, + "alwaysStrict": true, + + "types": [], + + "module": "ES6", + "target": "ES6", + "moduleResolution": "node", + "sourceMap": true, + "declaration": true, + "experimentalDecorators": true, + "allowJs": true, + "esModuleInterop": true, + "traceResolution": true, + // "allowSyntheticDefaultImports": true, + // "rootDir": ".", + // "outDir": "./build", + "baseUrl": ".", + // "emitDecoratorMetadata": true, + "lib": [ "es6", "dom", "ES2019.Object" ], + }, + "include": ["src/**/*.ts"] + // "exclude": ["src/**/*.test.ts"] +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/video.py Tue Jul 21 23:28:04 2020 -0700 @@ -0,0 +1,61 @@ +import docopt + +from twisted.internet import reactor +import cyclone.httpserver +import cyclone.web +import requests + +from cycloneerr import PrettyErrorHandler +from patchablegraph import PatchableGraph, CycloneGraphEventsHandler, CycloneGraphHandler +from standardservice.logsetup import log, verboseLogging + + +def getLoginBar(request: cyclone.httpserver.HTTPRequest): + c = requests.get('http://bang:9023/_loginBar', + headers={'Cookie': request.headers['cookie']}) + return c.content + + +class Transaction(PrettyErrorHandler, cyclone.web.RequestHandler): + def get(self): + self.render('transaction.html', + txn='data', + loginBar=getLoginBar(self.request)) + + +def main(): + args = docopt.docopt(''' +Usage: + video.py [options] + +Options: + -v, --verbose more logging +''') + verboseLogging(args['--verbose']) + + graph = PatchableGraph() + + class Application(cyclone.web.Application): + def __init__(self): + handlers = [ + (r"/()", cyclone.web.StaticFileHandler, {'path': '.', 'default_filename': 'index.html'}), + (r'/build/(bundle\.js)', cyclone.web.StaticFileHandler, {'path': './build/'}), + (r'/shaka-player/dist/(.*)', cyclone.web.StaticFileHandler, {'path': './shaka-player/dist/'}), + (r'/transaction', Transaction), + (r'/graph/video', CycloneGraphHandler, {'masterGraph': graph}), + (r'/graph/video/events', CycloneGraphEventsHandler, {'masterGraph': graph}), + ] + cyclone.web.Application.__init__( + self, + handlers, + graph=graph, + debug=args['--verbose'], + template_path='.', + ) + + reactor.listenTCP(9053, Application(), interface='::') + reactor.run() + + +if __name__ == '__main__': + main()