Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions plugin.video.nrk/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ def live_resolve(id):
media_url = nrktv.get_playback_url("/playback/manifest/channel/%s" % id);
if (media_url):
success = True
li = ListItem(path=media_url)
setResolvedUrl(plugin.handle, success, li)
is_helper = inputstreamhelper.Helper('hls')
if is_helper.check_inputstream():
playitem = ListItem(path=media_url)
playitem.setProperty('inputstream', is_helper.inputstream_addon)
setResolvedUrl(plugin.handle, success, playitem)


def set_stream_details(item, li):
Expand Down Expand Up @@ -247,16 +250,17 @@ def play(video_id):
if not urls:
raise Exception("could not find any streams")
url = urls[0] if len(urls) == 1 else "stack://" + ' , '.join(urls)

xbmcplugin.setResolvedUrl(plugin.handle, True, ListItem(path=url))
playitem = ListItem(path=url)
subtitles = subs.get_subtitles(video_id)
if subtitles:
playitem.setSubtitles(list(subtitles.values()))
xbmcplugin.setResolvedUrl(plugin.handle, True, listitem=playitem)
player = xbmc.Player()
subtitle = subs.get_subtitles(video_id)
if subtitle:
if subtitles:
# Wait for stream to start
start_time = time.time()
while not player.isPlaying() and time.time() - start_time < 10:
time.sleep(1.)
player.setSubtitles(subtitle)
if xbmcaddon.Addon().getSetting('showsubtitles') != '1':
player.showSubtitles(False)

Expand Down
3 changes: 2 additions & 1 deletion plugin.video.nrk/addon.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.nrk"
name="NRK Nett-TV"
version="4.9.2"
version="4.10.0"
provider-name="takoi+a99b">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests" version="1.0.4"/>
<import addon="script.module.routing" version="0.1.0"/>
<import addon="script.module.inputstreamhelper" version="0.8.0" />
</requires>
<extension point="xbmc.python.pluginsource" library="main.py">
<provides>video</provides>
Expand Down
4 changes: 4 additions & 0 deletions plugin.video.nrk/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[B]4.10.0[/B]
- add subtitles to VOD stream
- enable rewinding in live stream and add subtitles to live stream

[B]4.9.2[/B]
- use hardcoded username to fix github action

Expand Down
2 changes: 1 addition & 1 deletion plugin.video.nrk/nrktv.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _get(path, params=''):
def get_playback_url(manifest_url):
playable = _get(manifest_url)['playable']
if playable:
return playable['assets'][0]['url']
return playable['assets'][0]['url'].replace("adap=small&", "")
else:
return None

Expand Down
56 changes: 27 additions & 29 deletions plugin.video.nrk/subs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,34 @@


def get_subtitles(video_id):
mediaelement_json = requests.get("https://psapi.nrk.no/playback/manifest/%s" % (video_id)).json()

if not mediaelement_json["playable"]['subtitles']:
mediaelement_json = requests.get("https://psapi.nrk.no/mediaelement/%s" % (video_id),
headers={
"Referer": "https://tv.nrk.no",
"Accept": "application/vnd.nrk.psapi+json; version=9; ludo-client=true; psapi=snapshot"
}).json()
if not mediaelement_json['playable']['parts']:
return None
ttml_sub_url = mediaelement_json["playable"]['subtitles'][0]['webVtt']
subs = requests.get(ttml_sub_url).text
if not subs:
subtitles = mediaelement_json['playable']['parts'][0].get('subtitles', None)
if not subtitles:
return None

content = _vtt_to_srt(subs)
try:
filename = os.path.join(xbmc.translatePath("special://temp"), 'nor.srt') # deprecated already in Kodi v19
except:
filename = os.path.join(xbmcvfs.translatePath("special://temp"), 'nor.srt') # 4.8.0 https://github.com/xbmc/xbmc/pull/19301
with open(filename, 'w' ,encoding='utf8') as f:
f.write(content)
return filename


def _vtt_to_srt(content):
return content

def _str_to_time(txt):
p = txt.split(':')
try:
ms = float(p[2])
except ValueError:
ms = 0
return int(p[0]) * 3600 + int(p[1]) * 60 + ms
subs = {}
for sub in subtitles:
subs[sub['type']] = sub['webVtt']
if mediaelement_json['streamingMode'] != "onDemand":
return subs
for sub_type in subs.keys():
vtt_sub_url = subs[sub_type]
content = requests.get(vtt_sub_url).text
if not content:
continue
filename = "nor.sdh.vtt" if sub_type == 'ttv' else "%s.vtt" % sub_type
try:
filename = os.path.join(xbmcvfs.translatePath("special://temp"), filename) # 4.8.0 https://github.com/xbmc/xbmc/pull/19301
except:
filename = os.path.join(xbmc.translatePath("special://temp"), filename) # deprecated already in Kodi v19
with open(filename, 'w' ,encoding='utf8') as f:
f.write(content)
subs[sub_type] = filename
return subs


def _time_to_str(time):
return '%02d:%02d:%02d,%03d' % (time / 3600, (time % 3600) / 60, time % 60, (time % 1) * 1000)