Remove obsolete encodes and decodes

This commit is contained in:
croneter 2020-12-19 20:43:08 +01:00
parent ab73d3c1fd
commit c22b4c782d
14 changed files with 30 additions and 46 deletions

View file

@ -11,7 +11,6 @@ import xbmcgui
import xbmcplugin import xbmcplugin
from resources.lib import entrypoint, utils, transfer, variables as v, loghandler 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) LOG.debug('Full sys.argv received: %s', argv)
# Parse parameters # Parse parameters
params = dict(parse_qsl(argv[2][1:])) params = dict(parse_qsl(argv[2][1:]))
arguments = unicode_paths.decode(argv[2]) arguments = argv[2]
path = unicode_paths.decode(argv[0]) path = argv[0]
# Ensure unicode
for key, value in params.items():
params[key.decode('utf-8')] = params.pop(key)
params[key] = value.decode('utf-8')
mode = params.get('mode', '') mode = params.get('mode', '')
itemid = params.get('id', '') itemid = params.get('id', '')

View file

@ -108,7 +108,7 @@ class Sync(object):
self.remapSMBphotoOrg = remove_trailing_slash(utils.settings('remapSMBphotoOrg')) self.remapSMBphotoOrg = remove_trailing_slash(utils.settings('remapSMBphotoOrg'))
self.remapSMBphotoNew = remove_trailing_slash(utils.settings('remapSMBphotoNew')) self.remapSMBphotoNew = remove_trailing_slash(utils.settings('remapSMBphotoNew'))
self.escape_path = utils.settings('escapePath') == 'true' 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.indicate_media_versions = utils.settings('indicate_media_versions') == "true"
self.sync_specific_plex_playlists = utils.settings('syncSpecificPlexPlaylists') == 'true' self.sync_specific_plex_playlists = utils.settings('syncSpecificPlexPlaylists') == 'true'
self.sync_specific_kodi_playlists = utils.settings('syncSpecificKodiPlaylists') == 'true' self.sync_specific_kodi_playlists = utils.settings('syncSpecificKodiPlaylists') == 'true'

View file

@ -142,8 +142,8 @@ class ContextMenu(object):
playqueue.clear() playqueue.clear()
app.PLAYSTATE.context_menu_play = True app.PLAYSTATE.context_menu_play = True
handle = self.api.fullpath(force_addon=True)[0] handle = self.api.fullpath(force_addon=True)[0]
handle = 'RunPlugin(%s)' % handle handle = f'RunPlugin({handle})'
xbmc.executebuiltin(handle.encode('utf-8')) xbmc.executebuiltin(handle)
def _extras(self): def _extras(self):
""" """

View file

@ -483,7 +483,7 @@ def browse_plex(key=None, plex_type=None, section_id=None, synched=True,
if prompt is None: if prompt is None:
# User cancelled # User cancelled
return return
prompt = prompt.strip().decode('utf-8') prompt = prompt.strip()
args['query'] = prompt args['query'] = prompt
xml = DU().downloadUrl(utils.extend_url('{server}%s' % key, args)) xml = DU().downloadUrl(utils.extend_url('{server}%s' % key, args))
try: try:

View file

@ -410,7 +410,7 @@ class InitialSetup(object):
utils.messageDialog( utils.messageDialog(
utils.lang(29999), utils.lang(29999),
'%s %s\n%s' % (utils.lang(39013), '%s %s\n%s' % (utils.lang(39013),
server['name'].decode('utf-8'), server['name'],
utils.lang(39014))) utils.lang(39014)))
if self.plex_tv_sign_in() is False: if self.plex_tv_sign_in() is False:
# Exit while loop if user cancels # Exit while loop if user cancels

View file

@ -209,7 +209,7 @@ class KodiMonitor(xbmc.Monitor):
play_info = json.loads(play_info) play_info = json.loads(play_info)
app.APP.player.stop() app.APP.player.stop()
handle = 'RunPlugin(%s)' % play_info.get('handle') handle = 'RunPlugin(%s)' % play_info.get('handle')
xbmc.executebuiltin(handle.encode('utf-8')) xbmc.executebuiltin(handle)
def PlayBackStart(self, data): def PlayBackStart(self, data):
""" """
@ -582,11 +582,11 @@ def _notify_upnext(item):
} }
_complete_artwork_keys(info[key]) _complete_artwork_keys(info[key])
info['play_info'] = {'handle': next_api.fullpath(force_addon=True)[0]} info['play_info'] = {'handle': next_api.fullpath(force_addon=True)[0]}
sender = v.ADDON_ID.encode('utf-8') sender = v.ADDON_ID
method = 'upnext_data'.encode('utf-8') method = 'upnext_data'
data = binascii.hexlify(json.dumps(info)) data = binascii.hexlify(json.dumps(info))
data = '\\"[\\"{0}\\"]\\"'.format(data) data = '\\"[\\"{0}\\"]\\"'.format(data)
xbmc.executebuiltin('NotifyAll(%s, %s, %s)' % (sender, method, data)) xbmc.executebuiltin(f'NotifyAll({sender}, {method}, {data})')
def _videolibrary_onupdate(data): def _videolibrary_onupdate(data):

