def add_categories(self, records):
        # get our media item
        dirItem = DirectoryItem()
        # set as folder since these our virtual folders to filtered lists
        dirItem.isFolder = True
        # FIXME: queue and now playing menu items
        # universal context menu items for categories
        # #dirItem.addContextMenuItem( xbmc.getLocalizedString( 13347 ), "XBMC.Action(Queue)" )
        # #dirItem.addContextMenuItem( xbmc.getLocalizedString( 13350 ), "XBMC.ActivateWindow(10028)" )
        dirItem.addContextMenuItem(xbmc.getLocalizedString(24020), "XBMC.RunScript({addon},task='configure')".format(addon=self.m_addon.getAddonInfo("Id")))
        dirItem.addContextMenuItem(xbmc.getLocalizedString(137), u"XBMC.RunScript({addon},search={search}&category=u'')".format(addon=self.m_addon.getAddonInfo("Id"), search=quote_plus(repr(self.m_addon.params.get("search", u"")))))
        # initialize our categories list
        categories = []
        # enumerate thru and set category
        for title, icon, thumb, category in records:
            # check for cached thumb FIXME: only actors (not enabled)
            if (thumb is None or not os.path.isfile(thumb)):
                thumb = icon
            # set the URL
            dirItem.url = u"{url}?category={category}".format(url=self.m_addon.params["path"], category=category)
            # create our listitem
            dirItem.listitem = xbmcgui.ListItem(title, iconImage=icon, thumbnailImage=thumb)
            # add context menu items to listitem with replaceItems = True so only ours show
            dirItem.listitem.addContextMenuItems(dirItem.context, replaceItems=True)
            # add category to our category list
            categories += [(dirItem.url, dirItem.listitem, dirItem.isFolder,)]

        # add categories to our media list
        return self.media_window.addItems(categories)
