1515# Package imports
1616from codequick .script import Script
1717from codequick .support import auto_sort , build_path , logger_id , dispatcher
18- from codequick .utils import ensure_unicode , ensure_native_str , unicode_type , long_type
18+ from codequick .utils import ensure_unicode , ensure_native_str , unicode_type , PY3
1919
20- __all__ = ["Listitem" , "Art" , "Info" , "Stream" , "Context" , "Property" , "Params" ]
20+ __all__ = ["Listitem" ]
2121
2222# Logger specific to this module
2323logger = logging .getLogger ("%s.listitem" % logger_id )
4040
4141# Listing sort methods & sort mappings.
4242# Skips infolables that have no sortmethod and type is string. As by default they will be string anyway
43+ # noinspection PyUnresolvedReferences
4344infolable_map = {"artist" : (None , xbmcplugin .SORT_METHOD_ARTIST_IGNORE_THE ),
4445 "studio" : (ensure_native_str , xbmcplugin .SORT_METHOD_STUDIO_IGNORE_THE ),
4546 "title" : (ensure_native_str , xbmcplugin .SORT_METHOD_TITLE_IGNORE_THE ),
5556 "country" : (ensure_native_str , xbmcplugin .SORT_METHOD_COUNTRY ),
5657 "genre" : (None , xbmcplugin .SORT_METHOD_GENRE ),
5758 "date" : (ensure_native_str , xbmcplugin .SORT_METHOD_DATE ),
58- "size" : (long_type , xbmcplugin .SORT_METHOD_SIZE ),
59+ "size" : (int if PY3 else long , xbmcplugin .SORT_METHOD_SIZE ),
5960 "sortepisode" : (int , None ),
6061 "sortseason" : (int , None ),
6162 "userrating" : (int , None ),
@@ -94,7 +95,10 @@ def __getitem__(self, key):
9495 return value .decode ("utf8" ) if isinstance (value , bytes ) else value
9596
9697 def __setitem__ (self , key , value ):
97- self .raw_dict [key ] = value
98+ if isinstance (value , bytes ):
99+ self .raw_dict [key ] = value .decode ("utf8" )
100+ else :
101+ self .raw_dict [key ] = value
98102
99103 def __delitem__ (self , key ): # type: (str) -> None
100104 del self .raw_dict [key ]
@@ -175,11 +179,14 @@ def global_thumb(self, image):
175179 # So there is no neeed to use ensure_native_str
176180 self .raw_dict ["thumb" ] = global_image .format (image )
177181
178- def _close (self ):
182+ def _close (self , isfolder ):
179183 if fanart and "fanart" not in self .raw_dict : # pragma: no branch
180184 self .raw_dict ["fanart" ] = fanart
181185 if "thumb" not in self .raw_dict : # pragma: no branch
182186 self .raw_dict ["thumb" ] = icon
187+ if "icon" not in self .raw_dict : # pragma: no branch
188+ self .raw_dict ["icon" ] = "DefaultFolder.png" if isfolder else "DefaultVideo.png"
189+
183190 self ._listitem .setArt (self .raw_dict )
184191
185192
@@ -300,7 +307,12 @@ def _duration(duration):
300307 return duration
301308
302309 def _close (self , content_type ):
303- self ._listitem .setInfo (content_type , self .raw_dict )
310+ raw_dict = self .raw_dict
311+ # Add label as plot if no plot is found
312+ if "plot" not in raw_dict : # pragma: no branch
313+ raw_dict ["plot" ] = raw_dict ["title" ]
314+
315+ self ._listitem .setInfo (content_type , raw_dict )
304316
305317
306318class Property (Params ):
@@ -527,7 +539,7 @@ def __init__(self, content_type="video"):
527539
528540 self .params = Params ()
529541 """
530- Dictionary like object for parameters that will be passed to the "callback" object .
542+ Dictionary like object for parameters that will be passed to the "callback" function .
531543
532544 :example:
533545 >>> item = Listitem()
@@ -556,7 +568,8 @@ def label(self): # type: () -> str
556568 >>> item = Listitem()
557569 >>> item.label = "Video Title"
558570 """
559- return ensure_unicode (self .listitem .getLabel ())
571+ label = self .listitem .getLabel ()
572+ return label .decode ("utf8" ) if isinstance (label , bytes ) else label
560573
561574 @label .setter
562575 def label (self , label ): # type: (str) -> None
@@ -596,15 +609,7 @@ def _close(self):
596609 path = callback
597610 isfolder = False
598611
599- if isfolder :
600- # Set Kodi icon image if not already set
601- if "icon" not in self .art .raw_dict : # pragma: no branch
602- self .art .raw_dict ["icon" ] = "DefaultFolder.png"
603- else :
604- # Set Kodi icon image if not already set
605- if "icon" not in self .art .raw_dict : # pragma: no branch
606- self .art .raw_dict ["icon" ] = "DefaultVideo.png"
607-
612+ if not isfolder :
608613 # Add mediatype if not already set
609614 if "mediatype" not in self .info .raw_dict and self ._content_type in ("video" , "music" ): # pragma: no branch
610615 self .info .raw_dict ["mediatype" ] = self ._content_type
@@ -616,21 +621,16 @@ def _close(self):
616621 # Close video related datasets
617622 self .stream ._close ()
618623
619- label = self .label
620624 # Set label to UNKNOWN if unset
621- if not label : # pragma: no branch
622- self .label = label = u"UNKNOWN"
623-
624- # Add label as plot if no plot is found
625- if "plot" not in self .info : # pragma: no branch
626- self .info ["plot" ] = label
625+ if not self .label : # pragma: no branch
626+ self .label = u"UNKNOWN"
627627
628628 # Close common datasets
629629 self .listitem .setPath (path )
630630 self .property ._close ()
631631 self .context ._close ()
632632 self .info ._close (self ._content_type )
633- self .art ._close ()
633+ self .art ._close (isfolder )
634634
635635 # Return a tuple compatible with 'xbmcplugin.addDirectoryItems'
636636 return path , self .listitem , isfolder
0 commit comments