Skip to content

Commit bedeed1

Browse files
committed
dropped Py2 support
1 parent f8aaaa8 commit bedeed1

8 files changed

Lines changed: 45 additions & 99 deletions

File tree

addon.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="plugin.library.node.editor" name="Library Node Editor" version="1.0.11" provider-name="Unfledged, Team-Kodi">
2+
<addon id="plugin.library.node.editor" name="Library Node Editor" version="2.0.0" provider-name="Unfledged, Team-Kodi">
33
<requires>
4-
<import addon="xbmc.python" version="2.25.0"/>
4+
<import addon="xbmc.python" version="3.0.0"/>
55
<import addon="script.module.unidecode" version="0.4.16"/>
66
</requires>
77
<extension point="xbmc.python.pluginsource" library="plugin.py">

resources/lib/addon.py

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@
33

44
from resources.lib.common import *
55

6-
PY3 = sys.version_info.major >= 3
7-
8-
if PY3:
9-
from html.entities import name2codepoint
10-
from urllib.parse import parse_qs
11-
from urllib.parse import quote, unquote
12-
else:
13-
from htmlentitydefs import name2codepoint
14-
from urlparse import parse_qs
15-
from urllib import quote, unquote
6+
from html.entities import name2codepoint
7+
from urllib.parse import parse_qs
8+
from urllib.parse import quote, unquote
169

1710
import xbmc, xbmcplugin, xbmcgui, xbmcvfs
1811
import xml.etree.ElementTree as xmltree
@@ -51,11 +44,11 @@ def __init__(self, params, ltype, rule, attrib, pathrule, orderby):
5144
self.PATHRULE = pathrule
5245
self.ORDERBY = orderby
5346
# If there are no custom library nodes in the profile directory, copy them from the Kodi install
54-
targetDir = os.path.join( xbmc.translatePath( "special://profile" if PY3 else "special://profile".decode('utf-8') ), "library", ltype )
47+
targetDir = os.path.join( xbmc.translatePath( "special://profile" ), "library", ltype )
5548
if True:
5649
if not os.path.exists( targetDir ):
5750
xbmcvfs.mkdirs( targetDir )
58-
originDir = os.path.join( xbmc.translatePath( "special://xbmc" if PY3 else "special://xbmc".decode( "utf-8" ) ), "system", "library", ltype )
51+
originDir = os.path.join( xbmc.translatePath( "special://xbmc" ), "system", "library", ltype )
5952
dirs, files = xbmcvfs.listdir( originDir )
6053
self.copyNode( dirs, files, targetDir, originDir )
6154
else:
@@ -98,7 +91,7 @@ def __init__(self, params, ltype, rule, attrib, pathrule, orderby):
9891
keyboard = xbmc.Keyboard( label, LANGUAGE( 30300 ), False )
9992
keyboard.doModal()
10093
if ( keyboard.isConfirmed() ):
101-
newlabel = keyboard.getText() if PY3 else keyboard.getText().decode( "utf-8" )
94+
newlabel = keyboard.getText()
10295
if newlabel != "" and newlabel != label:
10396
# We've got a new label, update the xml file
10497
self.changeViewElement( self.PARAMS[ "actionPath" ], "label", newlabel )
@@ -139,7 +132,7 @@ def __init__(self, params, ltype, rule, attrib, pathrule, orderby):
139132
keyboard = xbmc.Keyboard( "", LANGUAGE( 30316 ), False )
140133
keyboard.doModal()
141134
if ( keyboard.isConfirmed() ):
142-
newView = keyboard.getText() if PY3 else keyboard.getText().decode( "utf-8" )
135+
newView = keyboard.getText()
143136
if newView != "":
144137
# Ensure filename is unique
145138
filename = self.slugify( newView.lower().replace( " ", "" ) )
@@ -168,7 +161,7 @@ def __init__(self, params, ltype, rule, attrib, pathrule, orderby):
168161
keyboard = xbmc.Keyboard( "", LANGUAGE( 30303 ), False )
169162
keyboard.doModal()
170163
if ( keyboard.isConfirmed() ):
171-
newNode = keyboard.getText() if PY3 else keyboard.getText().decode( "utf8" )
164+
newNode = keyboard.getText()
172165
if newNode == "":
173166
return
174167
# Ensure foldername is unique
@@ -196,7 +189,7 @@ def __init__(self, params, ltype, rule, attrib, pathrule, orderby):
196189
if selected != -1 and selected != 0:
197190
try:
198191
# Copy those defaults across
199-
originDir = os.path.join( xbmc.translatePath( "special://xbmc" if PY3 else "special://xbmc".decode( "utf-8" ) ), "system", "library", self.ltype, defaultValues[ selected ] )
192+
originDir = os.path.join( xbmc.translatePath( "special://xbmc" ), "system", "library", self.ltype, defaultValues[ selected ] )
200193
dirs, files = xbmcvfs.listdir( originDir )
201194
for file in files:
202195
if file != "index.xml":
@@ -519,12 +512,12 @@ def _parse_argv( self ):
519512
try:
520513
p = parse_qs(sys.argv[2][1:])
521514
for i in p.keys():
522-
p[i] = p[i][0] if PY3 else p[i][0].decode( "utf-8" )
515+
p[i] = p[i][0]
523516
self.PARAMS = p
524517
except:
525518
p = parse_qs(sys.argv[1])
526519
for i in p.keys():
527-
p[i] = p[i][0] if PY3 else p[i][0].decode( "utf-8" )
520+
p[i] = p[i][0]
528521
self.PARAMS = p
529522
if "path" in self.PARAMS:
530523
self.PATH = self.PARAMS[ "path" ]
@@ -541,7 +534,7 @@ def getRules( self, actionPath, justRules = False ):
541534
# Look for a 'content'
542535
content = root.find( "content" )
543536
if content is not None:
544-
returnVal.append( ( "content", content.text if PY3 else content.text.decode( "utf-8" ) ) )
537+
returnVal.append( ( "content", content.text ) )
545538
# Look for an 'order'
546539
order = root.find( "order" )
547540
if order is not None:
@@ -608,7 +601,7 @@ def listNodes( self, targetDir, nodes ):
608601
for dir in dirs:
609602
self.parseNode( os.path.join( targetDir, dir ), nodes )
610603
for file in files:
611-
self.parseItem( os.path.join( targetDir, file if PY3 else file.decode( "utf-8" ) ), nodes )
604+
self.parseItem( os.path.join( targetDir, file ), nodes )
612605

