fHDHR_XUMO/fHDHR/origin/origin_channels.py
deathbybandaid 77d3f554a2 test
2020-12-06 11:51:34 -05:00

125 lines
4.0 KiB
Python

import m3u8
class OriginChannels():
def __init__(self, fhdhr, origin):
self.fhdhr = fhdhr
self.origin = origin
self.base_api = 'https://valencia-app-mds.xumo.com/v2/'
def get_channels(self):
channel_list = []
channel_json_path = 'channels/list/%s.json?geoId=%s' % (self.origin.geoLST, self.origin.geoID)
channel_json_url = self.base_api + channel_json_path
api_json = self.fhdhr.web.session.get(channel_json_url).json()
for channel_dict in api_json['channel']['item']:
if channel_dict["properties"]["has_vod"] == "false":
clean_station_item = {
"name": channel_dict["title"],
"callsign": channel_dict["callsign"],
"number": str(channel_dict["number"]),
"id": str(channel_dict["guid"]["value"]),
"thumbnail": "https://image.xumo.com/v1/channels/channel/%s/512x512.png?type=color_onBlack" % str(channel_dict["guid"]["value"])
}
channel_list.append(clean_station_item)
return channel_list
def get_channel_stream(self, chandict):
try:
stream_json_path = 'channels/channel/%s/onnow.json' % str(chandict["origin_id"])
stream_id_url = self.base_api + stream_json_path
stream_id = self.fhdhr.web.session.get(stream_id_url).json()["id"]
stream_id_info_path = 'assets/asset/%s.json?f=title&f=providers&f=descriptions&f=runtime&f=availableSince' % str(stream_id)
stream_id_info_url = self.base_api + stream_id_info_path
stream_id_info_json = self.fhdhr.web.session.get(stream_id_info_url).json()
streamurls = []
for provider in stream_id_info_json["providers"]:
for source in provider["sources"]:
streamurls.append(source["uri"])
streamurl = streamurls[0]
except KeyError:
return None
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
"""
{
"title": "GameSpot",
"description": "GameSpot is the world's leading source for gaming.",
"guid": {
"value": "9999216",
"isPermaLink": false
},
"number": 300,
"callsign": "XGAME",
"genre": [
{
"value": "Entertainment",
"genreId": 1
}
],
"properties": {
"hybrid_type": "popular",
"is_live": "true",
"brand_color": "rgba(238,64,53,1)",
"has_vod": "true"
}
}
{
"title": "CBS News",
"description": "",
"guid": {
"value": "9999158",
"isPermaLink": false
},
"number": 125,
"callsign": "XCBSNWS",
"genre": [
{
"value": "News",
"genreId": 13
}
],
"properties": {
"simulcast_only": "true",
"hybrid_type": "promoted",
"is_live": "true",
"brand_color": "rgba(48,129,180,1)",
"has_vod": "false",
"is_simulcast": "true",
"has_discontinuity": "true"
}
}
"""