Skip to content

Commit

Permalink
fix guid data for OTT-only channels
Browse files Browse the repository at this point in the history
  • Loading branch information
micahg committed Nov 5, 2023
1 parent 74399c3 commit 7292493
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions plugin.video.cbc/addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.cbc"
name="Canadian Broadcasting Corp (CBC)"
version="4.0.16+matrix.1"
version="4.0.17+matrix.1"
provider-name="micahg,t1m,smf007,oshanrube">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
Expand All @@ -28,6 +28,6 @@
<forum>https://forum.kodi.tv/showthread.php?tid=328421</forum>
<website>https://watch.cbc.ca/</website>
<source>https://github.com/micahg/plugin.video.cbc</source>
<news>- Enable new authentication system</news>
<news>- Add schedule for CBC Comedy Channel</news>
</extension>
</addon>
7 changes: 6 additions & 1 deletion plugin.video.cbc/resources/lib/cbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# http_client.HTTPConnection.debuglevel = 1

CALLSIGN = 'cbc$callSign'
CHANNEL_GUID = 'guid'
API_KEY = '3f4beddd-2061-49b0-ae80-6f1f2ed65b37'
SCOPES = 'openid '\
'offline_access '\
Expand Down Expand Up @@ -262,7 +263,11 @@ def get_image(self, item):
@staticmethod
def get_callsign(item):
"""Get the callsign for a channel."""
return item[CALLSIGN] if CALLSIGN in item else None
if CALLSIGN in item:
return item[CALLSIGN]
if CHANNEL_GUID in item:
return item[CHANNEL_GUID]
return None

@staticmethod
def get_labels(item):
Expand Down
30 changes: 19 additions & 11 deletions plugin.video.cbc/resources/lib/epg.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@

# Y/M/D
GUIDE_URL_FMT = 'https://www.cbc.ca/programguide/daily/{}/cbc_television'
NEWSNET_URL_FMT = 'https://www.cbc.ca/programguide/daily/{}/cbc_news_network'

# This is a combination of actual callsigns (NN for newsnet) and guid values
# for over-the-top-only services. No doubt, someone will come back here some
# day and have questions. When this was written, channels in LIST_URL (from
# livechannels.py) had callsigns, guids or both (and maybe neither). Where
# we don't have a callsign, get_callsign (from cbc.py) uses a guid instead.
# Also important is that there needs to be symmetry between get_iptv_epg and
# get_iptv_channels (from livechannels.py) because of how iptvmanager works.
SPECIAL_GUIDES = {
'NN': 'https://www.cbc.ca/programguide/daily/{}/cbc_news_network',
'2265331267748': 'https://www.cbc.ca/programguide/daily/{}/cbc_comedy_fast',
'2076284995790': 'https://www.cbc.ca/programguide/daily/{}/cbc_news_explore',
}

def get_iptv_epg():
"""Get the EPG Data."""
Expand All @@ -32,17 +43,13 @@ def get_iptv_epg():
log('Starting EPG update')
with futures.ThreadPoolExecutor(max_workers=20) as executor:
for callsign, guide_id in channel_map.items():

# determine if we're dealing with news network
newsnetwork = callsign == 'NN'

# add empty array of programs
epg_data[callsign] = []

# submit three concurrent requests for a days guide data
for day_offset in [0, 1, 2]:
dttm = datetime.now() + timedelta(days=day_offset)
future = executor.submit(get_channel_data, dttm, guide_id, newsnetwork)
future = executor.submit(get_channel_data, dttm, guide_id, callsign)
future_to_callsign[future] = callsign

for future in futures.as_completed(future_to_callsign):
Expand All @@ -58,7 +65,7 @@ def map_channel_ids(unblocked):
soup = BeautifulSoup(data, features="html.parser")
select = soup.find('select', id="selectlocation-tv")
options = select.find_all('option')
channel_map = {'NN': None}
channel_map = { sign: None for sign in SPECIAL_GUIDES.keys()}
for option in options:
title = option.get_text()
value = option['value']
Expand All @@ -68,10 +75,11 @@ def map_channel_ids(unblocked):
return channel_map


def call_guide_url(dttm, location=None, newsnetwork=False):
def call_guide_url(dttm, location=None, callsign=None):
"""Call the guide URL and return the response body."""
date_str = dttm.strftime('%Y/%m/%d')
url = (NEWSNET_URL_FMT if newsnetwork else GUIDE_URL_FMT).format(date_str)
url_fmt = SPECIAL_GUIDES[callsign] if callsign in SPECIAL_GUIDES else GUIDE_URL_FMT
url = url_fmt.format(date_str)
cookies = {}
if location is not None:
cookies['pgTvLocation'] = location
Expand All @@ -82,10 +90,10 @@ def call_guide_url(dttm, location=None, newsnetwork=False):
return resp.content


def get_channel_data(dttm, channel, newsnetwork=False):
def get_channel_data(dttm, channel, callsign):
"""Get channel program data for a specified date."""
epg_data = []
data = call_guide_url(dttm, channel, newsnetwork)
data = call_guide_url(dttm, channel, callsign)
soup = BeautifulSoup(data, features="html.parser")

select = soup.find('table', id="sched-table").find('tbody')
Expand Down
2 changes: 0 additions & 2 deletions plugin.video.cbc/resources/lib/livechannels.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
LIST_URL = 'https://tpfeed.cbc.ca/f/ExhSPC/t_t3UKJR6MAT?pretty=true&sort=pubDate%7Cdesc'
LIST_ELEMENT = 'entries'



class LiveChannels:
"""Class for live channels."""

Expand Down

0 comments on commit 7292493

Please sign in to comment.