Skip to content

Commit

Permalink
Merge pull request #672 from anxdpanic/nexus
Browse files Browse the repository at this point in the history
remove dependency on six
  • Loading branch information
anxdpanic authored Feb 25, 2023
2 parents 6ad4395 + 2252105 commit 1d7bacd
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 87 deletions.
4 changes: 3 additions & 1 deletion addon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<addon id="plugin.video.twitch" version="2.6.2" name="Twitch" provider-name="anxdpanic, A Talented Community">
<requires>
<import addon="xbmc.python" version="3.0.1"/>
<import addon="script.module.six" version="1.11.0"/>
<import addon="script.module.requests" version="2.9.1"/>
<import addon="script.module.python.twitch" version="2.0.20"/>
</requires>
Expand All @@ -16,6 +15,9 @@
<fanart>resources/media/fanart.jpg</fanart>
</assets>
<news>
[rem] removed support for versions of Kodi pre-Nexus v20
[rem] removed support for python 2
[rem] removed dependency on six
[lang] updated translations from Weblate
</news>
<platform>all</platform>
Expand Down
3 changes: 1 addition & 2 deletions resources/lib/twitch_addon/addon/common/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
See LICENSES/GPL-3.0-only for more information.
"""

from six.moves import cPickle as pickle

import functools
import time
import hashlib
import os
import pickle
import shutil

from . import kodi, log_utils
Expand Down
33 changes: 12 additions & 21 deletions resources/lib/twitch_addon/addon/common/kodi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
See LICENSES/GPL-3.0-only for more information.
"""

from six import string_types, text_type, with_metaclass, PY2, PY3
from six.moves.urllib.parse import urlencode, parse_qs

from xbmc import PLAYLIST_VIDEO, PLAYLIST_MUSIC # NOQA

import xbmcaddon
Expand All @@ -26,6 +23,8 @@
import re
import json
import time
from urllib.parse import urlencode
from urllib.parse import parse_qs

try:
xbmc.translatePath = xbmcvfs.translatePath
Expand Down Expand Up @@ -59,11 +58,11 @@ def decode_utf8(string):


def is_unicode(string):
return PY2 and isinstance(string, text_type)
return False


def execute_jsonrpc(command):
if not isinstance(command, string_types):
if not isinstance(command, str):
command = json.dumps(command)
response = xbmc.executeJSONRPC(command)
return json.loads(response)
Expand All @@ -82,7 +81,7 @@ def translate_path(path):


def set_setting(id, value):
if not isinstance(value, string_types): value = str(value)
if not isinstance(value, str): value = str(value)
addon.setSetting(id, value)


Expand Down Expand Up @@ -149,29 +148,24 @@ def set_addon_enabled(addon_id, enabled=True):


def get_icon():
if PY2:
return translate_path('special://home/addons/{0!s}/icon.png'.format(get_id()))
else:
return translate_path('special://home/addons/{0!s}/resources/media/icon.png'.format(get_id()))
return translate_path('special://home/addons/{0!s}/resources/media/icon.png'.format(get_id()))


def get_thumb(filename):
return translate_path('special://home/addons/{0!s}/resources/media/thumbnails/{1!s}'.format(get_id(), filename))


def get_fanart():
if PY2:
return translate_path('special://home/addons/{0!s}/fanart.jpg'.format(get_id()))
else:
return translate_path('special://home/addons/{0!s}/resources/media/fanart.jpg'.format(get_id()))
return translate_path('special://home/addons/{0!s}/resources/media/fanart.jpg'.format(get_id()))


def get_kodi_version():
class MetaClass(type):
def __str__(self):
return '|%s| |%s| -> |%s|%s|%s|%s|%s|' % (self.application, self.version, self.major, self.minor, self.tag, self.tag_version, self.revision)

