1
0
mirror of https://github.com/fHDHR/fHDHR_NextPVR.git synced 2025-12-06 13:36:59 -05:00

Better Streaming

This commit is contained in:
deathbybandaid 2020-10-09 11:15:56 -04:00
parent 85a28642cc
commit fffd2f73e1
2 changed files with 33 additions and 16 deletions

View File

@ -65,8 +65,11 @@ class HDHR_Hub():
def get_image(self, request_args):
return self.images.get_image(request_args)
def get_stream(self, request_args):
return self.watch.get_stream(request_args)
def get_stream_info(self, request_args):
return self.watch.get_stream_info(request_args)
def get_stream(self, channel_id, method, channelUri, content_type):
return self.watch.get_stream(channel_id, method, channelUri, content_type)
hdhr = HDHR_Hub()
@ -148,9 +151,15 @@ class HDHR_HTTP_Server():
@app.route('/watch', methods=['GET'])
def watch():
if 'method' in list(request.args.keys()) and 'channel' in list(request.args.keys()):
return Response(stream_with_context(hdhr.get_stream(request.args)))
else:
abort(503)
channel_id = str(request.args["channel"])
method = str(request.args["method"])
method, channelUri, content_type = hdhr.get_stream_info(request.args)
if channelUri:
if method == "direct":
return Response(hdhr.get_stream(channel_id, method, channelUri, content_type), content_type=content_type, direct_passthrough=True)
elif method == "ffmpeg":
return Response(stream_with_context(hdhr.get_stream(channel_id, method, channelUri, content_type)), mimetype="video/mpeg")
abort(503)
@app.route('/lineup.post', methods=['POST'])
def lineup_post():

View File

@ -12,7 +12,7 @@ class WatchStream():
self.tuners = tuners
self.web = fHDHR.tools.WebReq()
def direct_stream(self, channelUri):
def direct_stream(self, channel_id, method, channelUri, content_type):
chunksize = int(self.tuners.config.dict["direct_stream"]['chunksize'])
req = self.web.session.get(channelUri, stream=True)
@ -28,7 +28,7 @@ class WatchStream():
return generate()
def ffmpeg_stream(self, channelUri):
def ffmpeg_stream(self, channel_id, method, channelUri, content_type):
bytes_per_read = int(self.config.dict["ffmpeg"]["bytes_per_read"])
ffmpeg_command = [self.config.dict["ffmpeg"]["ffmpeg_path"],
@ -61,10 +61,7 @@ class WatchStream():
self.tuners.tuner_close()
return generate()
def get_stream(self, request_args):
method = str(request_args["method"])
channel_id = str(request_args["channel"])
def get_stream(self, channel_id, method, channelUri, content_type):
try:
self.tuners.tuner_grab()
@ -75,10 +72,21 @@ class WatchStream():
print("Attempting a " + method + " stream request for channel " + str(channel_id))
channelUri = self.origserv.get_channel_stream(channel_id)
# print("Proxy URL determined as " + str(channelUri))
if method == "ffmpeg":
return self.ffmpeg_stream(channelUri)
return self.ffmpeg_stream(channel_id, method, channelUri, content_type)
elif method == "direct":
return self.direct_stream(channelUri)
return self.direct_stream(channel_id, method, channelUri, content_type)
def get_stream_info(self, request_args):
method = str(request_args["method"])
channel_id = str(request_args["channel"])
channelUri = self.origserv.get_channel_stream(channel_id)
if not channelUri:
return None, None, None
channelUri_headers = self.web.session.head(channelUri).headers
content_type = channelUri_headers['Content-Type']
return method, channelUri, content_type