Skip to content

Commit

Permalink
Merge pull request #68 from aigjermo/fix-media-urls-leia
Browse files Browse the repository at this point in the history
Fix some failing media urls due to invalid response from psapi.
  • Loading branch information
tamland authored Nov 4, 2022
2 parents b608d86 + 668bb27 commit c7090a4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion nrktv.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,19 @@ def from_response(r):

media_urls = []
if 'mediaAssetsOnDemand' in r:
def format_path(part):
try:
bitrates = [str(x) for x in part['bitrates']]
return part['urlPattern'].format(
'i',
',' + ','.join(bitrates) + ',',
'master.m3u8')
except (KeyError, IndexError):
# Fall back to previous behavior
return part['hlsUrl']

parts = sorted(r['mediaAssetsOnDemand'], key=lambda x: x['part'])
media_urls = [part['hlsUrl'] for part in parts]
media_urls = [format_path(part) for part in parts]

images = _image_url_key_standardize(r.get('image', {}).get('webImages', None))
duration = _duration_to_seconds(r.get('duration', 0))
Expand Down

0 comments on commit c7090a4

Please sign in to comment.