class KodiVersion(with_metaclass(MetaClass, object)):
class KodiVersion(object):
__metaclass__ = MetaClass
_json_query = execute_jsonrpc({"jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["name"]}, "id": 1})
application = 'Unknown'
if ('result' in _json_query) and ('name' in _json_query['result']):
Expand Down Expand Up @@ -234,7 +228,7 @@ def set_content(content):

def create_item(item_dict, add=True):
path = item_dict.get('path', '')
path = path if isinstance(path, string_types) else get_plugin_url(path)
path = path if isinstance(path, str) else get_plugin_url(path)
list_item = ListItem(label=item_dict.get('label', ''), label2=item_dict.get('label2', ''), path=path)
thumbfile = item_dict.get('thumbfile', None)

Expand Down Expand Up @@ -271,7 +265,7 @@ def add_item(item_dict, list_item):

list_item.setProperty('isPlayable', str(is_playable).lower())

url = path if isinstance(path, string_types) else get_plugin_url(path)
url = path if isinstance(path, str) else get_plugin_url(path)
xbmcplugin.addDirectoryItem(int(sys.argv[1]), url, list_item, isFolder=is_folder, totalItems=item_dict.get('total_items', 0))


Expand Down Expand Up @@ -376,10 +370,7 @@ def __init__(self, strings):

def i18n(self, string_id):
try:
if PY3:
return addon.getLocalizedString(self.strings[string_id])
else:
return addon.getLocalizedString(self.strings[string_id]).encode('utf-8', 'ignore')
return addon.getLocalizedString(self.strings[string_id])
except Exception as e:
xbmc.log('%s: Failed String Lookup: %s (%s)' % (get_name(), string_id, e), xbmc.LOGWARNING)
return string_id
Expand Down
3 changes: 1 addition & 2 deletions resources/lib/twitch_addon/addon/common/search_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
See LICENSES/GPL-3.0-only for more information.
"""
import datetime
import pickle
import sqlite3

import xbmcvfs

from six.moves import cPickle as pickle

from . import kodi


Expand Down
10 changes: 1 addition & 9 deletions resources/lib/twitch_addon/addon/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
See LICENSES/GPL-3.0-only for more information.
"""

from six import PY2
from six.moves.urllib_parse import quote
from urllib.parse import quote

from . import menu_items
from .common import kodi
Expand Down Expand Up @@ -50,8 +49,6 @@ def __init__(self, title_length):

def game_to_listitem(self, game):
name = game[Keys.NAME]
if name and PY2:
name = name.encode('utf-8', 'ignore')
if not name:
name = i18n('unknown_game')

Expand All @@ -73,8 +70,6 @@ def followed_game_to_listitem(self, game):
if 'viewersCount' in game:
viewer_count = str(game['viewersCount'])
name = game['displayName']
if name and PY2:
name = name.encode('utf-8', 'ignore')
if not name:
name = i18n('unknown_game')
image = self.get_boxart(game['boxArtURL'], Images.BOXART)
Expand Down Expand Up @@ -420,9 +415,6 @@ def _format_key(key, headings, info):
if info.get(key) is not None:

info_key = info.get(key)
if PY2 and isinstance(info_key, unicode):
info_key = info_key.encode('utf-8', 'ignore')

val_heading = kodi.decode_utf8(headings.get(key))
val_info = kodi.decode_utf8(info_key)
value = item_template.format(head=val_heading, info=val_info)
Expand Down
27 changes: 5 additions & 22 deletions resources/lib/twitch_addon/addon/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
See LICENSES/GPL-3.0-only for more information.
"""

from six import PY3

from ast import literal_eval
from copy import deepcopy
from functools import wraps
Expand All @@ -32,40 +30,25 @@ def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return result
except ResourceUnavailableException as error:
if PY3:
message = str(error)
else:
message = error.message
message = str(error)
log_utils.log('Connection failed |{0}|'.format(message), log_utils.LOGERROR)
kodi.notify(i18n('connection_failed'), message, duration=7000, sound=False)
except SubRequired as error:
if PY3:
message = str(error)
else:
message = error.message
message = str(error)
log_utils.log('Requires subscription to |{0}|'.format(message), log_utils.LOGDEBUG)
kodi.notify(kodi.get_name(), i18n('subscription_required') % message, duration=5000, sound=False)
except NotFound as error:
if PY3:
message = str(error)
else:
message = error.message
message = str(error)
log_utils.log('Not found |{0}|'.format(message), log_utils.LOGDEBUG)
kodi.notify(kodi.get_name(), i18n('none_found') % message.lower(), duration=5000, sound=False)
except PlaybackFailed as error:
if PY3:
message = str(error)
else:
message = error.message
message = str(error)
log_utils.log('Playback Failed |{0}|'.format(message), log_utils.LOGDEBUG)
kodi.notify(kodi.get_name(), i18n('playback_failed'), duration=5000, sound=False)
kodi.set_resolved_url(kodi.ListItem(), succeeded=False)
except TwitchException as error:
_error = ''
if PY3:
_message = literal_eval(str(deepcopy(error)).strip(','))
else:
_message = error.message
_message = literal_eval(str(deepcopy(error)).strip(','))
try:
_error = _message['error']
message = '[{0}] {1}'.format(_message['status'], _message['message'])
Expand Down
3 changes: 1 addition & 2 deletions resources/lib/twitch_addon/addon/google_firebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import json
import requests
from base64 import b64decode

from six.moves.urllib_parse import quote
from urllib.parse import quote

from .common import log_utils

Expand Down
4 changes: 0 additions & 4 deletions resources/lib/twitch_addon/addon/menu_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
See LICENSES/GPL-3.0-only for more information.
"""

from six import PY2

from . import utils
from .common import kodi
from .constants import MODES, Scripts
Expand All @@ -34,8 +32,6 @@ def clear_search_history(search_type, do_refresh=False):


def remove_search_history(search_type, query, do_refresh=True):
if PY2 and isinstance(query, unicode):
query = query.encode('utf-8')
query_label = '[B]%s[/B]' % query
params = {'mode': MODES.REMOVESEARCHHISTORY, 'search_type': search_type, 'query': query}
if not do_refresh:
Expand Down
15 changes: 4 additions & 11 deletions resources/lib/twitch_addon/addon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
See LICENSES/GPL-3.0-only for more information.
"""

from six import PY2, PY3
from six import iteritems, string_types
from six.moves.urllib.parse import quote_plus

import re
import time

from base64 import b64decode
from datetime import datetime
from urllib.parse import quote_plus

from .common import kodi, json_store
from .strings import STRINGS
Expand Down Expand Up @@ -45,11 +42,7 @@ def show_menu(menu, parent=None):


def to_string(value):
if PY3:
return kodi.decode_utf8(value)
elif PY2:
return value.encode('utf-8')
return value
return kodi.decode_utf8(value)


def loose_version(v):
Expand Down Expand Up @@ -530,7 +523,7 @@ def format_title(self, title_values):
title_setting = int(kodi.get_setting('title_display'))
template = self.get_title_template(title_setting, title_values)

for key, value in iteritems(title_values):
for key, value in title_values.items():
title_values[key] = self.clean_title_value(value)
title = template.format(**title_values)

Expand Down Expand Up @@ -570,7 +563,7 @@ def get_title_template(title_setting, title_values):

@staticmethod
def clean_title_value(value):
if isinstance(value, string_types):
if isinstance(value, str):
try:
value = value.decode('utf-8', 'ignore')
except (UnicodeEncodeError, AttributeError) as e:
Expand Down
4 changes: 0 additions & 4 deletions resources/lib/twitch_addon/routes/edit_qualities.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
See LICENSES/GPL-3.0-only for more information.
"""

from six import PY2

from ..addon import utils
from ..addon.common import kodi
from ..addon.constants import ADAPTIVE_SOURCE_TEMPLATE, LINE_LENGTH
Expand Down Expand Up @@ -44,6 +42,4 @@ def route(api, content_type, target_id=None, name=None, video_id=None, remove=Fa
result = utils.remove_default_quality(content_type)
if result:
name = result[result.keys()[0]]['name']
if PY2 and isinstance(name, unicode):
name = name.encode('utf-8')
kodi.notify(msg=i18n('removed_default_quality') % (content_type, name), sound=False)
5 changes: 0 additions & 5 deletions resources/lib/twitch_addon/routes/token_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
See LICENSES/GPL-3.0-only for more information.
"""

from six import PY2

from ..addon import utils
from ..addon.common import kodi
from ..addon.google_firebase import dynamic_links_short_url
Expand All @@ -26,8 +24,5 @@ def route(api):
short_url = None
prompt_url = short_url if short_url else i18n('authorize_url_fail')

if PY2 and isinstance(prompt_url, unicode):
prompt_url = prompt_url.encode('utf-8')

_ = kodi.Dialog().ok(i18n('authorize_heading'), i18n('authorize_message') + '[CR]%s' % prompt_url)
kodi.show_settings()
8 changes: 4 additions & 4 deletions resources/lib/twitch_addon/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
See LICENSES/GPL-3.0-only for more information.
"""

from six.moves import zip_longest as izip_longest
from six.moves.urllib.parse import quote, unquote

from ast import literal_eval
from datetime import datetime
from itertools import zip_longest
from urllib.parse import quote
from urllib.parse import unquote

import threading

Expand Down Expand Up @@ -117,7 +117,7 @@ def run(self):
@staticmethod
def grouped(items):
args = [iter(items)] * 3
return izip_longest(fillvalue='', *args)
return zip_longest(fillvalue='', *args)

@staticmethod
def notify_live():
Expand Down

0 comments on commit 1d7bacd

Please sign in to comment.