613606
def parseNode( self, node, nodes ):
614607
# If the folder we've been passed contains an index.xml, send that file to be processed
@@ -646,7 +639,7 @@ def parseItem( self, file, nodes, isFolder = False, origFolder = None ):
646639
icon = ""
647640
# Add it to our list of nodes
648641
if isFolder:
649-
nodes[ int( index ) ] = [ label, icon, quote( origFolder if PY3 else origFolder.decode( "utf-8" ) ), "folder", origIndex ]
642+
nodes[ int( index ) ] = [ label, icon, quote( origFolder ), "folder", origIndex ]
650643
else:
651644
nodes[ int( index ) ] = [ label, icon, file, "item", origIndex ]
652645
except:
@@ -777,14 +770,8 @@ def slugify(self, text, entities=True, decimal=True, hexadecimal=True, max_lengt
777770
# Handle integers
778771
if convertInteger and text.isdigit():
779772
text = "NUM-" + text
780-
# text to unicode
781-
if not PY3 and type(text) != types.UnicodeType:
782-
text = unicode(text, 'utf-8', 'ignore')
783773
# decode unicode ( ??? = Ying Shi Ma)
784774
text = unidecode(text)
785-
# text back to unicode
786-
if not PY3 and type(text) != types.UnicodeType:
787-
text = unicode(text, 'utf-8', 'ignore')
788775
# character entity reference
789776
if entities:
790777
text = CHAR_ENTITY_REXP.sub(lambda m: unichr(name2codepoint[m.group(1)]), text)
@@ -818,8 +805,6 @@ def slugify(self, text, entities=True, decimal=True, hexadecimal=True, max_lengt
818805

819806
def getVideoLibraryLType():
820807
json_query = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "id": 0, "method": "Settings.GetSettingValue", "params": {"setting": "myvideos.flatten"}}')
821-
if not PY3:
822-
json_query = unicode(json_query, 'utf-8', errors='ignore')
823808
json_response = json.loads(json_query)
824809

825810
if json_response.get('result') and json_response['result'].get('value'):

resources/lib/common.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,15 @@
33
import os
44
import xbmc, xbmcaddon
55

6-
PY3 = sys.version_info.major >= 3
7-
8-
96
ADDON = xbmcaddon.Addon()
10-
ADDONID = ADDON.getAddonInfo('id') if PY3 else ADDON.getAddonInfo('id').decode( 'utf-8' )
7+
ADDONID = ADDON.getAddonInfo('id')
118
ADDONVERSION = ADDON.getAddonInfo('version')
129
LANGUAGE = ADDON.getLocalizedString
13-
CWD = ADDON.getAddonInfo('path') if PY3 else ADDON.getAddonInfo('path').decode("utf-8")
14-
ADDONNAME = ADDON.getAddonInfo('name') if PY3 else ADDON.getAddonInfo('name').decode("utf-8")
15-
DATAPATH = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile')) if PY3 else xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile')).decode('utf-8')
10+
CWD = ADDON.getAddonInfo('path')
11+
ADDONNAME = ADDON.getAddonInfo('name')
12+
DATAPATH = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile'))
1613
DEFAULTPATH = os.path.join( CWD, 'resources' )
1714

