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

Merge pull request #21 from deathbybandaid/dev

Better Streaming
This commit is contained in:
Deathbybandaid 2020-10-09 14:30:38 -04:00 committed by GitHub
commit 10db19aa6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 16 deletions

View File

@ -65,8 +65,11 @@ class HDHR_Hub():
def get_image(self, request_args): def get_image(self, request_args):
return self.images.get_image(request_args) return self.images.get_image(request_args)
def get_stream(self, request_args): def get_stream_info(self, request_args):
return self.watch.get_stream(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() hdhr = HDHR_Hub()
@ -148,9 +151,15 @@ class HDHR_HTTP_Server():
@app.route('/watch', methods=['GET']) @app.route('/watch', methods=['GET'])
def watch(): def watch():
if 'method' in list(request.args.keys()) and 'channel' in list(request.args.keys()): if 'method' in list(request.args.keys()) and 'channel' in list(request.args.keys()):
return Response(stream_with_context(hdhr.get_stream(request.args))) channel_id = str(request.args["channel"])
else: method = str(request.args["method"])
abort(503) 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']) @app.route('/lineup.post', methods=['POST'])
def lineup_post(): def lineup_post():

View File

@ -12,7 +12,7 @@ class WatchStream():
self.tuners = tuners self.tuners = tuners
self.web = fHDHR.tools.WebReq() 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']) chunksize = int(self.tuners.config.dict["direct_stream"]['chunksize'])
req = self.web.session.get(channelUri, stream=True) req = self.web.session.get(channelUri, stream=True)
@ -28,7 +28,7 @@ class WatchStream():
return generate() 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"]) bytes_per_read = int(self.config.dict["ffmpeg"]["bytes_per_read"])
ffmpeg_command = [self.config.dict["ffmpeg"]["ffmpeg_path"], ffmpeg_command = [self.config.dict["ffmpeg"]["ffmpeg_path"],
@ -61,10 +61,7 @@ class WatchStream():
self.tuners.tuner_close() self.tuners.tuner_close()
return generate() return generate()
def get_stream(self, request_args): def get_stream(self, channel_id, method, channelUri, content_type):
method = str(request_args["method"])
channel_id = str(request_args["channel"])
try: try:
self.tuners.tuner_grab() self.tuners.tuner_grab()
@ -75,10 +72,21 @@ class WatchStream():
print("Attempting a " + method + " stream request for channel " + str(channel_id)) 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": if method == "ffmpeg":
return self.ffmpeg_stream(channelUri) return self.ffmpeg_stream(channel_id, method, channelUri, content_type)
elif method == "direct": 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