follow redirect
This commit is contained in:
parent
76a2947e7e
commit
bbca0d2fd7
21
stream.py
21
stream.py
@ -2,25 +2,38 @@
|
|||||||
import streamlink
|
import streamlink
|
||||||
import tornado.web
|
import tornado.web
|
||||||
import tornado.routing
|
import tornado.routing
|
||||||
|
import requests
|
||||||
|
|
||||||
providers = {}
|
providers = {}
|
||||||
providers["nrk"] = "https://tv.nrk.no"
|
providers["nrk"] = "https://tv.nrk.no"
|
||||||
providers["svt"] = "https://svtplay.se"
|
providers["svt"] = "https://svtplay.se"
|
||||||
providers["youtube"] = "https://youtu.be"
|
providers["youtube"] = "https://youtu.be"
|
||||||
|
providers["twitch"] = "https://twitch.tv"
|
||||||
|
|
||||||
class MainHandler(tornado.web.RequestHandler):
|
class MainHandler(tornado.web.RequestHandler):
|
||||||
def get(self):
|
def get(self):
|
||||||
provider = self.get_query_argument("provider", None)
|
provider = self.get_query_argument("provider", None)
|
||||||
if provider is not None and provider in providers:
|
|
||||||
endpoint = None
|
endpoint = None
|
||||||
|
if provider is not None and provider in providers.keys():
|
||||||
src = providers[provider] + self.request.uri
|
src = providers[provider] + self.request.uri
|
||||||
try:
|
try:
|
||||||
stream = streamlink.streams(src).get("best")
|
resp = requests.get(src)
|
||||||
if stream is not None:
|
if resp is not None:
|
||||||
|
src = resp.url
|
||||||
|
except Exception as e:
|
||||||
|
self.write(e)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
streams = streamlink.streams(src)
|
||||||
|
for key in reversed(streams):
|
||||||
|
stream = streams.get(key)
|
||||||
|
if hasattr(stream, "url"):
|
||||||
endpoint = stream.url
|
endpoint = stream.url
|
||||||
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.write(str(e))
|
self.write(str(e))
|
||||||
else:
|
return
|
||||||
if endpoint is None:
|
if endpoint is None:
|
||||||
self.write("stream not found")
|
self.write("stream not found")
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user