Skip to content

Commit

Permalink
Remove hard dependency on inputstream.adaptive.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainTK committed May 5, 2017
1 parent cc6ea22 commit e7aca5e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion addon.xml
Expand Up @@ -3,7 +3,6 @@
<requires>
<import addon="xbmc.python" version="2.25.0"/>
<import addon="script.module.requests" version="2.7.0"/>
<import addon="inputstream.adaptive" version="1.0.6"/>
</requires>
<extension point="xbmc.python.pluginsource" library="default.py">
<provides>audio video</provides>
Expand Down
11 changes: 11 additions & 0 deletions resources/lib/ipwww_common.py
Expand Up @@ -316,6 +316,17 @@ def AddMenuEntry(name, url, mode, iconimage, description, subtitles_url, aired=N
"""Adds a new line to the Kodi list of playables.
It is used in multiple ways in the plugin, which are distinguished by modes.
"""
# If DASH is selected as stream_protocol, we need to check if inputstream.adaptive
# is available and the version is correct.
if int(ADDON.getSetting('stream_protocol')) == 0:
if xbmc.getCondVisibility("System.HasAddon(inputstream.adaptive)"):
if (xbmcaddon.Addon(id='inputstream.adaptive').getAddonInfo('version') < "1.0.6"):
# Version is smaller than 1.0.6, fall back to HLS
ADDON.setSetting('stream_protocol','1')
else:
# inputstream.adaptive is not available, fall back to HLS
ADDON.setSetting('stream_protocol','1')

if not iconimage:
iconimage="DefaultFolder.png"
listitem_url = (sys.argv[0] + "?url=" + utf8_quote_plus(url) + "&mode=" + str(mode) +
Expand Down
2 changes: 1 addition & 1 deletion resources/settings.xml
Expand Up @@ -43,7 +43,7 @@
<setting label="30103" type="lsep" />
<setting id="streams_autoplay" label="30205" type="bool" default="true" />
<setting label="30101" type="lsep" />
<setting id="stream_protocol" label="30212" type="enum" values="DASH|HLS" default="0" />
<setting id="stream_protocol" label="30212" type="enum" values="DASH|HLS" default="1" />
<setting id="catchup_source" label="30210" type="enum" values="Any|Akamai|Limelight|Bidi" default="0" enable="true" />
<setting id="catchup_bitrate" label="30211" type="enum" values="Highest|0.8 Mbps|1.0 Mbps|1.5 Mbps|1.8 Mbps|2.4 Mbps|3.1 Mbps|5.5 Mbps" default="0" enable="eq(-4,true) + eq(-2,1)" />
<setting id="live_source" label="30220" type="enum" values="Any|Akamai|Limelight" default="0" enable="eq(-5,true)" />
Expand Down

13 comments on commit e7aca5e

@CaptainTK
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please test if this works with your various shortcut addons, @primaeval ?

In theory, whenever a new directory is created, it will check the availability of inputstream.adaptive, if stream_protocol is set to 0 (DASH). If it isn't available, or the version is too low, it will change the setting back to HLS.

I am not sure about the performance impact this has. It feels extremely slow since I introduced this patch, but this may also just be server load.

@primaeval
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's going to need another function to play the individual streams so that the inputstream.adaptive properties get added to the ListItem at the last minute before playing, just like PlayStream does in ipwww_video.py.

xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)

If you look at the normal Kodi favourites.xml there is only a link there not a complete ListItem.

<favourites>
    <favourite name="Bing - 37. Sparkle Magic" thumb="https://ichef.bbci.co.uk/images/ic/832x468/p027dlm3.jpg">PlayMedia(&quot;plugin://plugin.video.iplayerwww/?url=http%3A%2F%2Fwww.bbc.co.uk%2Fiplayer%2Fepisode%2Fb04kkc5t%2Fbing-37-sparkle-magic&amp;mode=202&amp;name=Bing+-+37.+Sparkle+Magic&amp;iconimage=https%3A%2F%2Fichef.bbci.co.uk%2Fimages%2Fic%2F832x468%2Fp027dlm3.jpg&amp;description=Sula+won%27t+let+Bing+join+in+with+her+game+of+sparkle+magic.&amp;subtitles_url=&amp;logged_in=False&quot;)</favourite>
</favourites>

inputstream.rtmp has done it the right way by listing the protocols as file name extensions
https://github.com/notspiff/inputstream.rtmp/blob/master/inputstream.rtmp/addon.xml.in
but inputstream.adaptive hasn't
https://github.com/peak3d/inputstream.adaptive/blob/master/inputstream.adaptive/addon.xml.in

If the link is to another mode= url for dash that uses the resolvedURL method with the inputstream.adaptive properties that would work fine for any shortcut: Favourites or otherwise.

It is a pain but that is the way it's been implemented so we have to move the mountain or move Mohammed.

@CaptainTK
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resetting it in PlayStream is not going to work. At that point of time we are no longer able to switch back to HLS. The best we could do at that point of time is to abort the playback.

If somebody created a shortcut to a DASH stream it would stick. However, if they attempt to create the directory item and then a shortcut, it will switch to HLS before creating the directory. Thus, the shortcut will also point to HLS.

@primaeval
Copy link
Contributor

@primaeval primaeval commented on e7aca5e May 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got confused with my addon where I just use the raw urls if autoplay is off.
As everything does go through PlayStream to play I think it should look at the stream url to work out the protocol. If it ends with mpd before the # suffix it can just set the inputstream.adaptive properties without looking at the Setting.
That should work as any shortcut or favourite link.
You could pass another parameter to PlayStream for the hls/dash/etc protocol if you really want to be sure it picks the right one, or make a PlayStreamDash.

@primaeval
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The individual links would probably best be called something that shows the protocol so it is obvious that if you disable inputstream.adaptive the link won't work any more. eg
BBC One - DASH Akamai https
or nicer.
In most of my addons I do a fuzzy channel match for the channel including number to word conversions so something like "Bbc1" will match "BBC One DASH" or "Channel 1. BBC 1 London". I ignore case and space.

@CaptainTK
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As everything does go through PlayStream to play I think it should look at the stream url to work out the protocol. If it ends with mpd before the # suffix it can just set the inputstream.adaptive properties without looking at the Setting.
That should work as any shortcut or favourite link.
You could pass another parameter to PlayStream for the hls/dash/etc protocol if you really want to be sure it picks the right one, or make a PlayStreamDash.

Problem is: IIRC, that does not work. If autoplay is on, the property to use inputstream.adaptive needs to be set for the directory/playable already. It can no longer be modified after the user clicks on the directory (or shortcut). That's why these properties also get set on a directory/item level qnd not just within PlayStream. The same issue blocks an automatic fallback for programmes which are not available as DASH streams.

@CaptainTK
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The individual links would probably best be called something that shows the protocol so it is obvious that if you disable inputstream.adaptive the link won't work any more. eg
BBC One - DASH Akamai https
or nicer.
In most of my addons I do a fuzzy channel match for the channel including number to word conversions so something like "Bbc1" will match "BBC One DASH" or "Channel 1. BBC 1 London". I ignore case and space.

I also tried that when experimenting with the automatic fallback. Something like returning an extra option or include a suffix in the name. Didn't work either, see last post.

The way Kodi invokes different players from addons is seriously f****d up at the moment.

@primaeval
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to think of a robust way to do this that handles all of Kodi's quirks.
Most of this is obvious but let's check the logic is right.

We can't rely on https working in Jarvis.
We can't rely on inputstream.adaptive being available on every platform.

There are really two main Play modes: Autoplay and Manual.

In Autoplay nothing needs to be added to the ListItems in the directory or shortcuts in favourites.
It can all depend on the current Settings and whether inputstream.adaptive is enabled.

In Manual we reveal all the possible links based on the Stream filters and allow users to make direct links to the stream variants.

The Autoplay pseudocode is something like:

Autoplay(episode url)
    if dash chosen and inputstream.adaptive is available and working:
        if provider chosen:
            play dash(provider)
        else
            choose dash(first provider)
    else #always fallback to hls
        find possible streams from provider
        filter streams by https setting
        filter streams by bandwidth
        play(highest bandwidth stream remaining)
        
Manual(episode url)
    same but just list Play(stream,protocol)
    include format in label # BBC One - HLS Akamai https 720p 50fps 5.5Mbps
    
Play(stream url, protocol?)
    work out protocol from url or protocol arg
    if dash 
        add properties to listitem
    return resolved url

If the user plays a Manual stream Shortcut after disabling inputstream.adapative:
tough luck, it just won't work
Manual is for advanced users and debugging so expect users to have to think a bit

The Directory listing needs to hold off adding anything about protocols.

Directory(episode url or page url)
    for links in page
        if episodes page
            add Directory(episodes url)
        else
            if autoplay 
                add Autoplay(episode url)
            else
                add Manual(episode url)

@CaptainTK
Copy link
Collaborator Author

@CaptainTK CaptainTK commented on e7aca5e May 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being quite. Been away again.

I get what you want to do. The problem is that there is not a single entry point like your Autoplay(episode_url). The closest thing I can think of right now is ParseStreamsHLSDASH, AddAvailableLiveStreamItemSelector and AddAvailableLiveStreamsDirectory.

I think this would work for live TV as the decision whether to use DASH or HLS is made before the final directory item is created. However, for catchup in Autoplay, ParseStreamsHLSDASH will be called by AddAvailableStreamItem and the corresponding directory item already is set to play with InputStream Adaptive.

I will give this a try, but I believe this will fail on catchup Autoplay.

@primaeval
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a priority now that Kodi 17.2 hasn't got inputstream.adaptive.
Maybe the solution is just to remove version 3 from the repo and bump version 2 to 4 until inputstream.adaptive returns.

@CaptainTK
Copy link
Collaborator Author

@CaptainTK CaptainTK commented on e7aca5e May 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean until it returns? Has it really been removed? Or has just the option moved?

BTW: I don't understand why, but it does seem to work. Will push a commit shortly, please test.
Edit: See 2dfdef1

@primaeval
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has totally gone from the system addons folder in Windows and Android at least.
inputstream.adaptive does not exists in Kodi 17.2.

@chewitt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few binary add-ons that are missing or not building correctly due to a lack of Krypton tagging from authors in repo's. inputstream.adaptive will be corrected for 17.3 release.

Please sign in to comment.