91 lines
3.4 KiB
Python
91 lines
3.4 KiB
Python
import m3u8
|
|
|
|
|
|
class OriginChannels():
|
|
|
|
def __init__(self, fhdhr, origin):
|
|
self.fhdhr = fhdhr
|
|
self.origin = origin
|
|
|
|
self.base_api_url = "https://ott-gateway-stirr.sinclairstoryline.com/api/rest/v3"
|
|
self.base_station_url = "https://ott-stationselection.sinclairstoryline.com/stationSelectionByAllStates"
|
|
|
|
"https://ott-gateway-stirr.sinclairstoryline.com/api/rest/v3/channels/stirr?station=abc3340"
|
|
|
|
"https://ott-gateway-stirr.sinclairstoryline.com/api/rest/v3/status/40b80f75-2efc-49af-813b-2a674e69ea59"
|
|
|
|
"https://ott-gateway-stirr.sinclairstoryline.com/api/rest/v3/program/stirr/ott/"
|
|
|
|
def get_channels(self):
|
|
|
|
station_locations = ["national", "abc3340"]
|
|
|
|
station_by_state_opn = self.fhdhr.web.session.get(self.base_station_url)
|
|
states_list = station_by_state_opn.json()
|
|
|
|
for state_uuid in states_list['page']:
|
|
if state_uuid["pageComponentUuid"].startswith("nearyou-"):
|
|
state_url = state_uuid["content"]
|
|
|
|
state_url_req = self.fhdhr.web.session.get(state_url)
|
|
state_url_json = state_url_req.json()
|
|
print(state_url_json["rss"]["channel"]["pagecomponent"]["component"][0].keys())
|
|
|
|
return []
|
|
|
|
chan_list_url = "%s/channels/stirr?station=national" % (self.base_api_url)
|
|
chan_list_urlopn = self.fhdhr.web.session.get(chan_list_url)
|
|
stirr_chan_list = chan_list_urlopn.json()
|
|
|
|
channel_list = []
|
|
# chanindex = 0
|
|
for channel_dict in stirr_chan_list["channel"]:
|
|
|
|
# chanindex += 1
|
|
|
|
chan_item_url = "%s/status/%s" % (self.base_api_url, str(channel_dict["id"]))
|
|
chan_item_urlopn = self.fhdhr.web.session.get(chan_item_url)
|
|
stirr_chan_item = chan_item_urlopn.json()
|
|
|
|
try:
|
|
thumbnail = channel_dict["icon"]["src"].split("?")[0]
|
|
except TypeError:
|
|
thumbnail = None
|
|
|
|
clean_station_item = {
|
|
"name": stirr_chan_item['rss']["channel"]["title"],
|
|
"callsign": channel_dict["display-name"],
|
|
# "number": chanindex,
|
|
"id": str(channel_dict["id"]),
|
|
"thumbnail": thumbnail
|
|
}
|
|
channel_list.append(clean_station_item)
|
|
|
|
return channel_list
|
|
|
|
def get_channel_stream(self, chandict):
|
|
chan_item_url = "%s/status/%s" % (self.base_api_url, str(chandict["origin_id"]))
|
|
chan_item_urlopn = self.fhdhr.web.session.get(chan_item_url)
|
|
stirr_chan_item = chan_item_urlopn.json()
|
|
streamurl = stirr_chan_item['rss']["channel"]["item"]["link"]
|
|
if self.fhdhr.config.dict["origin"]["force_best"]:
|
|
streamurl = self.m3u8_beststream(streamurl)
|
|
return streamurl
|
|
|
|
def m3u8_beststream(self, m3u8_url):
|
|
bestStream = None
|
|
videoUrlM3u = m3u8.load(m3u8_url)
|
|
if not videoUrlM3u.is_variant:
|
|
return m3u8_url
|
|
|
|
for videoStream in videoUrlM3u.playlists:
|
|
if not bestStream:
|
|
bestStream = videoStream
|
|
elif videoStream.stream_info.bandwidth > bestStream.stream_info.bandwidth:
|
|
bestStream = videoStream
|
|
|
|
if not bestStream:
|
|
return bestStream.absolute_uri
|
|
else:
|
|
return m3u8_url
|