Ejemplo n.º 2
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
Ejemplo n.º 4
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 )
    def add_movies(self, records, category):
        # get our media item
        dirItem = DirectoryItem()
        # FIXME: queue and now playing menu items
        # universal context menu items for trailer lists
        # #dirItem.addContextMenuItem( xbmc.getLocalizedString( 13347 ), "XBMC.Action(Queue)" )
        dirItem.addContextMenuItem(self.m_addon.getLocalizedString(30903), u"XBMC.Action(Info)")
        # #dirItem.addContextMenuItem( xbmc.getLocalizedString( 13350 ), "XBMC.ActivateWindow(10028)" )
        dirItem.addContextMenuItem(xbmc.getLocalizedString(24020), u"XBMC.RunScript({addon},task='configure')".format(addon=self.m_addon.getAddonInfo("Id")))
        #print ["PSPSPSPSPSPSPSPS", self.m_addon.params]
        dirItem.addContextMenuItem(xbmc.getLocalizedString(137), u"XBMC.RunScript({addon},search={search}&category={category})".format(addon=self.m_addon.getAddonInfo("Id"), search=quote_plus(repr(self.m_addon.params.get("search", u""))), category=quote_plus(repr([u"", category][self.m_addon.getSetting("search.current.list")]))))
        # initialize our movies list
        movies = []
        # video and audio stream details used by some skins to display flagging
        stream_details = {
            "video": {
                "Standard": {"codec": "h264", "aspect": 1.78, "width": 720, "height": 480},
                "480p": {"codec": "h264", "aspect": 1.78, "width": 720, "height": 480},
                "720p": {"codec": "h264", "aspect": 1.78, "width": 1280, "height": 720},
                "1080p": {"codec": "h264", "aspect": 1.78, "width": 1920, "height": 1080}
            },
            "audio": {
                "Standard": {"codec": "aac", "language": "en", "channels": 2},
                "480p": {"codec": "aac", "language": "en", "channels": 2},
                "720p": {"codec": "aac", "language": "en", "channels": 2},
                "1080p": {"codec": "aac", "language": "en", "channels": 2}
            }
        }
        # iterate thru and set trailer
        for movie in records:
            # set downloaded based on all trailers available
            downloaded = (
                sum([
                     tlr in movie[27] for tlr in movie[25].split(",")
                     if (movie[27] is not None)
                ]) == len(movie[25].split(","))
            )
            # set playcount based on all trailers available
            playcount = int(
                sum([
                     tlr in movie[26] for tlr in movie[25].split(",")
                     if (movie[26] is not None)
                ]) == len(movie[25].split(","))
            )

            # set URL and play parameter
            dirItem.url = u"{url}?play={id}".format(
                url=self.m_addon.params["path"],
                id=movie[0]
            )

            # Play Trailer
            context = [(
                self.m_addon.getLocalizedString(30902),
                u"XBMC.RunPlugin({url})".format(url=dirItem.url),
            )]
            # Download & Play
            if (self.m_addon.getSetting("trailer.play.mode") == 0 and
                sum([tlr in movie[27] for tlr in movie[25].split(",")
                if (movie[27] is not None)]) < len(movie[24].split(","))):
                    context += [(
                        self.m_addon.getLocalizedString(30901),
                        u"XBMC.RunPlugin({url}&download=True)".format(
                            url=dirItem.url
                        ),
                    )]
            # Check Showtimes
            context += [(
                self.m_addon.getLocalizedString(30900),
                u"XBMC.RunScript({id},showtimes={title})".format(
                    id=self.m_addon.getAddonInfo("Id"),
                    title=quote_plus(repr(movie[1].split(" | ")[0])),
                )
            )]

            # overlay
            overlay = [
                xbmcgui.ICON_OVERLAY_UNWATCHED,
                xbmcgui.ICON_OVERLAY_WATCHED
            ][playcount]

            # tagline
            tagline = [
                "",
                "In Theaters {date}".format(
                    date=format_date(movie[4])
                )
            ][movie[4] != ""]

            # year
            year = int(movie[4][: 4] or 0)

            # format duration, sum of all available trailers
            # #duration = "{0:1.0f}:{1:02.0f}".format(*divmod(movie[23], 60))#movie[15]

            # set proper date for sorting, we use downloaded date for downloaded lists
            # and release date for in theaters and coming soon lists
            if (category.startswith("downloaded")):
                date = movie[21].split(" ")[0]
            elif (category.startswith("intheaters:") or category.startswith("comingsoon:")):
                date = movie[4]
            else:
                date = movie[16]

            # set our listitem
            dirItem.listitem = xbmcgui.ListItem(
                movie[1].split(" | ")[-1],
                iconImage="DefaultVideo.png",
                thumbnailImage="{url}|User-Agent={ua}".format(
                    url=movie[11],
                    ua=quote_plus(movie[30])
                )
            )
            # set info
            dirItem.listitem.setInfo("video", {
                "Count": movie[0],
                "PlayCount": playcount,
                "SortTitle": movie[1].split(" | ")[0],
                "Title": u"{downloaded}{title}{trailers}".format(
                    downloaded=[u"", u"* "][downloaded],
                    title=movie[1].split(" | ")[-1],
                    trailers=["", " - ({trailers})".format(
                            trailers=len(movie[24].split(","))
                        )
                    ][len(movie[24].split(",")) > 1]
                ),
                "MPAA": movie[2],
                "Studio": movie[3],
                "Date": "{day}-{month}-{year}".format(
                    day=date[8 :],
                    month=date[5 : 7],
                    year=date[: 4]
                ),
                "Year": year,
                "Director": movie[6],
                "Writer": movie[7],
                "Plot": movie[8] or "No plot available",
                "Cast": movie[9].split(" / "),
                "Genre": movie[10],
                "TagLine": tagline,
                "Size": movie[17],
                "lastplayed": movie[20] or "",
                "Overlay": overlay
            })
            # set stream details
            stream_details["video"][movie[14]]["duration"] = movie[23]
            dirItem.listitem.addStreamInfo("video", stream_details["video"][movie[14]])
            dirItem.listitem.addStreamInfo("audio", stream_details["audio"][movie[14]])
            # set additional properties
            dirItem.listitem.setProperty("ReleaseDate", format_date(movie[4]))
            dirItem.listitem.setProperty("Copyright", movie[5])
            dirItem.listitem.setProperty("AvailableTrailers", movie[24].replace(",", " / "))
            ###############################################
            # dirItem.listitem.setProperty("fanart_image", self.m_addon.getSetting("fanart")[0])
            ###############################################
            # dirItem.listitem.setProperty("Poster", movie[11])
            # used for video info dialog to search on trailers not database
            # dirItem.listitem.setProperty("Addon.Actor", movie[9].split(" / ")[0])
            # dirItem.listitem.setProperty("Addon.OnClick", "XBMC.RunScript(%s,search=%s)" % (self.m_addon.getAddonInfo("Id"), quote_plus(movie[9].split(" / ")[0].encode("UTF-8")),))
            # add context menu items to listitem with replaceItems = True so only ours show
            dirItem.listitem.addContextMenuItems(dirItem.context + context, replaceItems=True)
            # add the movie to our movie list
            movies += [(dirItem.url, dirItem.listitem, dirItem.isFolder,)]

        # add movies to our media list
        return self.media_window.addItems(movies)