Skip to content

Commit

Permalink
Merge pull request #672 from MoojMidge/master
Browse files Browse the repository at this point in the history
v7.0.5+beta.3
  • Loading branch information
MoojMidge authored Apr 1, 2024
2 parents e5562cd + 0326b2f commit d813ff4
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 81 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.5+beta.2" provider-name="anxdpanic, bromix, MoojMidge">
<addon id="plugin.video.youtube" name="YouTube" version="7.0.5+beta.3" 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
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v7.0.5+beta.3
### Fixed
- Fix error message when rating video #666
- Fix various issues with Kodi 18 and Python 2 #668
- Fix issues with video playback #654, #659, #663

## v7.0.5+beta.2
### Fixed
- Fix typos #661
Expand Down
21 changes: 13 additions & 8 deletions resources/lib/youtube_plugin/kodion/compatibility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'parse_qsl',
'quote',
'string_type',
'to_str',
'unescape',
'unquote',
'urlencode',
Expand Down Expand Up @@ -52,6 +53,7 @@

string_type = str
byte_string_type = bytes
to_str = str
# Compatibility shims for Kodi v18 and Python v2.7
except ImportError:
import BaseHTTPServer
Expand Down Expand Up @@ -79,23 +81,21 @@


def quote(data, *args, **kwargs):
return _quote(data.encode('utf-8'), *args, **kwargs)
return _quote(to_str(data), *args, **kwargs)


def unquote(data):
return _unquote(data.encode('utf-8'))
return _unquote(to_str(data))


def urlencode(data, *args, **kwargs):
if isinstance(data, dict):
data = data.items()
return _urlencode({
key.encode('utf-8'): (
[part.encode('utf-8') if isinstance(part, unicode)
else str(part)
for part in value] if isinstance(value, (list, tuple))
else value.encode('utf-8') if isinstance(value, unicode)
else str(value)
to_str(key): (
[to_str(part) for part in value]
if isinstance(value, (list, tuple)) else
to_str(value)
)
for key, value in data
}, *args, **kwargs)
Expand All @@ -121,6 +121,11 @@ def _file_closer(*args, **kwargs):
string_type = basestring
byte_string_type = (bytes, str)

def to_str(value):
if isinstance(value, unicode):
return value.encode('utf-8')
return str(value)

# Kodi v20+
if hasattr(xbmcgui.ListItem, 'setDateTime'):
def datetime_infolabel(datetime_obj):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import os

from .. import logger
from ..compatibility import urlencode
from ..compatibility import to_str, urlencode
from ..json_store import AccessManager
from ..sql_store import (
DataCache,
Expand Down Expand Up @@ -265,7 +265,7 @@ def parse_params(self, params=None):
val for val in value.split(',') if val
]
elif param in self._STRING_PARAMS:
parsed_value = str(value)
parsed_value = to_str(value)
# process and translate deprecated parameters
if param == 'action':
if parsed_value in ('play_all', 'play_video'):
Expand Down Expand Up @@ -385,3 +385,6 @@ def get_infolabel(name):
@staticmethod
def get_listitem_detail(detail_name, attr=False):
raise NotImplementedError()

def tear_down(self):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,8 @@ def get_listitem_detail(detail_name, attr=False):
if attr else
'Container.ListItem(0).Property({0})'.format(detail_name)
)

def tear_down(self):
self._settings.flush()
del self._addon
self._addon = None
6 changes: 3 additions & 3 deletions resources/lib/youtube_plugin/kodion/items/audio_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from __future__ import absolute_import, division, unicode_literals

from .base_item import BaseItem
from ..compatibility import unescape
from ..compatibility import to_str, unescape


class AudioItem(BaseItem):
Expand Down Expand Up @@ -54,7 +54,7 @@ def add_artist(self, artist):
if self._artists is None:
self._artists = []
if artist:
self._artists.append(str(artist))
self._artists.append(to_str(artist))

def get_artists(self):
return self._artists
Expand All @@ -72,7 +72,7 @@ def add_genre(self, genre):
if self._genres is None:
self._genres = []
if genre:
self._genres.append(str(genre))
self._genres.append(to_str(genre))

def get_genres(self):
return self._genres
Expand Down
85 changes: 49 additions & 36 deletions resources/lib/youtube_plugin/kodion/items/base_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
from datetime import date, datetime
from hashlib import md5

from ..compatibility import datetime_infolabel, string_type, unescape
from ..compatibility import datetime_infolabel, string_type, to_str, unescape
from ..constants import MEDIA_PATH


class BaseItem(object):
VERSION = 3
INFO_DATE = 'date' # (string) iso 8601

_playable = False

Expand Down Expand Up @@ -48,43 +47,19 @@ def __init__(self, name, uri, image='', fanart=''):
self._next_page = False

def __str__(self):
name = self._name
uri = self._uri
image = self._image
obj_str = "------------------------------\n'%s'\nURI: %s\nImage: %s\n------------------------------" % (name, uri, image)
return obj_str
return ('------------------------------\n'
'Name: |{0}|\n'
'URI: |{1}|\n'
'Image: |{2}|\n'
'------------------------------'.format(self._name,
self._uri,
self._image))

def to_dict(self):
return {'type': self.__class__.__name__, 'data': self.__dict__}

def dumps(self):
def _encoder(obj):
if isinstance(obj, (date, datetime)):
class_name = obj.__class__.__name__

if 'fromisoformat' in dir(obj):
return {
'__class__': class_name,
'__isoformat__': obj.isoformat(),
}

if class_name == 'datetime':
if obj.tzinfo:
format_string = '%Y-%m-%dT%H:%M:%S%z'
else:
format_string = '%Y-%m-%dT%H:%M:%S'
else:
format_string = '%Y-%m-%d'

