2021-04-30 08:49:10 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import streamlink
|
|
|
|
import tornado.web
|
|
|
|
import tornado.routing
|
|
|
|
|
|
|
|
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)
|
2021-04-30 09:20:00 +00:00
|
|
|
if provider is not None and provider in providers:
|
2021-04-30 08:49:10 +00:00
|
|
|
endpoint = None
|
|
|
|
src = providers[provider] + self.request.uri
|
|
|
|
try:
|
2021-04-30 09:24:25 +00:00
|
|
|
stream = streamlink.streams(src).get("best")
|
|
|
|
if stream is not None:
|
|
|
|
endpoint = stream.url
|
2021-04-30 08:49:10 +00:00
|
|
|
except Exception as e:
|
|
|
|
self.write(str(e))
|
|
|
|
else:
|
2021-04-30 09:26:21 +00:00
|
|
|
if endpoint is None:
|
|
|
|
self.write("stream not found")
|
|
|
|
else:
|
|
|
|
self.redirect(endpoint, status=303)
|
2021-04-30 08:49:10 +00:00
|
|
|
try:
|
|
|
|
app_web = tornado.web.Application([(tornado.routing.AnyMatches(), MainHandler)])
|
|
|
|
app_web.listen(8080)
|
|
|
|
tornado.ioloop.IOLoop.current().start()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print()
|
|
|
|
|