mirror of
https://github.com/fHDHR/fHDHR_NextPVR.git
synced 2025-12-06 13:06:59 -05:00
Reconfigure /watch to /auto
This commit is contained in:
parent
1d6c6d9354
commit
4b78e912e5
@ -69,11 +69,11 @@ class HDHR_Hub():
|
|||||||
def get_channels_m3u(self, base_url):
|
def get_channels_m3u(self, base_url):
|
||||||
return self.m3u.get_channels_m3u(base_url)
|
return self.m3u.get_channels_m3u(base_url)
|
||||||
|
|
||||||
def get_stream_info(self, request_args):
|
def get_stream_info(self, stream_args):
|
||||||
return self.watch.get_stream_info(request_args)
|
return self.watch.get_stream_info(stream_args)
|
||||||
|
|
||||||
def get_stream(self, channel_id, method, channelUri, content_type, duration):
|
def get_stream(self, stream_args):
|
||||||
return self.watch.get_stream(channel_id, method, channelUri, content_type, duration)
|
return self.watch.get_stream(stream_args)
|
||||||
|
|
||||||
|
|
||||||
hdhr = HDHR_Hub()
|
hdhr = HDHR_Hub()
|
||||||
@ -174,31 +174,17 @@ class HDHR_HTTP_Server():
|
|||||||
|
|
||||||
@app.route('/auto/<channel>')
|
@app.route('/auto/<channel>')
|
||||||
def auto(channel):
|
def auto(channel):
|
||||||
request_args = {
|
stream_args = {
|
||||||
"channel": channel.replace('v', ''),
|
"channel": channel.replace('v', ''),
|
||||||
"method": hdhr.config.dict["fhdhr"]["stream_type"],
|
"method": request.args.get('method', default=hdhr.config.dict["fhdhr"]["stream_type"], type=str),
|
||||||
"duration": request.args.get('duration', default=0, type=int),
|
"duration": request.args.get('duration', default=0, type=int),
|
||||||
}
|
}
|
||||||
channel_id = request_args["channel"]
|
stream_args = hdhr.get_stream_info(stream_args)
|
||||||
method, channelUri, content_type, duration = hdhr.get_stream_info(request_args)
|
if stream_args["channelUri"]:
|
||||||
if channelUri:
|
if stream_args["method"] == "direct":
|
||||||
if method == "direct":
|
return Response(hdhr.get_stream(stream_args), content_type=stream_args["content_type"], direct_passthrough=True)
|
||||||
return Response(hdhr.get_stream(channel_id, method, channelUri, content_type, duration), content_type=content_type, direct_passthrough=True)
|
elif stream_args["method"] == "ffmpeg":
|
||||||
elif method == "ffmpeg":
|
return Response(stream_with_context(hdhr.get_stream(stream_args)), mimetype="video/mpeg")
|
||||||
return Response(stream_with_context(hdhr.get_stream(channel_id, method, channelUri, content_type, duration)), mimetype="video/mpeg")
|
|
||||||
abort(503)
|
|
||||||
|
|
||||||
@app.route('/watch', methods=['GET'])
|
|
||||||
def watch():
|
|
||||||
if 'method' in list(request.args.keys()) and 'channel' in list(request.args.keys()):
|
|
||||||
channel_id = str(request.args["channel"])
|
|
||||||
method = str(request.args["method"])
|
|
||||||
method, channelUri, content_type, duration = hdhr.get_stream_info(request.args)
|
|
||||||
if channelUri:
|
|
||||||
if method == "direct":
|
|
||||||
return Response(hdhr.get_stream(channel_id, method, channelUri, content_type, duration), content_type=content_type, direct_passthrough=True)
|
|
||||||
elif method == "ffmpeg":
|
|
||||||
return Response(stream_with_context(hdhr.get_stream(channel_id, method, channelUri, content_type, duration)), mimetype="video/mpeg")
|
|
||||||
abort(503)
|
abort(503)
|
||||||
|
|
||||||
@app.route('/lineup.post', methods=['POST'])
|
@app.route('/lineup.post', methods=['POST'])
|
||||||
|
|||||||
@ -45,10 +45,9 @@ class channels_M3U():
|
|||||||
|
|
||||||
fakefile.write(
|
fakefile.write(
|
||||||
"%s\n" % (
|
"%s\n" % (
|
||||||
('%s%s/watch?method=%s&channel=%s' %
|
('%s%s/auto/v%s' %
|
||||||
("http://",
|
("http://",
|
||||||
base_url,
|
base_url,
|
||||||
self.config.dict["fhdhr"]["stream_type"],
|
|
||||||
str(channel['number'])))
|
str(channel['number'])))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@ -13,20 +13,20 @@ class WatchStream():
|
|||||||
self.tuners = tuners
|
self.tuners = tuners
|
||||||
self.web = fHDHR.tools.WebReq()
|
self.web = fHDHR.tools.WebReq()
|
||||||
|
|
||||||
def direct_stream(self, channel_id, method, channelUri, content_type, duration):
|
def direct_stream(self, stream_args):
|
||||||
|
|
||||||
chunksize = int(self.tuners.config.dict["direct_stream"]['chunksize'])
|
chunksize = int(self.tuners.config.dict["direct_stream"]['chunksize'])
|
||||||
|
|
||||||
if not duration == 0:
|
if not stream_args["duration"] == 0:
|
||||||
duration += time.time()
|
stream_args["duration"] += time.time()
|
||||||
|
|
||||||
req = self.web.session.get(channelUri, stream=True)
|
req = self.web.session.get(stream_args["channelUri"], stream=True)
|
||||||
|
|
||||||
def generate():
|
def generate():
|
||||||
try:
|
try:
|
||||||
for chunk in req.iter_content(chunk_size=chunksize):
|
for chunk in req.iter_content(chunk_size=chunksize):
|
||||||
|
|
||||||
if not duration == 0 and not time.time() < duration:
|
if not stream_args["duration"] == 0 and not time.time() < stream_args["duration"]:
|
||||||
req.close()
|
req.close()
|
||||||
print("Requested Duration Expired.")
|
print("Requested Duration Expired.")
|
||||||
break
|
break
|
||||||
@ -40,12 +40,12 @@ class WatchStream():
|
|||||||
|
|
||||||
return generate()
|
return generate()
|
||||||
|
|
||||||
def ffmpeg_stream(self, channel_id, method, channelUri, content_type, duration):
|
def ffmpeg_stream(self, stream_args):
|
||||||
|
|
||||||
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"],
|
||||||
"-i", channelUri,
|
"-i", stream_args["channelUri"],
|
||||||
"-c", "copy",
|
"-c", "copy",
|
||||||
"-f", "mpegts",
|
"-f", "mpegts",
|
||||||
"-nostats", "-hide_banner",
|
"-nostats", "-hide_banner",
|
||||||
@ -53,8 +53,8 @@ class WatchStream():
|
|||||||
"pipe:stdout"
|
"pipe:stdout"
|
||||||
]
|
]
|
||||||
|
|
||||||
if not duration == 0:
|
if not stream_args["duration"] == 0:
|
||||||
duration += time.time()
|
stream_args["duration"] += time.time()
|
||||||
|
|
||||||
ffmpeg_proc = subprocess.Popen(ffmpeg_command, stdout=subprocess.PIPE)
|
ffmpeg_proc = subprocess.Popen(ffmpeg_command, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ class WatchStream():
|
|||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
if not duration == 0 and not time.time() < duration:
|
if not stream_args["duration"] == 0 and not time.time() < stream_args["duration"]:
|
||||||
ffmpeg_proc.terminate()
|
ffmpeg_proc.terminate()
|
||||||
ffmpeg_proc.communicate()
|
ffmpeg_proc.communicate()
|
||||||
print("Requested Duration Expired.")
|
print("Requested Duration Expired.")
|
||||||
@ -88,33 +88,30 @@ class WatchStream():
|
|||||||
|
|
||||||
return generate()
|
return generate()
|
||||||
|
|
||||||
def get_stream(self, channel_id, method, channelUri, content_type, duration):
|
def get_stream(self, stream_args):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.tuners.tuner_grab()
|
self.tuners.tuner_grab()
|
||||||
except TunerError:
|
except TunerError:
|
||||||
print("A " + method + " stream request for channel " +
|
print("A " + stream_args["method"] + " stream request for channel " +
|
||||||
str(channel_id) + " was rejected do to a lack of available tuners.")
|
str(stream_args["channel"]) + " was rejected do to a lack of available tuners.")
|
||||||
return
|
return
|
||||||
|
|
||||||
print("Attempting a " + method + " stream request for channel " + str(channel_id))
|
print("Attempting a " + stream_args["method"] + " stream request for channel " + str(stream_args["channel"]))
|
||||||
|
|
||||||
if method == "ffmpeg":
|
if stream_args["method"] == "ffmpeg":
|
||||||
return self.ffmpeg_stream(channel_id, method, channelUri, content_type, duration)
|
return self.ffmpeg_stream(stream_args)
|
||||||
elif method == "direct":
|
elif stream_args["method"] == "direct":
|
||||||
return self.direct_stream(channel_id, method, channelUri, content_type, duration)
|
return self.direct_stream(stream_args)
|
||||||
|
|
||||||
def get_stream_info(self, request_args):
|
def get_stream_info(self, stream_args):
|
||||||
|
|
||||||
method = str(request_args["method"])
|
stream_args["channelUri"] = self.origserv.get_channel_stream(str(stream_args["channel"]))
|
||||||
channel_id = str(request_args["channel"])
|
if not stream_args["channelUri"]:
|
||||||
duration = int(request_args["duration"])
|
print("Could not Obtain Channel Stream.")
|
||||||
|
stream_args["content_type"] = "video/mpeg"
|
||||||
|
else:
|
||||||
|
channelUri_headers = self.web.session.head(stream_args["channelUri"]).headers
|
||||||
|
stream_args["content_type"] = channelUri_headers['Content-Type']
|
||||||
|
|
||||||
channelUri = self.origserv.get_channel_stream(channel_id)
|
return stream_args
|
||||||
if not channelUri:
|
|
||||||
return None, None, None, None
|
|
||||||
|
|
||||||
channelUri_headers = self.web.session.head(channelUri).headers
|
|
||||||
content_type = channelUri_headers['Content-Type']
|
|
||||||
|
|
||||||
return method, channelUri, content_type, duration
|
|
||||||
|
|||||||
@ -13,7 +13,6 @@ class OriginService():
|
|||||||
if not self.serviceorigin.login():
|
if not self.serviceorigin.login():
|
||||||
raise LoginError(self.config.dict["main"]["servicename"] + " Login Failed.")
|
raise LoginError(self.config.dict["main"]["servicename"] + " Login Failed.")
|
||||||
|
|
||||||
self.streamtype = self.config.dict["fhdhr"]["stream_type"]
|
|
||||||
self.channels = {
|
self.channels = {
|
||||||
"list": {},
|
"list": {},
|
||||||
"list_updated": None,
|
"list_updated": None,
|
||||||
@ -47,10 +46,9 @@ class OriginService():
|
|||||||
return channel_list
|
return channel_list
|
||||||
|
|
||||||
def get_fhdhr_stream_url(self, base_url, channel):
|
def get_fhdhr_stream_url(self, base_url, channel):
|
||||||
return ('%s%s/watch?method=%s&channel=%s' %
|
return ('%s%s/auto/v%s' %
|
||||||
("http://",
|
("http://",
|
||||||
base_url,
|
base_url,
|
||||||
self.streamtype,
|
|
||||||
channel['number']))
|
channel['number']))
|
||||||
|
|
||||||
def get_station_list(self, base_url):
|
def get_station_list(self, base_url):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user