Skip to content
Closed
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ It is recommended to not add your InputStream add-on as a dependency in addon.xm
## Accepted drm arguments: ##
* widevine
* com.widevine.alpha
* fairplay
* com.apple.fps
* com.apple.fairplay

FairPlay Streaming is played by Kodi itself on Apple platforms, for HLS only. With a FairPlay drm argument
`check_inputstream()` returns whether this Kodi can do that and never shows a dialog, so an add-on can use it
to choose between a FairPlay and a Widevine stream.

## Support ##
Please report any issues or bug reports on the [GitHub Issues](https://github.com/emilsvennesson/script.module.inputstreamhelper/issues) page.
Expand Down
16 changes: 16 additions & 0 deletions lib/inputstreamhelper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,19 @@ def cleanup():
remove_tree(temp_path())
return True

def _supports_fairplay(self):
"""Return if Kodi itself plays FairPlay Streaming, which it only does for HLS on Apple platforms."""
if self.protocol != 'hls':
log(3, 'FairPlay is unsupported with {protocol}', protocol=self.protocol)
return False

from xbmc import getCondVisibility
if getCondVisibility('System.HasFairPlay'):
return True

log(3, 'FairPlay is unsupported on this Kodi install.')
return False

def _supports_hls(self):
"""Return if HLS support is available in inputstream.adaptive."""
if parse_version(self._inputstream_version()) >= parse_version(config.HLS_MINIMUM_IA_VERSION):
Expand Down Expand Up @@ -428,6 +441,9 @@ def check_inputstream(self):
if get_setting_bool('disabled', False): # blindly return True if helper has been disabled
log(3, 'InputStreamHelper is disabled in its settings.xml.')
return True
if self.drm == 'fairplay':
# Kodi plays FairPlay without an InputStream add-on, and add-ons call this to choose a DRM scheme, so no dialogs
return self._supports_fairplay()
if not self._has_inputstream():
# Try to install InputStream add-on
if not self._install_inputstream():
Expand Down
5 changes: 4 additions & 1 deletion lib/inputstreamhelper/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

DRM_SCHEMES = {
'widevine': 'widevine',
'com.widevine.alpha': 'widevine'
'com.widevine.alpha': 'widevine',
'fairplay': 'fairplay',
'com.apple.fps': 'fairplay',
'com.apple.fairplay': 'fairplay'
}

WIDEVINE_CDM_FILENAME = {
Expand Down
39 changes: 39 additions & 0 deletions tests/test_fairplay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# MIT License (see LICENSE.txt or https://opensource.org/licenses/MIT)

# pylint: disable=missing-docstring

import unittest

import inputstreamhelper

xbmc = __import__('xbmc')


class FairPlayTests(unittest.TestCase):

def setUp(self):
self.cond_visibility = xbmc.getCondVisibility

def tearDown(self):
xbmc.getCondVisibility = self.cond_visibility

def test_supported(self):
xbmc.getCondVisibility = lambda string: string == 'System.HasFairPlay'
for drm in ('fairplay', 'com.apple.fps', 'com.apple.fairplay'):
is_helper = inputstreamhelper.Helper('hls', drm=drm)
self.assertTrue(is_helper.check_inputstream())

def test_unsupported_kodi(self):
xbmc.getCondVisibility = lambda string: False
is_helper = inputstreamhelper.Helper('hls', drm='com.apple.fps')
self.assertFalse(is_helper.check_inputstream())

def test_unsupported_protocol(self):
xbmc.getCondVisibility = lambda string: string == 'System.HasFairPlay'
is_helper = inputstreamhelper.Helper('mpd', drm='com.apple.fps')
self.assertFalse(is_helper.check_inputstream())


if __name__ == '__main__':
unittest.main()