1815
def log(txt):
19-
if isinstance (txt,str):
20-
if not PY3:
21-
txt = txt.decode('utf-8')
2216
message = u'%s: %s' % (ADDONID, txt)
23-
xbmc.log(msg=message if PY3 else message.encode("utf-8"), level=xbmc.LOGDEBUG)
24-
25-
def six_decoder(item):
26-
if PY3:
27-
return item
28-
return item.decode("utf-8")
17+
xbmc.log(msg=message, level=xbmc.LOGDEBUG)

resources/lib/orderby.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
import xbmc, xbmcaddon, xbmcplugin, xbmcgui, xbmcvfs
44
import xml.etree.ElementTree as xmltree
55
from traceback import print_exc
6+
from urllib.parse import unquote
67

78
from resources.lib.common import *
89

9-
if PY3:
10-
from urllib.parse import unquote
11-
else:
12-
from urllib import unquote
13-
1410
class OrderByFunctions():
1511
def __init__(self, ltype):
1612
self.ltype = ltype

resources/lib/pathrules.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
import os, sys, shutil
33
import xbmc, xbmcaddon, xbmcplugin, xbmcgui, xbmcvfs
44
import xml.etree.ElementTree as xmltree
5-
from traceback import print_exc
65
import json
6+
from traceback import print_exc
7+
from urllib.parse import quote, unquote
78

89
from resources.lib.common import *
910

10-
if PY3:
11-
from urllib.parse import quote, unquote
12-
else:
13-
from urllib import quote, unquote
14-
1511
class PathRuleFunctions():
1612
def __init__(self, ltype):
1713
self.nodeRules = None
@@ -32,7 +28,7 @@ def _load_rules( self ):
3228
def translateComponent( self, component, splitPath ):
3329
if component[ 0 ] is None:
3430
return splitPath[ 0 ]
35-
if (not PY3 and unicode( component[0], "utf-8" ).isnumeric()) or (PY3 and component[0].isdigit()):
31+
if component[0].isdigit():
3632
string = LANGUAGE( int( component[ 0 ] ) )
3733
if string != "": return string
3834
return xbmc.getLocalizedString( int( component[ 0 ] ) )
@@ -52,8 +48,6 @@ def translateValue( self, rule, splitPath, ruleNum ):
5248
return splitPath[ ruleNum ][ 1 ]
5349

5450
json_query = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "id": 0, "method": "Files.GetDirectory", "params": { "properties": ["title"], "directory": "%s", "media": "files" } }' % rule[ 3 ] )
55-
if not PY3:
56-
json_query = unicode(json_query, 'utf-8', errors='ignore')
5751
json_response = json.loads(json_query)
5852
listings = []
5953
values = []
@@ -238,7 +232,7 @@ def editValue( self, actionPath, ruleNum ):
238232
type = xbmcgui.INPUT_NUMERIC
239233
returnVal = xbmcgui.Dialog().input( LANGUAGE( 30307 ), splitPath[ ruleNum ][ 1 ], type=type )
240234
if returnVal != "":
241-
self.ATTRIB.writeUpdatedPath( actionPath, ( ruleNum, splitPath[ ruleNum ][ 0 ], six_decoder(returnVal) ) )
235+
self.ATTRIB.writeUpdatedPath( actionPath, ( ruleNum, splitPath[ ruleNum ][ 0 ], returnVal ) )
242236

243237

244238
def browse( self, actionPath, ruleNum ):
@@ -263,8 +257,6 @@ def browse( self, actionPath, ruleNum ):
263257
browsePath = self.getBrowsePath( splitPath, rule[ 3 ], ruleNum )
264258

265259
json_query = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "id": 0, "method": "Files.GetDirectory", "params": { "properties": ["title", "file", "thumbnail"], "directory": "%s", "media": "files" } }' % browsePath )
266-
if not PY3:
267-
json_query = unicode(json_query, 'utf-8', errors='ignore')
268260
json_response = json.loads(json_query)
269261
listings = []
270262
values = []
@@ -320,10 +312,10 @@ def getBrowsePath( self, splitPath, newBase, rule ):
320312
if x == 0:
321313
returnText = newBase
322314
elif not addedQ:
323-
returnText += "?%s=%s" %( component[ 0 ], six_decoder(quote(component[1] if PY3 else component[1].encode( "utf-8" ))) )
315+
returnText += "?%s=%s" %( component[ 0 ], quote(component[1]) )
324316
addedQ = True
325317
else:
326-
returnText += "&%s=%s" %( component[ 0 ], six_decoder(quote(component[1] if PY3 else component[1].encode( "utf-8" ))) )
318+
returnText += "&%s=%s" %( component[ 0 ], quote(component[1]) )
327319
return returnText
328320

