fHDHR_XUMO/fHDHR/origin/origin_channels.py
deathbybandaid 0d527a109d test
2020-12-06 10:25:11 -05:00

99 lines
3.9 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?sort=hybrid&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']:
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/300x300.png?type=color_onBlack" % str(channel_dict["guid"]["value"])
}
channel_list.append(clean_station_item)
return channel_list
def get_channel_stream(self, chandict):
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]
# 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
"""
{
'id': 'XM0IFYLJ0RMD0X',
'contentType': 'SIMULCAST',
'title': 'CBS News',
'descriptions': {
'medium': "CBSN offers original, up-to-the-minute coverage of national and global stories with dynamic on-demand video content, including video from CBS News' extensive archives."
},
'availableSince': 'Tue, 20 Dec 2016 23:25:37 +0000',
'providers': [
{
'title': 'CBSN',
'id': 42,
'color': 'rgba(48,129,180,1)',
'sources': [
{
'uri': 'https://dai.google.com/linear/hls/event/Sid4xiTQTkCT1SLu6rjUSQ/master.m3u8?iu=/8264/vaw-can/ott/cbsnews_xumo&description_url=https://xumo.tv&ppid=&url=com.xumo.app&rdid=&idtype=&is_lat=&msid=&an=com.xumo.app',
'bitrate': 3009,
'width': 1280,
'height': 720,
'lang': 'en',
'produces': 'application/x-mpegURL'
}
],
'sunrise': 'Thu, 1 Jan 1970 00:00:01 +0000',
'sunset': 'Tue, 19 Jan 2038 03:14:07 +0000'
}
],
'type': 'Asset'
}
"""