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 )
    def _add_video( self, video, total ):
        try:
            dirItem = DirectoryItem()
            dirItem.totalItems = total
            # set the default icon
            icon = os.path.join(self.Addon.getAddonInfo('path'),'resource','images','list.png')
            overlay = ( xbmcgui.ICON_OVERLAY_NONE, xbmcgui.ICON_OVERLAY_HD, )[ video["quality"] == "HD 480p" or video["quality"] == "HD 720p" or video["quality"] == "HD 1080p"]

            dirItem.listitem = xbmcgui.ListItem( video[ "title" ], iconImage=icon, thumbnailImage=video[ "poster" ])
            try:
                release_date = datetime.date( int( video[ "releasedate" ].split( "-" )[ 0 ] ), int( video[ "releasedate" ].split( "-" )[ 1 ] ), int( video[ "releasedate" ].split( "-" )[ 2 ] ) ).strftime( self.date_format )
                year = int( video[ "releasedate" ].split( "-" )[ 0 ] )
            except:
                release_date = ""
                year = 0
            # dirItem.listitem.setInfo( "video", { "Title": video[ "title" ], "Overlay": overlay, "Size": video[ "size" ], "Year": year, "Plot": video[ "plot" ], "PlotOutline": video[ "plot" ], "Genre": video[ "genre" ], "Studio": video[ "studio" ], "Director": video[ "director" ], "Duration": video[ "runtime" ], "Cast": video[ "cast" ], "Date": video[ "postdate" ] } )
            dirItem.listitem.setInfo( "video", { "Title": video[ "title" ], "Overlay": overlay, "Size": video[ "size" ], "Year": year, "Plot": video[ "plot" ], "PlotOutline": video[ "plot" ], "Genre": video[ "genre" ], "Studio": video[ "studio" ], "Director": video[ "director" ], "Duration": video[ "runtime" ][:2], "Cast": video[ "cast" ]} )
            dirItem.listitem.setProperty( "releasedate", release_date )
            dirItem.listitem.setProperty( "fanart_image", video[ "fanart" ] )
            tmp_path, filepath = get_legal_filepath( video[ "title" ], video[ "trailer" ], 2, self.settings[ "download_path" ], self.settings[ "use_title" ], self.settings[ "use_trailer" ] )
            # add the movie information item
            dirItem.addContextMenuItem( self.Addon.getLocalizedString(30930), "XBMC.Action(Info)" )
            if ( self.settings[ "play_existing" ] and os.path.isfile( filepath.encode( "utf-8" ) ) ):
                dirItem.url = filepath
                dirItem.addContextMenuItem( self.Addon.getLocalizedString(30920), "XBMC.PlayMedia(%s)" % ( dirItem.url, ) )
            elif ( self.settings[ "play_mode" ] == 0 ):
                dirItem.url = video[ "trailer" ]
                dirItem.addContextMenuItem( self.Addon.getLocalizedString(30910), "XBMC.RunPlugin(%s?Download_Trailer=True&trailer_url=%s)" % ( sys.argv[ 0 ], urllib.quote_plus( repr( video[ "trailer" ] ) ), ) )
                dirItem.addContextMenuItem( self.Addon.getLocalizedString(30920), "XBMC.PlayMedia(%s)" % ( dirItem.url, ) )
            else:
                dirItem.url = "%s?Download_Trailer=True&trailer_url=%s" % ( sys.argv[ 0 ], urllib.quote_plus( repr( video[ "trailer" ] ) ) )
                dirItem.addContextMenuItem( self.Addon.getLocalizedString( 30910), "XBMC.RunPlugin(%s?Download_Trailer=True&trailer_url=%s)" % ( sys.argv[ 0 ], urllib.quote_plus( repr( video[ "trailer" ] ) ), ) )
            dirItem.addContextMenuItem(  xbmc.getLocalizedString( 1045 ), "XBMC.RunPlugin(%s?OpenSettings)" % ( sys.argv[ 0 ], ) )
            return self.MediaWindow.add( dirItem )
        except:
            print "PN2 ERROR: %s::%s (%d) - %s" % ( self.__class__.__name__, sys.exc_info()[ 2 ].tb_frame.f_code.co_name, sys.exc_info()[ 2 ].tb_lineno, sys.exc_info()[ 1 ], )
            return False