Skip to content

Commit

Permalink
Merge pull request #713 from MoojMidge/master
Browse files Browse the repository at this point in the history
v7.0.6+beta.2
  • Loading branch information
MoojMidge authored Apr 25, 2024
2 parents 94f7c6e + 3df4000 commit 16df238
Show file tree
Hide file tree
Showing 23 changed files with 192 additions and 134 deletions.
2 changes: 1 addition & 1 deletion 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.youtube" name="YouTube" version="7.0.6+beta.1" provider-name="anxdpanic, bromix, MoojMidge">
<addon id="plugin.video.youtube" name="YouTube" version="7.0.6+beta.2" provider-name="anxdpanic, bromix, MoojMidge">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.requests" version="2.27.1"/>
Expand Down
16 changes: 14 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## v7.0.6+beta.2
### Fixed
- Further fixes for multiple busy dialog crash workaround
- Possibly fix issues reported in comments of #704
- Update error checks to avoid unnecessary retries of player requests

### Changed
- Make "Support alternative player" and "Use YouTube website urls with default player" mutually exclusive options #692
- Enable OPUS audio by default #537
- Enable MPEG-DASH for live streams by default #680
- Setup Wizard will prompt to run when plugin first opens after updating, in order to update default settings
- http server will shutdown on idle timeout #699

## v7.0.6+beta.1
### Fixed
- Improve updating containers and (re)loading windows #681
Expand All @@ -7,8 +20,7 @@

### Changed
- Setup Wizard default settings now disable pre-downloading subtitles if MPEG-DASH is enabled
- Ask for quality, Play with subtitles, Play audio only context menu items only displayed if
associated setting is not already enabled
- Ask for quality, Play with subtitles, Play audio only context menu items only displayed if associated setting is not already enabled
- Only make extra request for subtitles for Android client when all subtitle languages are enabled
- Overhaul alternative player support due to Kodi changes and also improve external player support

Expand Down
8 changes: 2 additions & 6 deletions resources/lib/youtube_plugin/kodion/compatibility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,8 @@ def to_str(value):
# Kodi v20+
if hasattr(xbmcgui.ListItem, 'setDateTime'):
def datetime_infolabel(datetime_obj):
if datetime_obj:
return datetime_obj.replace(microsecond=0, tzinfo=None).isoformat()
return ''
return datetime_obj.replace(microsecond=0, tzinfo=None).isoformat()
# Compatibility shims for Kodi v18 and v19
else:
def datetime_infolabel(datetime_obj):
if datetime_obj:
return datetime_obj.strftime('%d.%m.%Y')
return ''
return datetime_obj.strftime('%d.%m.%Y')
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 @@ -34,6 +34,7 @@

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

