diff --git a/README.md b/README.md index 3709adde..e19e3e52 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/inputstreamhelper/__init__.py b/lib/inputstreamhelper/__init__.py index 383f9938..3354463f 100644 --- a/lib/inputstreamhelper/__init__.py +++ b/lib/inputstreamhelper/__init__.py @@ -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): @@ -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(): diff --git a/lib/inputstreamhelper/config.py b/lib/inputstreamhelper/config.py index c861c7d0..8ff92939 100644 --- a/lib/inputstreamhelper/config.py +++ b/lib/inputstreamhelper/config.py @@ -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 = { diff --git a/tests/test_fairplay.py b/tests/test_fairplay.py new file mode 100644 index 00000000..6e6dbb8d --- /dev/null +++ b/tests/test_fairplay.py @@ -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()