Skip to content

Commit

Permalink
Merge pull request #29 from anxdpanic/pr_jarvis
Browse files Browse the repository at this point in the history
  • Loading branch information
anxdpanic committed Sep 11, 2020
2 parents 2790b22 + d53e0f9 commit 08f2664
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 48 deletions.
8 changes: 6 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.playthis" name="PlayThis" version="5.0.2" provider-name="anxdpanic">
<addon id="plugin.video.playthis" name="PlayThis" version="5.0.3" provider-name="anxdpanic">
<requires>
<import addon="xbmc.python" version="2.24.0"/>
<import addon="script.module.six" version="1.11.0"/>
Expand All @@ -11,7 +11,11 @@
</extension>
<extension point="xbmc.addon.metadata">
<news>
[upd] Use new settings format on Kodi 19
[fix] Kodi 19 not working
[fix] remove LOGNOTICE AND LOGSEVERE, both removed in Kodi 19
[fix] use xbmcvfs.translatePath when available
[fix] mitigate busy dialog related crashes

</news>
<assets>
<icon>icon.png</icon>
Expand Down
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
5.0.3
[fix] Kodi 19 not working
[fix] remove LOGNOTICE AND LOGSEVERE, both removed in Kodi 19
[fix] use xbmcvfs.translatePath when available
[fix] mitigate busy dialog related crashes

5.0.2
[upd] Use new settings format on Kodi 19

Expand Down
6 changes: 6 additions & 0 deletions resources/lib/addon_lib/kodi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@

from . import strings

try:
xbmc.translatePath = xbmcvfs.translatePath
except AttributeError:
pass

__log = xbmc.log

Addon = xbmcaddon.Addon
Dialog = xbmcgui.Dialog
Monitor = xbmc.Monitor
Player = xbmc.Player
execute_builtin = xbmc.executebuiltin
sleep = xbmc.sleep
conditional_visibility = xbmc.getCondVisibility
getCurrentWindowDialogId = xbmcgui.getCurrentWindowDialogId
get_supported_media = xbmc.getSupportedMedia
vfs = xbmcvfs

Expand Down
6 changes: 3 additions & 3 deletions resources/lib/addon_lib/log_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
from xbmc import LOGFATAL
from xbmc import LOGINFO
from xbmc import LOGNONE
from xbmc import LOGNOTICE
from xbmc import LOGSEVERE
from xbmc import LOGWARNING

LOGNOTICE = LOGINFO

from . import kodi


__all__ = ['log', 'trace', 'LOGDEBUG', 'LOGERROR', 'LOGFATAL', 'LOGINFO', 'LOGNONE', 'LOGNOTICE', 'LOGSEVERE', 'LOGWARNING']
__all__ = ['log', 'trace', 'LOGDEBUG', 'LOGERROR', 'LOGFATAL', 'LOGINFO', 'LOGNONE', 'LOGNOTICE', 'LOGWARNING']


name = kodi.get_name()
Expand Down
91 changes: 48 additions & 43 deletions resources/lib/addon_lib/playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ def remote_play(source):
'thumb': quote(source['art']['thumb']), 'title': quote(source['info']['title'])})
else:
filename = source['url']

utils.wait_for_busy_dialog()
command = {'jsonrpc': '2.0', 'id': 1, 'method': 'Player.Open', 'params': {'item': {'file': filename}}}
response = rpc_client.execute_rpc(command)
if 'error' in response:
Expand All @@ -644,6 +646,8 @@ def play(source, player=True):
if player == 'remote':
remote_play(source)
else:
utils.wait_for_busy_dialog()

if source['content_type'] == 'image':
command = {'jsonrpc': '2.0', 'id': 1, 'method': 'Player.Open', 'params': {'item': {'file': source['url']}}}
log_utils.log('Play using jsonrpc method Player.Open: |{0!s}|'.format(source['url']), log_utils.LOGDEBUG)
Expand Down Expand Up @@ -823,51 +827,52 @@ def play_this(item, title='', thumbnail='', player=True, history=None):
stream_url = None

if stream_url and (content_type == 'video' or content_type == 'audio' or content_type == 'image' or content_type == 'executable'):
working_dialog = kodi.WorkingDialog()
with working_dialog:
play_history = utils.PlayHistory()
working_dialog.update(20)
if history or player == 'history':
history_item = item.split('|')[0]
if '%' not in history_item:
history_item = quote(history_item)
log_utils.log('Adding source |{0}| to history with content_type |{1}|'
.format(item, content_type), log_utils.LOGDEBUG)
play_history.add(history_item, content_type, label if label else item, quote(thumbnail))
working_dialog.update(40)
if override_content_type and override_history:
history_item = stream_url
if history_item.startswith('plugin://') or unresolved_source:
history_item = unresolved_source
history_item = history_item.split('|')[0]
if '%' not in history_item:
history_item = quote(history_item)
log_utils.log('Adding source |{0}| to history with content_type |{1}|'
.format(unresolved_source, override_content_type), log_utils.LOGDEBUG)
play_history.add(history_item, override_content_type, source_label, quote(source_thumbnail))
if player == 'history':
return
if history_item:
kodi.refresh_container()
working_dialog.update(60)
if (not stream_url.startswith('plugin://')) and (headers is not None):
stream_url = get_url_with_headers(stream_url, headers)

