fHDHR_STIRR/origin/origin_channels.py
deathbybandaid 0bd569286b test
2020-12-15 10:54:15 -05:00

196 lines
12 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"
"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):
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 = []
for channel_dict in stirr_chan_list["channel"]:
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": str(channel_dict["number"]),
"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
"""
{
'rss': {
'xmlns:sinclair': 'sinclair',
'xmlns:media': 'http://search.yahoo.com/mrss/',
'channel': {
'item': {
'link': 'https://dai.google.com/linear/hls/event/4aD5IJf0QgKUJwPbq2fngg/master.m3u8',
'category': 'OTTFeed',
'guid': {
'isPermaLink': 'false',
'content': '0cf15df7-1dbc-4dac-bc8d-867e8ab3d3cf'
},
'pubDate': '2020-12-15T09:42:17+00:00',
'media:content': {
'sinclair:ad_preroll': 'https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&iu=/4756/OTT_Gateway/TC&vpos=preroll&url=http%3A%2F%2Fstirr-mrss-adapter.sinclairstoryline.com%2Fapi%2Frest%2Fv3%2Fstatus%2F0cf15df7-1dbc-4dac-bc8d-867e8ab3d3cf&description_url=http%3A%2F%2Fstirr-mrss-adapter.sinclairstoryline.com%2Fapi%2Frest%2Fv3%2Fstatus%2F0cf15df7-1dbc-4dac-bc8d-867e8ab3d3cf',
'sinclair:ad_postroll': 'https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&iu=/4756/OTT_Gateway/TC&vpos=postroll&url=http%3A%2F%2Fstirr-mrss-adapter.sinclairstoryline.com%2Fapi%2Frest%2Fv3%2Fstatus%2F0cf15df7-1dbc-4dac-bc8d-867e8ab3d3cf&description_url=http%3A%2F%2Fstirr-mrss-adapter.sinclairstoryline.com%2Fapi%2Frest%2Fv3%2Fstatus%2F0cf15df7-1dbc-4dac-bc8d-867e8ab3d3cf',
'sinclair:attributes': {
'sinclair:ads': {
'sinclair:daiAdParams': {
'description_url': 'https://tennischanneleverywhere.com'
}
}
},
'sinclair:status': {
'sinclair:displayText': '',
'state': '',
'reason': ''
},
'media:title': {
'content': 'Real People'
},
'media:description': {
'content': 'Featuring a school for bagpipers, motorized bar stools, and Disco Sally.'
},
'media:thumbnail': [
{
'width': '1920',
'height': '1080',
'url': 'https://komonews.com/resources/media2/16x9/full/1920/center/90/015a7576-6fc7-425d-9937-408d11f74b08-full16x9_undefinede31e5e1dde2644f98bafc75e3d583ecarealpeopleseason33vod75dcdbf745aa4e8683a08f48700a367depisode23teaser.jpg?cb=cfcd208495d565ef66e7dff9f98764da'
},
{
'width': '1920',
'height': '640',
'url': 'https://komonews.com/resources/media2/3x1/full/1920/center/90/015a7576-6fc7-425d-9937-408d11f74b08-full3x1_undefinede31e5e1dde2644f98bafc75e3d583ecarealpeopleseason33vod75dcdbf745aa4e8683a08f48700a367depisode23teaser.jpg?cb=cfcd208495d565ef66e7dff9f98764da'
},
{
'width': '1440',
'height': '1440',
'url': 'https://komonews.com/resources/media2/1x1/full/1440/center/90/015a7576-6fc7-425d-9937-408d11f74b08-full1x1_undefinede31e5e1dde2644f98bafc75e3d583ecarealpeopleseason33vod75dcdbf745aa4e8683a08f48700a367depisode23teaser.jpg?cb=cfcd208495d565ef66e7dff9f98764da'
},
{
'width': '899',
'height': '500',
'url': 'https://komonews.com/resources/media2/16x9/full/899/center/90/015a7576-6fc7-425d-9937-408d11f74b08-full16x9_undefinede31e5e1dde2644f98bafc75e3d583ecarealpeopleseason33vod75dcdbf745aa4e8683a08f48700a367depisode23teaser.jpg?cb=cfcd208495d565ef66e7dff9f98764da'
},
{
'width': '548',
'height': '308',
'url': 'https://komonews.com/resources/media2/16x9/full/548/center/90/015a7576-6fc7-425d-9937-408d11f74b08-full16x9_undefinede31e5e1dde2644f98bafc75e3d583ecarealpeopleseason33vod75dcdbf745aa4e8683a08f48700a367depisode23teaser.jpg?cb=cfcd208495d565ef66e7dff9f98764da'
},
{
'width': '375',
'height': '563',
'url': 'https://komonews.com/resources/media2/2x3/full/375/center/90/015a7576-6fc7-425d-9937-408d11f74b08-full2x3_undefinede31e5e1dde2644f98bafc75e3d583ecarealpeopleseason33vod75dcdbf745aa4e8683a08f48700a367depisode23teaser.jpg?cb=cfcd208495d565ef66e7dff9f98764da'
},
{
'width': '448',
'height': '252',
'url': 'https://komonews.com/resources/media2/16x9/full/448/center/90/015a7576-6fc7-425d-9937-408d11f74b08-full16x9_undefinede31e5e1dde2644f98bafc75e3d583ecarealpeopleseason33vod75dcdbf745aa4e8683a08f48700a367depisode23teaser.jpg?cb=cfcd208495d565ef66e7dff9f98764da'
},
{
'width': '410',
'height': '615',
'url': 'https://komonews.com/resources/media2/2x3/full/410/center/90/015a7576-6fc7-425d-9937-408d11f74b08-full2x3_undefinede31e5e1dde2644f98bafc75e3d583ecarealpeopleseason33vod75dcdbf745aa4e8683a08f48700a367depisode23teaser.jpg?cb=cfcd208495d565ef66e7dff9f98764da'
},
{
'width': '473',
'height': '267',
'url': 'https://komonews.com/resources/media2/16x9/full/473/center/90/015a7576-6fc7-425d-9937-408d11f74b08-full16x9_undefinede31e5e1dde2644f98bafc75e3d583ecarealpeopleseason33vod75dcdbf745aa4e8683a08f48700a367depisode23teaser.jpg?cb=cfcd208495d565ef66e7dff9f98764da'
},
{
'width': '375',
'height': '211',
'url': 'https://komonews.com/resources/media2/16x9/full/375/center/90/015a7576-6fc7-425d-9937-408d11f74b08-full16x9_undefinede31e5e1dde2644f98bafc75e3d583ecarealpeopleseason33vod75dcdbf745aa4e8683a08f48700a367depisode23teaser.jpg?cb=cfcd208495d565ef66e7dff9f98764da'
},
{
'width': '219',
'height': '123',
'url': 'https://komonews.com/resources/media2/16x9/full/219/center/90/015a7576-6fc7-425d-9937-408d11f74b08-full16x9_undefinede31e5e1dde2644f98bafc75e3d583ecarealpeopleseason33vod75dcdbf745aa4e8683a08f48700a367depisode23teaser.jpg?cb=cfcd208495d565ef66e7dff9f98764da'
},
{
'width': '600',
'height': '338',
'url': 'https://komonews.com/resources/media2/16x9/full/600/center/90/015a7576-6fc7-425d-9937-408d11f74b08-full16x9_undefinede31e5e1dde2644f98bafc75e3d583ecarealpeopleseason33vod75dcdbf745aa4e8683a08f48700a367depisode23teaser.jpg?cb=cfcd208495d565ef66e7dff9f98764da'
}
],
'sinclair:logo': {
'width': '119',
'height': '39',
'text': 'On Demand',
'url': 'https://komonews.com/resources/media2/3x1/full/119/center/90/44e3adac-d9ed-4f62-b8e7-3bc5d09d94cc-small3x1_STIRR_LOGO_0220_STIRRCity_1920x1080_EPG.png?cb=eccbc87e4b5ce2fe28308fd9f2a7baf3'
},
'medium': 'video',
'sinclair:ident': '0cf15df7-1dbc-4dac-bc8d-867e8ab3d3cf',
'expression': 'nonstop',
'type': 'application/x-mpegURL',
'url': 'https://dai.google.com/linear/hls/event/4aD5IJf0QgKUJwPbq2fngg/master.m3u8',
'duration': '0',
'sinclair:isLive': 'false',
'sinclair:isLiveProgram': 'false',
'sinclair:url': 'dai://4aD5IJf0QgKUJwPbq2fngg'
}
},
'id': '0cf15df7-1dbc-4dac-bc8d-867e8ab3d3cf',
'link': 'https://ott-gateway-stirr.sinclairstoryline.com/api/rest/v3/status/0cf15df7-1dbc-4dac-bc8d-867e8ab3d3cf',
'description': 'Watch the latest breaking news and weather from the National region. Powered by WJLA',
'title': 'STIRR | National'
},
'version': '2'}
}
"""