Skip to content

Commit

Permalink
Now always using the highest bitrate audio stream
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjomckay committed Jun 14, 2020
1 parent 6667e8d commit d958177
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,30 @@ def mode_episode(pid):
programme = requests.get('https://www.bbc.co.uk/programmes/' + pid + '.json')
programme_json = programme.json()["programme"]

url = None
picked_url = None

for version in programme_json["versions"]:
playlist = requests.get(
'https://open.live.bbc.co.uk/mediaselector/6/select/version/2.0/mediaset/iptv-all/vpid/' + version["pid"] + '/format/json')
playlist_json = playlist.json()

if "media" not in playlist_json:
# TODO
continue

url = playlist_json["media"][0]["connection"][1]["href"]
# Filter by only audio items, and order with the highest bitrate first
audio_items = [item for item in playlist_json['media'] if item['kind'] == 'audio']
audio_items.sort(key=lambda x: x['bitrate'], reverse=True)

play_item = xbmcgui.ListItem(path=url)
xbmc.log('Found {0} audio items for the programme version {1}'.format(len(audio_items), version['pid']), level=xbmc.LOGNOTICE)

# Pick the first stream available for the highest bitrate item
picked_stream = audio_items[0]
picked_url = picked_stream["connection"][1]["href"]

xbmc.log('Picked the {0} stream with the bitrate {1}'.format(picked_stream['encoding'], picked_stream['bitrate']), level=xbmc.LOGNOTICE)

play_item = xbmcgui.ListItem(path=picked_url)
play_item.setArt({
'thumb': 'https://ichef.bbci.co.uk/images/ic/480xn/' + programme_json["image"]["pid"] + '.jpg',
'icon': 'https://ichef.bbci.co.uk/images/ic/480xn/' + programme_json["image"]["pid"] + '.jpg'
Expand All @@ -148,9 +159,9 @@ def mode_episode(pid):
'comment': programme_json["short_synopsis"]
})

xbmc.Player().play(url, play_item)
xbmc.Player().play(picked_url, play_item)

if url is None:
if picked_url is None:
xbmcgui.Dialog().notification(__addonname__, "Episode not available to stream", icon=xbmcgui.NOTIFICATION_ERROR)


Expand Down
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.audio.bbcsounds" name="BBC Sounds" version="0.0.4" provider-name="jonjomckay">
<addon id="plugin.audio.bbcsounds" name="BBC Sounds" version="0.0.5" provider-name="jonjomckay">
<requires>
<import addon="xbmc.python" version="2.20.0" />
<import addon="script.module.beautifulsoup4" version="4.3.2" />
Expand Down

0 comments on commit d958177

Please sign in to comment.