__all__ = (
Expand All @@ -42,6 +43,7 @@
'BUSY_FLAG',
'DATA_PATH',
'MEDIA_PATH',
'PLAYLIST_POSITION',
'RESOURCE_PATH',
'SWITCH_PLAYER_FLAG',
'TEMP_PATH',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ def execute(command):
def sleep(timeout=None):
raise NotImplementedError()

@staticmethod
def get_infobool(name):
raise NotImplementedError()

@staticmethod
def get_infolabel(name):
raise NotImplementedError()
Expand Down
21 changes: 14 additions & 7 deletions resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,17 @@ def format_time(time_obj, str_format=None):
@staticmethod
def get_language():
language = xbmc.getLanguage(format=xbmc.ISO_639_1, region=True)
lang_code, seperator, region = language.partition('-')
lang_code, separator, region = language.partition('-')
if not lang_code:
language = xbmc.getLanguage(format=xbmc.ISO_639_2, region=False)
lang_code, seperator, region = language.partition('-')
lang_code, separator, region = language.partition('-')
if lang_code != 'fil':
lang_code = lang_code[:2]
region = region[:2]
if not lang_code:
return 'en-US'
if region:
return seperator.join((lang_code.lower(), region.upper()))
return separator.join((lang_code.lower(), region.upper()))
return lang_code

def get_language_name(self, lang_id=None):
Expand Down Expand Up @@ -549,7 +552,7 @@ def execute(self, command, wait=False, wait_for=None):

@staticmethod
def sleep(timeout=None):
wait(timeout)
return wait(timeout)

def addon_enabled(self, addon_id):
response = jsonrpc(method='Addons.GetAddonDetails',
Expand Down Expand Up @@ -590,7 +593,7 @@ def use_inputstream_adaptive(self):
if self.addon_enabled('inputstream.adaptive'):
success = True
elif self.get_ui().on_yes_no_input(
self.get_name(), self.localize('isa.enable.confirm')
self.get_name(), self.localize('isa.enable.confirm')
):
success = self.set_addon_enabled('inputstream.adaptive')
else:
Expand All @@ -610,8 +613,8 @@ def use_inputstream_adaptive(self):
'ttml': loose_version('20.0.0'),
# audio codecs
'vorbis': loose_version('2.3.14'),
# unknown when Opus audio support was implemented
'opus': loose_version('19.0.0'),
# Opus audio enabled in Kodi v21+ which fixes stalls after seek
'opus': loose_version('21.0.0'),
'mp4a': True,
'ac-3': loose_version('2.1.15'),
'ec-3': loose_version('2.1.15'),
Expand Down Expand Up @@ -660,6 +663,10 @@ def inputstream_adaptive_auto_stream_selection():
def abort_requested(self):
return self.get_ui().get_property('abort_requested').lower() == 'true'

@staticmethod
def get_infobool(name):
return xbmc.getCondVisibility(name)

@staticmethod
def get_infolabel(name):
return xbmc.getInfoLabel(name)
Expand Down
7 changes: 4 additions & 3 deletions resources/lib/youtube_plugin/kodion/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,12 @@ def get_stats(self, flush=True, reuse=False):
self._profiler,
stream=output_stream
).strip_dirs().sort_stats('cumulative', 'time').print_stats(50)
output = output_stream.getvalue()
# Occurs when no stats were able to be generated from profiler
except TypeError:
pass
output = output_stream.getvalue()
output_stream.close()
output = 'Profiler: unable to generate stats'
finally:
output_stream.close()

if reuse:
# If stats are accumulating then enable existing/new profiler
Expand Down
31 changes: 16 additions & 15 deletions resources/lib/youtube_plugin/kodion/items/base_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,13 @@ def set_date_from_datetime(self, date_time):
self._date = date_time

def get_date(self, as_text=False, short=False, as_info_label=False):
if not self._date:
return ''
if short:
return self._date.date().strftime('%x')
if as_text:
return self._date.strftime('%x %X')
if as_info_label:
return datetime_infolabel(self._date)
if self._date:
if as_info_label:
return datetime_infolabel(self._date)
if short:
return self._date.date().strftime('%x')
if as_text:
return self._date.strftime('%x %X')
return self._date

def set_dateadded(self, year, month, day, hour=0, minute=0, second=0):
Expand All @@ -165,12 +164,11 @@ def set_dateadded_from_datetime(self, date_time):
self._dateadded = date_time

def get_dateadded(self, as_text=False, as_info_label=False):
if not self._dateadded:
return ''
if as_text:
return self._dateadded.strftime('%x %X')
if as_info_label:
return datetime_infolabel(self._date)
if self._dateadded:
if as_info_label:
return datetime_infolabel(self._dateadded)
if as_text:
return self._dateadded.strftime('%x %X')
return self._dateadded

def set_added_utc(self, date_time):
Expand Down Expand Up @@ -241,4 +239,7 @@ def encode(self, obj, nested=False):
}
else:
output = obj
return output if nested else super(_Encoder, self).encode(output)

if nested:
return to_str(output)
return super(_Encoder, self).encode(output)
27 changes: 13 additions & 14 deletions resources/lib/youtube_plugin/kodion/items/video_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,11 @@ def set_premiered_from_datetime(self, date_time):
self._premiered = date_time.date()

def get_premiered(self, as_text=True, as_info_label=False):
if not self._premiered:
return ''
if as_info_label:
return self._premiered.isoformat()
if as_text:
return self._premiered.strftime('%x')
if self._premiered:
if as_info_label:
return self._premiered.isoformat()
if as_text:
return self._premiered.strftime('%x')
return self._premiered

def set_plot(self, plot):
Expand Down Expand Up @@ -228,12 +227,11 @@ def set_aired_from_datetime(self, date_time):
self._aired = date_time.date()

def get_aired(self, as_text=True, as_info_label=False):
if not self._aired:
return ''
if as_info_label:
return self._aired.isoformat()
if as_text:
return self._aired.strftime('%x')
if self._aired:
if as_info_label:
return self._aired.isoformat()
if as_text:
return self._aired.strftime('%x')
return self._aired

def set_scheduled_start_utc(self, date_time):
Expand Down Expand Up @@ -319,8 +317,9 @@ def set_last_played(self, last_played):
self._last_played = last_played

def get_last_played(self, as_info_label=False):
if as_info_label:
return datetime_infolabel(self._last_played)
if self._last_played:
if as_info_label:
return datetime_infolabel(self._last_played)
return self._last_played

def set_start_percent(self, start_percent):
Expand Down
10 changes: 7 additions & 3 deletions resources/lib/youtube_plugin/kodion/items/xbmc/xbmc_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ def video_playback_item(context, video_item, show_fanart=None):
if current_system_version.compatible(19, 0) else
'inputstreamaddon')
props[inputstream_property] = 'inputstream.adaptive'
props['inputstream.adaptive.manifest_type'] = manifest_type

if not current_system_version.compatible(21, 0):
props['inputstream.adaptive.manifest_type'] = manifest_type

