commit f1e23b4a48519e065415955df80a44d6aae5ccda Author: Roy Olav Purser Date: Fri Apr 30 10:49:10 2021 +0200 first commit diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..ba62b6a --- /dev/null +++ b/.drone.yml @@ -0,0 +1,16 @@ +kind: pipeline +name: default + +steps: +- name: docker + image: plugins/docker + settings: + username: + from_secret: docker_username + password: + from_secret: docker_password + repo: + from_secret: docker_repo + tags: + - latest + - ${DRONE_BUILD_FINISHED} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f7c89ce --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM alpine:edge as base +RUN ["apk", "add", "--no-cache", "streamlink"] +RUN ["mkdir", "/app"] +COPY ["stream.py", "/app/stream.py"] + +FROM scratch +COPY --from=base / / + +USER 1444:1444 +ENTRYPOINT ["/app/stream.py"] diff --git a/stream.py b/stream.py new file mode 100755 index 0000000..c41e231 --- /dev/null +++ b/stream.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +import streamlink +import tornado.web +import tornado.routing +import urllib.parse + +providers = {} +providers["nrk"] = "https://tv.nrk.no" +providers["svt"] = "https://svtplay.se" +providers["youtube"] = "https://youtu.be" + +class MainHandler(tornado.web.RequestHandler): + def get(self): + provider = self.get_query_argument("provider", None) + if provider in providers: + endpoint = None + src = providers[provider] + self.request.uri + try: + endpoint = streamlink.streams(src).get("best").url + except Exception as e: + self.write(str(e)) + else: + self.redirect(endpoint, status=303) +try: + app_web = tornado.web.Application([(tornado.routing.AnyMatches(), MainHandler)]) + app_web.listen(8080) + tornado.ioloop.IOLoop.current().start() +except KeyboardInterrupt: + print() +