329321
# in-place prettyprint formatter

resources/lib/pluginBrowser.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ def getPluginPath( ltype, location = None ):
2626
dialog.create( ADDONNAME, LANGUAGE( 30410 ) )
2727

2828
json_query = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "id": 0, "method": "Files.GetDirectory", "params": { "properties": ["title", "file", "thumbnail", "episode", "showtitle", "season", "album", "artist", "imdbnumber", "firstaired", "mpaa", "trailer", "studio", "art"], "directory": "' + location + '", "media": "files" } }')
29-
if not PY3:
30-
json_query = unicode(json_query, 'utf-8', errors='ignore')
3129
json_response = json.loads(json_query)
3230

3331
# Add all directories returned by the json query

resources/lib/rules.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
import os, sys, shutil
33
import xbmc, xbmcaddon, xbmcplugin, xbmcgui, xbmcvfs
44
import xml.etree.ElementTree as xmltree
5-
from traceback import print_exc
65
import json
6+
from traceback import print_exc
7+
from urllib.parse import quote, unquote
78

89
from resources.lib.common import *
910

10-
if PY3:
11-
from urllib.parse import quote, unquote
12-
else:
13-
from urllib import quote, unquote
14-
15-
1611
class RuleFunctions():
1712
def __init__(self, ltype):
1813
self.nodeRules = None
@@ -240,7 +235,7 @@ def editValue( self, actionPath, ruleNum ):
240235
type = xbmcgui.INPUT_ALPHANUM
241236
returnVal = xbmcgui.Dialog().input( LANGUAGE( 30307 ), curValue, type=type )
242237
if returnVal != "":
243-
self.writeUpdatedRule( unquote(actionPath), ruleNum, value=returnVal if PY3 else returnVal.decode( "utf-8" ) )
238+
self.writeUpdatedRule( unquote(actionPath), ruleNum, value=returnVal )
244239
except:
245240
print_exc()
246241

@@ -950,7 +945,7 @@ def browse( self, actionPath, ruleNum, match, content = None ):
950945
returnVal = self.browser( self.niceMatchName( match ) )
951946
try:
952947
# Delete any fake node
953-
xbmcvfs.delete( os.path.join( xbmc.translatePath( "special://profile" if PY3 else "special://profile".decode('utf-8') ), "library", self.ltype, "plugin.library.node.editor", "temp.xml" ) )
948+
xbmcvfs.delete( os.path.join( xbmc.translatePath( "special://profile" ), "library", self.ltype, "plugin.library.node.editor", "temp.xml" ) )
954949
except:
955950
print_exc()
956951
self.writeUpdatedRule( actionPath, ruleNum, value = returnVal )
@@ -966,7 +961,7 @@ def niceMatchName( self, match ):
966961

967962
def createBrowseNode( self, content, grouping = None ):
968963
# This function creates a fake node which we'll use for browsing
969-
targetDir = os.path.join( xbmc.translatePath( "special://profile" if PY3 else "special://profile".decode('utf-8') ), "library", self.ltype, "plugin.library.node.editor" )
964+
targetDir = os.path.join( xbmc.translatePath( "special://profile" ), "library", self.ltype, "plugin.library.node.editor" )
970965
if not os.path.exists( targetDir ):
971966
xbmcvfs.mkdirs( targetDir )
972967
# Create a new etree
@@ -987,8 +982,6 @@ def createBrowseNode( self, content, grouping = None ):
987982
def browser( self, title ):
988983
# Browser instance used by majority of browses
989984
json_query = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "id": 0, "method": "Files.GetDirectory", "params": { "properties": ["title", "file", "genre", "studio", "director", "thumbnail"], "directory": "library://%s/plugin.library.node.editor/temp.xml", "media": "files" } }' % self.ltype)
990-
if not PY3:
991-
json_query = unicode(json_query, 'utf-8', errors='ignore')
992985
json_response = json.loads(json_query)
993986
listings = []
994987
values = []
@@ -1035,8 +1028,6 @@ def browser( self, title ):
10351028
def browserPlaylist( self, title ):
10361029
# Browser instance used by playlists
10371030
json_query = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "id": 0, "method": "Files.GetDirectory", "params": { "properties": ["title", "file", "thumbnail"], "directory": "special://%splaylists/", "media": "files" } }' % self.ltype)
1038-
if not PY3:
1039-
json_query = unicode(json_query, 'utf-8', errors='ignore')
10401031
json_response = json.loads(json_query)
10411032
listings = []
10421033
values = []

0 commit comments

Comments
 (0)