View file

@ -379,7 +379,7 @@ def audio_subtitle_prefs(api, item):
codec, codec,
channellayout) channellayout)
audio_streams_list.append(index) audio_streams_list.append(index)
audio_streams.append(track.encode('utf-8')) audio_streams.append(track)
audio_numb += 1 audio_numb += 1
# Subtitles # 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(39709)) # Forced
track = "%s (%s)" % (track, utils.lang(39710)) # burn-in track = "%s (%s)" % (track, utils.lang(39710)) # burn-in
subtitle_streams_list.append(index) subtitle_streams_list.append(index)
subtitle_streams.append(track.encode('utf-8')) subtitle_streams.append(track)
sub_num += 1 sub_num += 1
if audio_numb > 1: if audio_numb > 1:
@ -437,7 +437,7 @@ def audio_subtitle_prefs(api, item):
else: else:
LOG.info('User chose to burn-in subtitle %s: %s', LOG.info('User chose to burn-in subtitle %s: %s',
select_subs_index, select_subs_index,
subtitle_streams[resp].decode('utf-8')) subtitle_streams[resp])
select_subs_index = subtitle_streams_list[resp - 1] select_subs_index = subtitle_streams_list[resp - 1]
# Now prep the PMS for our choice # Now prep the PMS for our choice
args = { args = {

View file

@ -795,4 +795,4 @@ def get_plextype_from_xml(xml):
except (TypeError, IndexError, AttributeError): except (TypeError, IndexError, AttributeError):
LOG.error('Could not get plex metadata for plex id %s', plex_id) LOG.error('Could not get plex metadata for plex id %s', plex_id)
return return
return new_xml[0].attrib.get('type').decode('utf-8') return new_xml[0].attrib.get('type')

View file

@ -130,7 +130,7 @@ def kodi_playlist_hash(path):
m = hashlib.md5() m = hashlib.md5()
m.update(repr(stat.st_size)) m.update(repr(stat.st_size))
m.update(repr(stat.st_mtime)) m.update(repr(stat.st_mtime))
return m.hexdigest().decode('utf-8') return m.hexdigest()
class PlaylistQueue(OrderedSetQueue): class PlaylistQueue(OrderedSetQueue):

View file

@ -31,7 +31,7 @@ def external_item_id(title, year, plex_type, collection):
parameters = { parameters = {
'api_key': API_KEY, 'api_key': API_KEY,
'language': v.KODILANGUAGE, 'language': v.KODILANGUAGE,
'query': title.encode('utf-8') 'query': title
} }
data = DU().downloadUrl(url, data = DU().downloadUrl(url,
authenticate=False, authenticate=False,

View file

@ -141,11 +141,11 @@ class PlexCompanion(backgroundthread.KillableThread):
app.CONN.plex_transient_token = data.get('key') app.CONN.plex_transient_token = data.get('key')
params = { params = {
'mode': 'plex_node', 'mode': 'plex_node',
'key': '{server}%s' % data.get('key'), 'key': f"{{server}}{data.get('key')}",
'offset': data.get('offset') 'offset': data.get('offset')
} }
handle = 'RunPlugin(plugin://%s)' % utils.extend_url(v.ADDON_ID, params) handle = f'RunPlugin(plugin://{utils.extend_url(v.ADDON_ID, params)})'
executebuiltin(handle.encode('utf-8')) executebuiltin(handle)
@staticmethod @staticmethod
def _process_playlist(data): def _process_playlist(data):

View file

@ -55,7 +55,7 @@ def ParseContainerKey(containerKey):
Output hence: library, key, query (str, int, dict) Output hence: library, key, query (str, int, dict)
""" """
result = utils.urlparse(containerKey) result = utils.urlparse(containerKey)
library, key = GetPlexKeyNumber(result.path.decode('utf-8')) library, key = GetPlexKeyNumber(result.path)
query = dict(utils.parse_qsl(result.query)) query = dict(utils.parse_qsl(result.query))
return library, key, query return library, key, query

View file

@ -54,7 +54,7 @@ REGEX_MUSICPATH = re.compile(r'''^\^(.+)\$$''')
# Grab Plex id from an URL-encoded string # Grab Plex id from an URL-encoded string
REGEX_PLEX_ID_FROM_URL = re.compile(r'''metadata%2F(\d+)''') 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]+))?/') HTTP_DAV_FTP = re.compile(r'(http(s)?|dav(s)?|(s)?ftp)://((.+):(.+)@)?([\w\.]+)(:([\d]+))?/')
def garbageCollect(): def garbageCollect():
@ -332,35 +332,24 @@ def extend_url(url, params):
def parse_qs(qs, keep_blank_values=0, strict_parsing=0): 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 Pass in the query string qs as string. Returns a dict with lists as values
either as str or unicode as unicode
Returns a dict with lists as values; all entires unicode
""" """
if isinstance(qs, str): return _urlparse.parse_qs(qs, keep_blank_values, strict_parsing)
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()}
def parse_qsl(qs, keep_blank_values=0, strict_parsing=0): 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 Pass in string. Returns a list of string tuples
Returns a list of unicode tuples
""" """
if isinstance(qs, str): return _urlparse.parse_qsl(qs, keep_blank_values, strict_parsing)
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]
def urlparse(url, scheme='', allow_fragments=True): 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()! CAREFUL: returns an encoded urlparse.ParseResult()!
""" """
if isinstance(url, str):
url = url.encode('utf-8')
return _urlparse.urlparse(url, scheme, allow_fragments) return _urlparse.urlparse(url, scheme, allow_fragments)

