stream-api/stream.py
2021-04-30 10:49:10 +02:00

31 lines
909 B
Python
Executable File

#!/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()