diff --git a/main.py b/main.py index ca9471a..29bbe8f 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,17 @@ #Copyright primaeval - but you can use it for free if you can be nice to someone all day :) -from rpc import RPC +from rpc import RPC, PY3 from xbmcswift2 import Plugin import re import requests import xbmc,xbmcaddon,xbmcvfs,xbmcgui import xbmcplugin import base64 -import urllib import zipfile +if PY3: + import urllib.parse +else: + import urllib plugin = Plugin() big_list_view = False @@ -328,7 +331,10 @@ def add_folder(path): folder_name = d.input("New Folder") if not folder_name: return - quoted_folder_name = urllib.quote(folder_name,safe='') + if PY3: + quoted_folder_name = urllib.parse.quote(folder_name,safe='') + else: + quoted_folder_name = urllib.quote(folder_name,safe='') path = "%s%s/" % (path,quoted_folder_name) xbmcvfs.mkdirs(path) folder_icon = get_icon_path('folder') @@ -358,11 +364,17 @@ def remove_folder(path): @plugin.route('/rename_folder//') def rename_folder(path,name): d = xbmcgui.Dialog() - unquoted_name = urllib.unquote(name) + if PY3: + unquoted_name = urllib.parse.unquote(name) + else: + unquoted_name = urllib.unquote(name) new_name = d.input("New Name for: %s" % unquoted_name,unquoted_name) if not new_name: return - quoted_new_name = urllib.quote(new_name,safe='') + if PY3: + quoted_new_name = urllib.parse.quote(new_name,safe='') + else: + quoted_new_name = urllib.quote(new_name,safe='') old_folder = "%s%s/" % (path,name) new_folder = "%s%s/" % (path,quoted_new_name) xbmcvfs.rename(old_folder,new_folder) @@ -605,7 +617,10 @@ def index_of(path=None): context_items.append(("[COLOR yellow][B]%s[/B][/COLOR] " % 'Change Fanart', 'XBMC.RunPlugin(%s)' % (plugin.url_for(change_folder_fanart, path=folder_path)))) context_items.append(("[COLOR yellow][B]%s[/B][/COLOR] " % 'Change Colour', 'XBMC.RunPlugin(%s)' % (plugin.url_for(change_folder_colour, path=folder_path)))) context_items.append(("[COLOR yellow][B]%s[/B][/COLOR] " % 'Set Password', 'XBMC.RunPlugin(%s)' % (plugin.url_for(set_password, path=folder_path)))) - label = urllib.unquote(folder) + if PY3: + label = urllib.parse.unquote(folder) + else: + label = urllib.unquote(folder) if colour: label = "[COLOR %s]%s[/COLOR]" % (colour,remove_formatting(label)) item = { diff --git a/rpc.py b/rpc.py index cc99eab..918ec59 100644 --- a/rpc.py +++ b/rpc.py @@ -1,3 +1,9 @@ +import sys +PY3 = sys.version_info.major >= 3 + +if PY3: + from builtins import str, object + import json #from xbmcswift2 import xbmc import xbmc @@ -6,8 +12,12 @@ class RPCType(type): def __getattr__(cls, category): return Category(category) -class RPC(object): - __metaclass__ = RPCType +if PY3: + class RPC(object, metaclass=RPCType): + pass +else: + class RPC(object): + __metaclass__ = RPCType class Category(object): def __init__(self, name): @@ -43,9 +53,12 @@ def json_query(query): query["id"] = 1 xbmc_request = json.dumps(query) - raw = xbmc.executeJSONRPC(xbmc_request) - clean = unicode(raw, 'utf-8', errors='ignore') - response = json.loads(clean) + if PY3: + response = json.loads(xbmc.executeJSONRPC(xbmc_request)) + else: + raw = xbmc.executeJSONRPC(xbmc_request) + clean = unicode(raw, 'utf-8', errors='ignore') + response = json.loads(clean) if "error" in response: raise RPCError(response["error"]) return response.get('result', response)