working_dialog.update(80)
if any(plugin_id in stream_url for plugin_id in RUNPLUGIN_EXCEPTIONS):
log_utils.log('Running plugin: |{0!s}|'.format(stream_url), log_utils.LOGDEBUG)
kodi.execute_builtin('RunPlugin(%s)' % stream_url)
else:
if override_content_type:
content_type = override_content_type
play_history = utils.PlayHistory()
if history or player == 'history':
history_item = item.split('|')[0]
if '%' not in history_item:
history_item = quote(history_item)
log_utils.log('Adding source |{0}| to history with content_type |{1}|'
.format(item, content_type), log_utils.LOGDEBUG)
play_history.add(history_item, content_type, label if label else item, quote(thumbnail))
if override_content_type and override_history:
history_item = stream_url
if history_item.startswith('plugin://') or unresolved_source:
history_item = unresolved_source
history_item = history_item.split('|')[0]
if '%' not in history_item:
history_item = quote(history_item)
log_utils.log('Adding source |{0}| to history with content_type |{1}|'
.format(unresolved_source, override_content_type), log_utils.LOGDEBUG)
play_history.add(history_item, override_content_type, source_label, quote(source_thumbnail))
if player == 'history':
return
if history_item:
kodi.refresh_container()
if (not stream_url.startswith('plugin://')) and (headers is not None):
stream_url = get_url_with_headers(stream_url, headers)

kodi.execute_builtin('Dialog.Close(busydialog)')
kodi.execute_builtin('Dialog.Close(busydialognocancel)')

if any(plugin_id in stream_url for plugin_id in RUNPLUGIN_EXCEPTIONS):
log_utils.log('Running plugin: |{0!s}|'.format(stream_url), log_utils.LOGDEBUG)
utils.wait_for_busy_dialog()
kodi.execute_builtin('RunPlugin(%s)' % stream_url)
else:
if override_content_type:
content_type = override_content_type

source = {'content_type': content_type,
'url': stream_url,
'is_dash': is_dash,
'info': {'title': source_label},
'art': {'icon': source_thumbnail, 'thumb': source_thumbnail}}
source = {'content_type': content_type,
'url': stream_url,
'is_dash': is_dash,
'info': {'title': source_label},
'art': {'icon': source_thumbnail, 'thumb': source_thumbnail}}

play(source, player)
play(source, player)

else:
log_utils.log('Found no potential sources: |{0!s}|'.format(item), log_utils.LOGDEBUG)

kodi.execute_builtin('Dialog.Close(busydialog)')
kodi.execute_builtin('Dialog.Close(busydialognocancel)')
43 changes: 43 additions & 0 deletions resources/lib/addon_lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""

import re
import time

from six import PY2
from six.moves.urllib_parse import quote
Expand Down Expand Up @@ -336,3 +337,45 @@ def export(self, row_id):
return
log_utils.log('STRMUtils.export no item for export to .strm', log_utils.LOGDEBUG)
kodi.notify(msg=kodi.i18n('no_items_export'), sound=False)


def wait_for_busy_dialog():
"""
Wait for busy dialogs to close, starting playback while the busy dialog is active
could crash Kodi 18 / 19 (pre-alpha)
Github issues:
https://github.com/xbmc/xbmc/issues/16756
https://github.com/xbmc/xbmc/pull/16450 # possible solution
TODO: remove this function when the above issue is resolved
"""
monitor = kodi.Monitor()
start_time = time.time()
kodi.sleep(500)

def _abort():
return monitor.abortRequested()

def _busy():
return kodi.getCurrentWindowDialogId() in [10138, 10160]

def _wait():
log_utils.log('Waiting for busy dialogs to close ...', log_utils.LOGDEBUG)
while not _abort() and _busy():
if monitor.waitForAbort(1):
break

while not _abort():
if _busy():
_wait()

if monitor.waitForAbort(1):
break

if not _busy():
break

log_utils.log('Waited %.2f for busy dialogs to close.' %
(time.time() - start_time), log_utils.LOGDEBUG)
return not _abort() and not _busy()

0 comments on commit 08f2664

Please sign in to comment.