Skip to content

Commit

Permalink
Improve support alternative player option
Browse files Browse the repository at this point in the history
- Bit of a hack
- Now will work with any configured external player using Play with...
- TODO:
  - Add option to prefer muxed http streams for players that don't support loading MPEG-DASH manifest
  - Split existing use website url option
    - Prefer website urls for use with context menu
    - Force use of web urls for use with default external player
  • Loading branch information
MoojMidge committed Apr 13, 2024
1 parent 7eab8fb commit ec68426
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
2 changes: 2 additions & 0 deletions resources/lib/youtube_plugin/kodion/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
}

BUSY_FLAG = 'busy'
SWITCH_PLAYER_FLAG = 'switch_player'
WAIT_FLAG = 'builtin_running'

__all__ = (
Expand All @@ -42,6 +43,7 @@
'DATA_PATH',
'MEDIA_PATH',
'RESOURCE_PATH',
'SWITCH_PLAYER_FLAG',
'TEMP_PATH',
'VALUE_FROM_STR',
'WAIT_FLAG',
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/youtube_plugin/kodion/items/menu_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from __future__ import absolute_import, division, unicode_literals

from ..constants import paths
from ..constants import ADDON_ID, paths


def more_for_video(context, video_id, logged_in=False, refresh=False):
Expand Down Expand Up @@ -66,7 +66,7 @@ def content_from_description(context, video_id):
def play_with(context):
return (
context.localize('video.play.with'),
'Action(SwitchPlayer)'
'RunScript({addon_id},action/play_with)'.format(addon_id=ADDON_ID),
)


Expand Down
23 changes: 13 additions & 10 deletions resources/lib/youtube_plugin/kodion/items/xbmc/xbmc_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from __future__ import absolute_import, division, unicode_literals

from .. import AudioItem, DirectoryItem, ImageItem, UriItem, VideoItem
from ...constants import SWITCH_PLAYER_FLAG
from ...compatibility import xbmc, xbmcgui
from ...utils import current_system_version, datetime_parser

Expand Down Expand Up @@ -329,9 +330,19 @@ def video_playback_item(context, video_item, show_fanart=None):
settings = context.get_settings()
headers = video_item.get_headers()
license_key = video_item.get_license_key()
is_external = False
is_strm = context.get_param('strm')
mime_type = None

if context.get_ui().get_property(SWITCH_PLAYER_FLAG):
is_external = True
if (settings.alternative_player_web_urls()
and not video_item.get_license_key()):
is_external = True
uri = 'https://www.youtube.com/watch?v={video_id}'.format(
video_id=video_item.video_id
)

if is_strm:
kwargs = {
'path': uri,
Expand All @@ -349,7 +360,7 @@ def video_playback_item(context, video_item, show_fanart=None):
'isPlayable': str(video_item.playable).lower(),
}

if (video_item.use_isa_video()
if (not is_external and video_item.use_isa_video()
and context.addon_enabled('inputstream.adaptive')):
if video_item.use_mpd_video():
manifest_type = 'mpd'
Expand Down Expand Up @@ -559,14 +570,6 @@ def video_listitem(context, video_item, show_fanart=None):
uri = video_item.get_uri()
context.log_debug('Converting VideoItem |%s|' % uri)

settings = context.get_settings()

if (settings.alternative_player_web_urls()
and not video_item.get_license_key()):
uri = 'https://www.youtube.com/watch?v={video_id}'.format(
video_id=video_item.video_id
)

kwargs = {
'label': video_item.get_title() or video_item.get_name(),
'label2': video_item.get_short_details(),
Expand Down Expand Up @@ -615,7 +618,7 @@ def video_listitem(context, video_item, show_fanart=None):
props['playlist_item_id'] = prop_value

if show_fanart is None:
show_fanart = settings.show_fanart()
show_fanart = context.get_settings().show_fanart()
image = video_item.get_image()
list_item.setArt({
'icon': image or 'DefaultVideo.png',
Expand Down
18 changes: 15 additions & 3 deletions resources/lib/youtube_plugin/kodion/monitors/player_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import threading

from ..compatibility import xbmc
from ..constants import BUSY_FLAG
from ..constants import BUSY_FLAG, SWITCH_PLAYER_FLAG


class PlayerMonitorThread(threading.Thread):
Expand Down Expand Up @@ -352,13 +352,24 @@ def cleanup_threads(self, only_ended=True):
))
self.threads = active_threads

def onPlayBackStarted(self):
if self._ui.get_property(SWITCH_PLAYER_FLAG):
self._context.execute('Action(FullScreen)')
self._context.execute('Action(SwitchPlayer)')
self._context.execute('Action(Stop)')

def onAVStarted(self):
if self._ui.get_property(SWITCH_PLAYER_FLAG):
return

if not self._ui.busy_dialog_active():
self._ui.clear_property(BUSY_FLAG)

playback_json = self._ui.get_property('playback_json')
if not playback_json:
return
self._ui.clear_property('playback_json')
self.cleanup_threads()

playback_json = json.loads(playback_json)
try:
Expand All @@ -370,8 +381,6 @@ def onAVStarted(self):
self.start_time = None
self.end_time = None

self._ui.clear_property('playback_json')
self.cleanup_threads()
self.threads.append(PlayerMonitorThread(self,
self._provider,
self._context,
Expand All @@ -382,6 +391,9 @@ def onPlayBackEnded(self):
if not self._ui.busy_dialog_active():
self._ui.clear_property(BUSY_FLAG)

if self._ui.get_property(SWITCH_PLAYER_FLAG):
self._ui.clear_property(SWITCH_PLAYER_FLAG)

self.stop_threads()
self.cleanup_threads()

Expand Down
7 changes: 6 additions & 1 deletion resources/lib/youtube_plugin/kodion/script_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import socket

from .compatibility import parse_qsl, urlsplit, xbmc, xbmcaddon, xbmcvfs
from .constants import DATA_PATH, TEMP_PATH, WAIT_FLAG
from .constants import DATA_PATH, SWITCH_PLAYER_FLAG, TEMP_PATH, WAIT_FLAG
from .context import XbmcContext
from .network import get_client_ip_address, httpd_status
from .utils import rm_dir, validate_ip_address
Expand Down Expand Up @@ -337,6 +337,11 @@ def run(argv):
xbmc.executebuiltin('Container.Refresh')
return

if action == 'play_with':
ui.set_property(SWITCH_PLAYER_FLAG, 'true')
xbmc.executebuiltin('Action(Play)')
return

if category == 'config':
_config_actions(context, action, params)
return
Expand Down

0 comments on commit ec68426

Please sign in to comment.