first commit

This commit is contained in:
Roy Olav Purser 2021-04-30 10:49:10 +02:00
commit f1e23b4a48
No known key found for this signature in database
GPG Key ID: 0BA77797F072BC52
4 changed files with 57 additions and 0 deletions

16
.drone.yml Normal file
View File

@ -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}

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.pyc

10
Dockerfile Normal file
View File

@ -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"]

30
stream.py Executable file
View File

@ -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()