33
44from 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
1710import xbmc , xbmcplugin , xbmcgui , xbmcvfs
1811import 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
819806def 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' ):
0 commit comments