From c22b4c782d15a14efa730ec9c8f7bb484af90ff4 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 19 Dec 2020 20:43:08 +0100 Subject: [PATCH] Remove obsolete encodes and decodes --- default.py | 9 ++----- resources/lib/app/libsync.py | 2 +- resources/lib/context_entry.py | 4 ++-- resources/lib/entrypoint.py | 2 +- resources/lib/initialsetup.py | 2 +- resources/lib/kodimonitor.py | 8 +++---- resources/lib/playback_decision.py | 6 ++--- resources/lib/playlist_func.py | 2 +- resources/lib/playlists/common.py | 2 +- resources/lib/plex_api/fanart_lookup.py | 2 +- resources/lib/plex_companion.py | 6 ++--- resources/lib/plex_functions.py | 2 +- resources/lib/utils.py | 25 ++++++-------------- resources/lib/windows/direct_path_sources.py | 4 ++-- 14 files changed, 30 insertions(+), 46 deletions(-) diff --git a/default.py b/default.py index 1a767615..8eab9599 100644 --- a/default.py +++ b/default.py @@ -11,7 +11,6 @@ import xbmcgui import xbmcplugin from resources.lib import entrypoint, utils, transfer, variables as v, loghandler -from resources.lib.tools import unicode_paths ############################################################################### @@ -30,12 +29,8 @@ class Main(object): LOG.debug('Full sys.argv received: %s', argv) # Parse parameters params = dict(parse_qsl(argv[2][1:])) - arguments = unicode_paths.decode(argv[2]) - path = unicode_paths.decode(argv[0]) - # Ensure unicode - for key, value in params.items(): - params[key.decode('utf-8')] = params.pop(key) - params[key] = value.decode('utf-8') + arguments = argv[2] + path = argv[0] mode = params.get('mode', '') itemid = params.get('id', '') diff --git a/resources/lib/app/libsync.py b/resources/lib/app/libsync.py index 7bc03fb4..84a9b783 100644 --- a/resources/lib/app/libsync.py +++ b/resources/lib/app/libsync.py @@ -108,7 +108,7 @@ class Sync(object): self.remapSMBphotoOrg = remove_trailing_slash(utils.settings('remapSMBphotoOrg')) self.remapSMBphotoNew = remove_trailing_slash(utils.settings('remapSMBphotoNew')) self.escape_path = utils.settings('escapePath') == 'true' - self.escape_path_safe_chars = utils.settings('escapePathSafeChars').encode('utf-8') + self.escape_path_safe_chars = utils.settings('escapePathSafeChars') self.indicate_media_versions = utils.settings('indicate_media_versions') == "true" self.sync_specific_plex_playlists = utils.settings('syncSpecificPlexPlaylists') == 'true' self.sync_specific_kodi_playlists = utils.settings('syncSpecificKodiPlaylists') == 'true' diff --git a/resources/lib/context_entry.py b/resources/lib/context_entry.py index 9009df30..0c0cb51c 100644 --- a/resources/lib/context_entry.py +++ b/resources/lib/context_entry.py @@ -142,8 +142,8 @@ class ContextMenu(object): playqueue.clear() app.PLAYSTATE.context_menu_play = True handle = self.api.fullpath(force_addon=True)[0] - handle = 'RunPlugin(%s)' % handle - xbmc.executebuiltin(handle.encode('utf-8')) + handle = f'RunPlugin({handle})' + xbmc.executebuiltin(handle) def _extras(self): """ diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index 757ee9d6..ce21bdc3 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -483,7 +483,7 @@ def browse_plex(key=None, plex_type=None, section_id=None, synched=True, if prompt is None: # User cancelled return - prompt = prompt.strip().decode('utf-8') + prompt = prompt.strip() args['query'] = prompt xml = DU().downloadUrl(utils.extend_url('{server}%s' % key, args)) try: diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index ed81d746..86ba59a6 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -410,7 +410,7 @@ class InitialSetup(object): utils.messageDialog( utils.lang(29999), '%s %s\n%s' % (utils.lang(39013), - server['name'].decode('utf-8'), + server['name'], utils.lang(39014))) if self.plex_tv_sign_in() is False: # Exit while loop if user cancels diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 7a72b4cc..e317c312 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -209,7 +209,7 @@ class KodiMonitor(xbmc.Monitor): play_info = json.loads(play_info) app.APP.player.stop() handle = 'RunPlugin(%s)' % play_info.get('handle') - xbmc.executebuiltin(handle.encode('utf-8')) + xbmc.executebuiltin(handle) def PlayBackStart(self, data): """ @@ -582,11 +582,11 @@ def _notify_upnext(item): } _complete_artwork_keys(info[key]) info['play_info'] = {'handle': next_api.fullpath(force_addon=True)[0]} - sender = v.ADDON_ID.encode('utf-8') - method = 'upnext_data'.encode('utf-8') + sender = v.ADDON_ID + method = 'upnext_data' data = binascii.hexlify(json.dumps(info)) data = '\\"[\\"{0}\\"]\\"'.format(data) - xbmc.executebuiltin('NotifyAll(%s, %s, %s)' % (sender, method, data)) + xbmc.executebuiltin(f'NotifyAll({sender}, {method}, {data})') def _videolibrary_onupdate(data): diff --git a/resources/lib/playback_decision.py b/resources/lib/playback_decision.py index 8f6a00fc..8e89cd74 100644 --- a/resources/lib/playback_decision.py +++ b/resources/lib/playback_decision.py @@ -379,7 +379,7 @@ def audio_subtitle_prefs(api, item): codec, channellayout) audio_streams_list.append(index) - audio_streams.append(track.encode('utf-8')) + audio_streams.append(track) audio_numb += 1 # Subtitles @@ -405,7 +405,7 @@ def audio_subtitle_prefs(api, item): track = "%s - %s" % (track, utils.lang(39709)) # Forced track = "%s (%s)" % (track, utils.lang(39710)) # burn-in subtitle_streams_list.append(index) - subtitle_streams.append(track.encode('utf-8')) + subtitle_streams.append(track) sub_num += 1 if audio_numb > 1: @@ -437,7 +437,7 @@ def audio_subtitle_prefs(api, item): else: LOG.info('User chose to burn-in subtitle %s: %s', select_subs_index, - subtitle_streams[resp].decode('utf-8')) + subtitle_streams[resp]) select_subs_index = subtitle_streams_list[resp - 1] # Now prep the PMS for our choice args = { diff --git a/resources/lib/playlist_func.py b/resources/lib/playlist_func.py index 29e9f1cf..d6b8d92a 100644 --- a/resources/lib/playlist_func.py +++ b/resources/lib/playlist_func.py @@ -795,4 +795,4 @@ def get_plextype_from_xml(xml): except (TypeError, IndexError, AttributeError): LOG.error('Could not get plex metadata for plex id %s', plex_id) return - return new_xml[0].attrib.get('type').decode('utf-8') + return new_xml[0].attrib.get('type') diff --git a/resources/lib/playlists/common.py b/resources/lib/playlists/common.py index 1ebd4ab2..4de357ea 100644 --- a/resources/lib/playlists/common.py +++ b/resources/lib/playlists/common.py @@ -130,7 +130,7 @@ def kodi_playlist_hash(path): m = hashlib.md5() m.update(repr(stat.st_size)) m.update(repr(stat.st_mtime)) - return m.hexdigest().decode('utf-8') + return m.hexdigest() class PlaylistQueue(OrderedSetQueue): diff --git a/resources/lib/plex_api/fanart_lookup.py b/resources/lib/plex_api/fanart_lookup.py index 05c5abc3..bae5c359 100644 --- a/resources/lib/plex_api/fanart_lookup.py +++ b/resources/lib/plex_api/fanart_lookup.py @@ -31,7 +31,7 @@ def external_item_id(title, year, plex_type, collection): parameters = { 'api_key': API_KEY, 'language': v.KODILANGUAGE, - 'query': title.encode('utf-8') + 'query': title } data = DU().downloadUrl(url, authenticate=False, diff --git a/resources/lib/plex_companion.py b/resources/lib/plex_companion.py index d6f3675a..72def4ce 100644 --- a/resources/lib/plex_companion.py +++ b/resources/lib/plex_companion.py @@ -141,11 +141,11 @@ class PlexCompanion(backgroundthread.KillableThread): app.CONN.plex_transient_token = data.get('key') params = { 'mode': 'plex_node', - 'key': '{server}%s' % data.get('key'), + 'key': f"{{server}}{data.get('key')}", 'offset': data.get('offset') } - handle = 'RunPlugin(plugin://%s)' % utils.extend_url(v.ADDON_ID, params) - executebuiltin(handle.encode('utf-8')) + handle = f'RunPlugin(plugin://{utils.extend_url(v.ADDON_ID, params)})' + executebuiltin(handle) @staticmethod def _process_playlist(data): diff --git a/resources/lib/plex_functions.py b/resources/lib/plex_functions.py index 1e37ebed..a7391b5c 100644 --- a/resources/lib/plex_functions.py +++ b/resources/lib/plex_functions.py @@ -55,7 +55,7 @@ def ParseContainerKey(containerKey): Output hence: library, key, query (str, int, dict) """ result = utils.urlparse(containerKey) - library, key = GetPlexKeyNumber(result.path.decode('utf-8')) + library, key = GetPlexKeyNumber(result.path) query = dict(utils.parse_qsl(result.query)) return library, key, query diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 01a0c4b3..be49ae6b 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -54,7 +54,7 @@ REGEX_MUSICPATH = re.compile(r'''^\^(.+)\$$''') # Grab Plex id from an URL-encoded string REGEX_PLEX_ID_FROM_URL = re.compile(r'''metadata%2F(\d+)''') -SAFE_URL_CHARACTERS = "%/:=&?~#+!$,;'@()*[]".encode('utf-8') +SAFE_URL_CHARACTERS = "%/:=&?~#+!$,;'@()*[]" HTTP_DAV_FTP = re.compile(r'(http(s)?|dav(s)?|(s)?ftp)://((.+):(.+)@)?([\w\.]+)(:([\d]+))?/') def garbageCollect(): @@ -332,35 +332,24 @@ def extend_url(url, params): def parse_qs(qs, keep_blank_values=0, strict_parsing=0): """ - unicode-safe way to use urlparse.parse_qs(). Pass in the query string qs - either as str or unicode - Returns a dict with lists as values; all entires unicode + Pass in the query string qs as string. Returns a dict with lists as values + as unicode """ - if isinstance(qs, str): - qs = qs.encode('utf-8') - qs = _urlparse.parse_qs(qs, keep_blank_values, strict_parsing) - return {k.decode('utf-8'): [e.decode('utf-8') for e in v] - for k, v in qs.items()} + return _urlparse.parse_qs(qs, keep_blank_values, strict_parsing) def parse_qsl(qs, keep_blank_values=0, strict_parsing=0): """ - unicode-safe way to use urlparse.parse_qsl(). Pass in either str or unicode - Returns a list of unicode tuples + Pass in string. Returns a list of string tuples """ - if isinstance(qs, str): - qs = qs.encode('utf-8') - qs = _urlparse.parse_qsl(qs, keep_blank_values, strict_parsing) - return [(x.decode('utf-8'), y.decode('utf-8')) for (x, y) in qs] + return _urlparse.parse_qsl(qs, keep_blank_values, strict_parsing) def urlparse(url, scheme='', allow_fragments=True): """ - unicode-safe way to use urlparse.urlparse(). Pass in either str or unicode + Pass in string. CAREFUL: returns an encoded urlparse.ParseResult()! """ - if isinstance(url, str): - url = url.encode('utf-8') return _urlparse.urlparse(url, scheme, allow_fragments) diff --git a/resources/lib/windows/direct_path_sources.py b/resources/lib/windows/direct_path_sources.py index 48716ddb..d7baa287 100644 --- a/resources/lib/windows/direct_path_sources.py +++ b/resources/lib/windows/direct_path_sources.py @@ -76,7 +76,7 @@ def start(): hostname = utils.dialog('input', utils.lang(30201)) if not hostname: return - hostname = hostname.decode('utf-8').strip() + hostname = hostname.strip() if not is_valid_hostname(hostname) and not is_valid_ip(hostname): LOG.error('Entered invalid hostname or IP: %s', hostname) # "The hostname or IP '{0}' that you entered is not valid" @@ -90,7 +90,7 @@ def start(): protocol = utils.dialog('input', utils.lang(30203)) if not protocol: return - protocol = protocol.decode('utf-8').lower().strip() + protocol = protocol.lower().strip() if protocol not in SUPPORTED_PROTOCOLS: LOG.error('Entered invalid protocol %s', protocol) # "The protocol '{0}' that you entered is not supported."