View file

@ -76,7 +76,7 @@ def start():
hostname = utils.dialog('input', utils.lang(30201)) hostname = utils.dialog('input', utils.lang(30201))
if not hostname: if not hostname:
return return
hostname = hostname.decode('utf-8').strip() hostname = hostname.strip()
if not is_valid_hostname(hostname) and not is_valid_ip(hostname): if not is_valid_hostname(hostname) and not is_valid_ip(hostname):
LOG.error('Entered invalid hostname or IP: %s', hostname) LOG.error('Entered invalid hostname or IP: %s', hostname)
# "The hostname or IP '{0}' that you entered is not valid" # "The hostname or IP '{0}' that you entered is not valid"
@ -90,7 +90,7 @@ def start():
protocol = utils.dialog('input', utils.lang(30203)) protocol = utils.dialog('input', utils.lang(30203))
if not protocol: if not protocol:
return return
protocol = protocol.decode('utf-8').lower().strip() protocol = protocol.lower().strip()
if protocol not in SUPPORTED_PROTOCOLS: if protocol not in SUPPORTED_PROTOCOLS:
LOG.error('Entered invalid protocol %s', protocol) LOG.error('Entered invalid protocol %s', protocol)
# "The protocol '{0}' that you entered is not supported." # "The protocol '{0}' that you entered is not supported."