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
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', '')

View file

@ -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'

View file

@ -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):
"""

View file

@ -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:

View file

@ -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

View file

@ -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):

View file

@ -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 = {

View file

@ -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')

View file

@ -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):

View file

@ -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,

View file

@ -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):

View file

@ -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

View file

@ -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)

View file

@ -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."