if headers:
props['inputstream.adaptive.manifest_headers'] = headers
Expand All @@ -381,8 +383,10 @@ def video_playback_item(context, video_item, show_fanart=None):
mime_type = uri.split('mime=', 1)[1].split('&', 1)[0]
mime_type = mime_type.replace('%2F', '/')

if (not settings.support_alternative_player()
and headers and uri.startswith('http')):
if (headers and uri.startswith('http') and not (
settings.default_player_web_urls()
or (is_external and settings.alternative_player_web_urls())
)):
kwargs['path'] = '|'.join((uri, headers))

list_item = xbmcgui.ListItem(**kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def onSettingsChanged(self):
'plugin://{0}/'.format(ADDON_ID))):
xbmc.executebuiltin('Container.Refresh')

use_httpd = settings.use_isa() or settings.api_config_page()
use_httpd = (settings.use_isa()
or settings.api_config_page()
or settings.support_alternative_player())
address, port = get_connect_address()
whitelist = settings.httpd_whitelist()

Expand Down Expand Up @@ -166,3 +168,6 @@ def restart_httpd(self):
@staticmethod
def ping_httpd():
return httpd_status()

def httpd_required(self):
return self._use_httpd
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ def play_playlist_item(self, position, resume=False):
context.log_debug('Playing from playlist position: {0}'
.format(position))

if not resume:
xbmc.Player().play(self._playlist, startpos=position - 1)
return
# JSON Player.Open can be too slow but is needed if resuming is enabled
jsonrpc(method='Player.Open',
params={'item': {'playlistid': self._playlist.getPlayListId(),
# Convert 1 indexed to 0 indexed position
'position': position - 1}},
options={'resume': resume},
options={'resume': True},
no_response=True)

def get_position(self, offset=0):
Expand Down
38 changes: 19 additions & 19 deletions resources/lib/youtube_plugin/kodion/plugin/xbmc/xbmc_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from traceback import format_stack

from ..abstract_plugin import AbstractPlugin
from ...constants import BUSY_FLAG
from ...constants import BUSY_FLAG, PLAYLIST_POSITION
from ...compatibility import xbmcplugin
from ...exceptions import KodionException
from ...items import (
Expand Down Expand Up @@ -42,27 +42,22 @@ def run(self, provider, context):
ui = context.get_ui()

if ui.get_property(BUSY_FLAG).lower() == 'true':
ui.clear_property(BUSY_FLAG)
if ui.busy_dialog_active():
playlist = XbmcPlaylist('auto', context, retry=3)
playlist.clear()
xbmcplugin.endOfDirectory(
self.handle,
succeeded=False,
updateListing=True,
)

playlist = XbmcPlaylist('auto', context, retry=3)
position, remaining = playlist.get_position()
items = playlist.get_items() if remaining else None
playlist.clear()

context.log_warning('Multiple busy dialogs active - '
'playlist cleared to avoid Kodi crash')

num_items = 0
items = ui.get_property('playlist')
position = ui.get_property('position')

if position and items:
position = int(position)
ui.clear_property('playlist')

if items:
max_wait_time = 30
while ui.busy_dialog_active():
max_wait_time -= 1
Expand All @@ -74,10 +69,12 @@ def run(self, provider, context):

context.log_warning('Multiple busy dialogs active - '
'reloading playlist')
num_items = playlist.add_items(items, loads=True)
num_items = playlist.add_items(items)

old_position = ui.get_property(PLAYLIST_POSITION)
if old_position and position == int(old_position):
position += 1

if position and num_items:
position += 1
max_wait_time = min(position, num_items)
while ui.busy_dialog_active() or playlist.size() < position:
max_wait_time -= 1
Expand All @@ -89,8 +86,13 @@ def run(self, provider, context):
else:
playlist.play_playlist_item(position)

ui.clear_property(BUSY_FLAG)
ui.clear_property(PLAYLIST_POSITION)
return False

ui.clear_property(BUSY_FLAG)
ui.clear_property(PLAYLIST_POSITION)

if settings.is_setup_wizard_enabled():
provider.run_wizard(context)

Expand Down Expand Up @@ -169,10 +171,8 @@ def _set_resolved_url(self, context, base_item, show_fanart):
if not context.is_plugin_path(uri) and ui.busy_dialog_active():
ui.set_property(BUSY_FLAG, 'true')
playlist = XbmcPlaylist('auto', context)
position, remaining = playlist.get_position()
if remaining:
ui.set_property('playlist', playlist.get_items(dumps=True))
ui.set_property('position', str(position))
position, _ = playlist.get_position()
ui.set_property(PLAYLIST_POSITION, str(position))

item = playback_item(context, base_item, show_fanart)
xbmcplugin.setResolvedUrl(self.handle,
Expand Down
Loading

0 comments on commit 16df238

Please sign in to comment.