Exemple #1
0
 def _parse_categories( self, xmlSource, category ):
     try:
         # encoding
         encoding = re.findall( "<\?xml version=\"[^\"]*\" encoding=\"([^\"]*)\"\?>", xmlSource[ 0 ] )[ 0 ]
         # gather all trailer records <movieinfo>
         trailers = re.findall( "<movieinfo id=\".+?\"><info>.+?<studio>(.*?)</studio>.+?<director>(.*?)</director>.+?(?:<cast>(.+?)</cast>)?<genre>(.+?)</genre>.+?</movieinfo>", xmlSource[ 0 + ( 2 * ( self.settings[ "trailer_quality" ] > 1 and self.settings[ "trailer_hd_only" ] ) ) ] )
         # use dictionary method to filter out duplicates; set our item list
         dupes = {}
         # enumerate thru the trailers list and create our category list
         for studio, directors, actors, genres in trailers:
             # genres category
             if ( category == "genres" ):
                 # parse genres 
                 genres = re.findall( "<name>(.+?)</name>", genres )
                 # filter out duplicates
                 for x in genres:
                     dupes[ x ] = ( x, "DefaultGenre.png", None, )
             elif ( category == "studios" ):
                 # filter out duplicates
                 dupes[ studio ] = ( studio, "DefaultStudios.png", None, )
             elif ( category == "directors" ):
                 # parse directors 
                 directors = directors.split( ", " )
                 # filter out duplicates
                 for x in directors:
                     dupes[ x ] = ( x, "DefaultDirector.png", None, )
             elif ( category == "actors" ):
                 # parse actors 
                 actors = re.findall( "<name>(.+?)</name>", actors )
                 # filter out duplicates
                 for x in actors:
                     dupes[ x ] = ( x, "DefaultActor.png", "special://profile/Thumbnails/Video/%s/%s" % ( xbmc.getCacheThumbName( "actor" + x )[ 0 ], xbmc.getCacheThumbName( "actor" + x ) ,), )
         # grap the categories
         categories = dupes.values()
         # sort our list
         categories.sort()
         # get our media item
         dirItem = DirectoryItem()
         # set total items
         dirItem.totalItems = len( categories )
         # set as folder since these our virtual folders to filtered lists
         dirItem.isFolder = True
         # add settings menu item
         dirItem.addContextMenuItem( "", "DUMMY TO CLEAR CONTEXT MENU" )
         # enumerate thru and add our items
         for title, icon, thumb in categories:
             # check for cached thumb (only actors)
             if ( thumb is None or not os.path.isfile( thumb ) ):
                 thumb = icon
             # create our listitem
             dirItem.listitem = xbmcgui.ListItem( title, iconImage=icon, thumbnailImage=thumb )
             # set the url
             dirItem.url = "%s?category=%s" % ( sys.argv[ 0 ], urllib.quote_plus( repr( "%s: %s" % ( category, unicode( title, "utf-8" ), ) ) ), )
             # add item
             self.MediaWindow.add( dirItem )
     except Exception, e:
         # oops, notify user what error occurred
         LOG( str( e ), xbmc.LOGERROR )
Exemple #2
0
 def _add_video( self, video ):
     try:
         # get our media item
         dirItem = DirectoryItem()
         # set the default icon
         icon = "DefaultVideo.png"
         # set an overlay if one is practical
         overlay = ( xbmcgui.ICON_OVERLAY_NONE, xbmcgui.ICON_OVERLAY_HD, )[ "720p." in video[ "trailer" ] or "1080p." in video[ "trailer" ] ]
         # only need to add label and thumbnail, setInfo() and addSortMethod() takes care of label2
         dirItem.listitem = xbmcgui.ListItem( video[ "title" ], iconImage=icon, thumbnailImage=video[ "poster" ] )
         # release date and year
         try:
             # format the date
             release_date = datetime.date( int( video[ "releasedate" ].split( "-" )[ 0 ] ), int( video[ "releasedate" ].split( "-" )[ 1 ] ), int( video[ "releasedate" ].split( "-" )[ 2 ] ) ).strftime( self.date_format )
             # we need just year also
             year = int( video[ "releasedate" ].split( "-" )[ 0 ] )
         except:
             release_date = ""
             year = 0
         # set the key information
         dirItem.listitem.setInfo( "video", { "Title": video[ "title" ], "Overlay": overlay, "Size": video[ "size" ], "Year": year, "Plot": video[ "plot" ], "PlotOutline": video[ "plot" ], "MPAA": video[ "mpaa" ], "Genre": video[ "genre" ], "Studio": video[ "studio" ], "Director": video[ "director" ], "Duration": video[ "duration" ], "Cast": video[ "cast" ], "Date": "%s-%s-%s" % ( video[ "postdate" ][ 8 : ], video[ "postdate" ][ 5 : 7 ], video[ "postdate" ][ : 4 ], ) } )
         # set release date property
         dirItem.listitem.setProperty( "releasedate", release_date )
         # get filepath and tmp_filepath
         tmp_path, filepath = get_legal_filepath( video[ "title" ], video[ "trailer" ].split( "?|" )[ 0 ], 2, self.settings[ "download_path" ], self.settings[ "use_title" ], self.settings[ "use_trailer" ] )
         # set theater showtimes menu item
         dirItem.addContextMenuItem( 30900, "XBMC.RunPlugin(%s?showtimes=%s)" % ( sys.argv[ 0 ], urllib.quote_plus( repr( video[ "title" ] ) ), ) )
         # check if trailer already exists if user specified
         if ( self.settings[ "play_existing" ] and os.path.isfile( filepath.encode( "utf-8" ) ) ):
             dirItem.url = filepath
             # just add play trailer if trailer exists and user preference to always play existing
             dirItem.addContextMenuItem( 30920, "XBMC.PlayMedia(%s,noresume)" % ( dirItem.url, ) )
         elif ( self.settings[ "play_mode" ] == 0 ):
             dirItem.url = video[ "trailer" ]
             # we want both play and download if user preference is to stream
             dirItem.addContextMenuItem( 30910, "XBMC.RunPlugin(%s?download=%s)" % ( sys.argv[ 0 ], urllib.quote_plus( video[ "trailer" ].split( "?|" )[ 0 ] ), ) )
             dirItem.addContextMenuItem( 30920, "XBMC.PlayMedia(%s,noresume)" % ( dirItem.url, ) )
         else:
             dirItem.url = "%s?download=%s" % ( sys.argv[ 0 ], urllib.quote_plus( video[ "trailer" ].split( "?|" )[ 0 ] ) )
             # only add download if user prefernce is not stream
             dirItem.addContextMenuItem( 30910, "XBMC.RunPlugin(%s?download=%s)" % ( sys.argv[ 0 ], urllib.quote_plus( video[ "trailer" ].split( "?|" )[ 0 ] ), ) )
         # add the movie information item
         dirItem.addContextMenuItem( 30930, "XBMC.Action(Info)" )
         # add settings menu item
         dirItem.addContextMenuItem( 1045, "XBMC.RunPlugin(%s?settings=open)" % ( sys.argv[ 0 ], ) )
         # add the item to the media list
         return self.MediaWindow.add( dirItem )
     except Exception, e:
         # oops, notify user what error occurred
         LOG( str( e ), xbmc.LOGERROR )