return {
'__class__': class_name,
'__format_string__': format_string,
'__value__': obj.strftime(format_string)
}

return json.JSONEncoder().default(obj)

return json.dumps(self.to_dict(), ensure_ascii=False, default=_encoder)
return json.dumps(self.to_dict(), ensure_ascii=False, cls=_Encoder)

def get_id(self):
"""
Expand Down Expand Up @@ -230,5 +205,43 @@ def next_page(self, value):
self._next_page = bool(value)

@property
def playable(cls):
return cls._playable
def playable(self):
return self._playable


class _Encoder(json.JSONEncoder):
def encode(self, obj):
if isinstance(obj, string_type):
return to_str(obj)

if isinstance(obj, dict):
return {to_str(key): self.encode(value)
for key, value in obj.items()}

if isinstance(obj, (list, tuple)):
return [self.encode(item) for item in obj]

if isinstance(obj, (date, datetime)):
class_name = obj.__class__.__name__

if 'fromisoformat' in dir(obj):
return {
'__class__': class_name,
'__isoformat__': obj.isoformat(),
}

if class_name == 'datetime':
if obj.tzinfo:
format_string = '%Y-%m-%dT%H:%M:%S%z'
else:
format_string = '%Y-%m-%dT%H:%M:%S'
else:
format_string = '%Y-%m-%d'

return {
'__class__': class_name,
'__format_string__': format_string,
'__value__': obj.strftime(format_string)
}

return self.iterencode(obj)
16 changes: 8 additions & 8 deletions resources/lib/youtube_plugin/kodion/items/video_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import re

from .base_item import BaseItem
from ..compatibility import datetime_infolabel, unescape
from ..compatibility import datetime_infolabel, to_str, unescape
from ..utils import duration_to_seconds, seconds_to_duration


Expand Down Expand Up @@ -71,7 +71,7 @@ def add_artist(self, artist):
if self._artists is None:
self._artists = []
if artist:
self._artists.append(str(artist))
self._artists.append(to_str(artist))

def get_artists(self):
return self._artists
Expand All @@ -83,7 +83,7 @@ def add_studio(self, studio):
if self._studios is None:
self._studios = []
if studio:
self._studios.append(str(studio))
self._studios.append(to_str(studio))

def get_studios(self):
return self._studios
Expand Down Expand Up @@ -156,7 +156,7 @@ def add_directors(self, director):
if self._directors is None:
self._directors = []
if director:
self._directors.append(str(director))
self._directors.append(to_str(director))

def get_directors(self):
return self._directors
Expand All @@ -169,10 +169,10 @@ def add_cast(self, member, role=None, order=None, thumbnail=None):
self._cast = []
if member:
self._cast.append({
'member': str(member),
'role': str(role) if role else '',
'member': to_str(member),
'role': to_str(role) if role else '',
'order': int(order) if order else len(self._cast) + 1,
'thumbnail': str(thumbnail) if thumbnail else '',
'thumbnail': to_str(thumbnail) if thumbnail else '',
})

def get_cast(self):
Expand Down Expand Up @@ -262,7 +262,7 @@ def add_genre(self, genre):
if self._genres is None:
self._genres = []
if genre:
self._genres.append(str(genre))
self._genres.append(to_str(genre))

def get_genres(self):
return self._genres
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ def run(self, provider, context):

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

num_items = 0
items = ui.get_property('playlist')
Expand Down
10 changes: 6 additions & 4 deletions resources/lib/youtube_plugin/kodion/plugin_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ def run(provider, context=None):
path=context.get_path(),
params=params))

plugin.run(provider, context)
provider.tear_down(context)
try:
plugin.run(provider, context)
finally:
if profiler:
profiler.print_stats()

if profiler:
profiler.print_stats()
provider.tear_down(context)
1 change: 1 addition & 0 deletions resources/lib/youtube_plugin/kodion/script_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,5 @@ def run(argv):
_user_actions(context, action, params)
return
finally:
context.tear_down()
ui.clear_property(WAIT_FLAG)
2 changes: 2 additions & 0 deletions resources/lib/youtube_plugin/kodion/service_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ def run():

if monitor.httpd:
monitor.shutdown_httpd() # shutdown http server

context.tear_down()
19 changes: 15 additions & 4 deletions resources/lib/youtube_plugin/kodion/settings/abstract_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import sys

from ..constants import settings
from ..utils import validate_ip_address
from ..utils import current_system_version, validate_ip_address


class AbstractSettings(object):
Expand Down Expand Up @@ -383,6 +383,17 @@ def get_history_playlist(self):
def set_history_playlist(self, value):
return self.set_string(settings.HISTORY_PLAYLIST, value)

def get_label_color(self, label_part):
setting_name = '.'.join((settings.LABEL_COLOR, label_part))
return self.get_string(setting_name, 'white')
if current_system_version.compatible(20, 0):
def get_label_color(self, label_part):
setting_name = '.'.join((settings.LABEL_COLOR, label_part))
return self.get_string(setting_name, 'white')
else:
_COLOR_MAP = {
'commentCount': 'cyan',
'favoriteCount': 'gold',
'likeCount': 'lime',
'viewCount': 'lightblue',
}

def get_label_color(self, label_part):
return self._COLOR_MAP.get(label_part, 'white')
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ def _set_string_list(store, setting, value):
})

@classmethod
def flush(cls, xbmc_addon):
def flush(cls, xbmc_addon=None):
if not xbmc_addon:
del cls._instance
cls._instance = None
return

cls._echo = get_kodi_setting_bool('debug.showloginfo')
cls._cache = {}
if current_system_version.compatible(21, 0):
Expand Down
Loading

0 comments on commit d813ff4

Please sign in to comment.