コード例 #1
0
 def _download_video(self):
     try:
         # get filepath and tmp_filepath
         tmp_path, self.filepath = get_legal_filepath(
             g_title, self.args.trailer_url, self.settings["play_mode"],
             self.settings["download_path"], self.settings["use_title"],
             self.settings["use_trailer"])
         # only download if the trailer doesn't exist
         if (not os.path.isfile(self.filepath.encode("utf-8"))):
             # fetch the video
             urllib.urlretrieve(self.args.trailer_url, tmp_path,
                                self._report_hook)
             # create the conf file for xbox and copy to final location
             ok = self._finalize_download(tmp_path)
             # if the copy failed raise an error
             if (not ok): raise
     except:
         print "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],
         )
         # filepath is not always released immediately, we may need to try more than one attempt, sleeping between
         urllib.urlcleanup()
         remove_tries = 3
         while remove_tries and os.path.isfile(tmp_path):
             try:
                 os.remove(tmp_path)
             except:
                 remove_tries -= 1
                 xbmc.sleep(1000)
         pDialog.close()
         self.filepath = ""
コード例 #2
0
 def _add_video( self, video, total ):
     try:
         # set the default icon
         icon = "DefaultVideo.png"
         # set an overlay if one is practical
         overlay = ( xbmcgui.ICON_OVERLAY_NONE, xbmcgui.ICON_OVERLAY_HD, )[ "720p.mov" in video[ "trailer" ] or "1080p.mov" in video[ "trailer" ] ]
         # only need to add label and thumbnail, setInfo() and addSortMethod() takes care of label2
         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
         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[ "runtime" ], "Cast": video[ "cast" ], "Date": video[ "postdate" ] } )
         # set release date property
         listitem.setProperty( "releasedate", release_date )
         # get filepath and tmp_filepath
         tmp_path, filepath = get_legal_filepath( video[ "title" ], video[ "trailer" ], 2, self.settings[ "download_path" ], self.settings[ "use_title" ], self.settings[ "use_trailer" ] )
         # set context menu items
         items = [ ( xbmc.getLocalizedString( 30900 ), "XBMC.RunPlugin(%s?Fetch_Showtimes=True&title=%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" ) ) ):
             url = filepath
             # just add play trailer if trailer exists and user preference to always play existing
             items += [ ( xbmc.getLocalizedString( 30920 ), "XBMC.PlayMedia(%s)" % ( url ), ) ]
         elif ( self.settings[ "play_mode" ] == 0 ):
             url = video[ "trailer" ]
             # we want both play and download if user preference is to stream
             items += [ ( xbmc.getLocalizedString( 30910 ), "XBMC.RunPlugin(%s?Download_Trailer=True&trailer_url=%s)" % ( sys.argv[ 0 ], urllib.quote_plus( repr( video[ "trailer" ] ) ), ), ) ]
             items += [ ( xbmc.getLocalizedString( 30920 ), "XBMC.PlayMedia(%s)" % ( url ), ) ]
         else:
             url = "%s?Download_Trailer=True&trailer_url=%s" % ( sys.argv[ 0 ], urllib.quote_plus( repr( video[ "trailer" ] ) ) )
             # only add download if user prefernce is not stream
             items += [ ( xbmc.getLocalizedString( 30910 ), "XBMC.RunPlugin(%s?Download_Trailer=True&trailer_url=%s)" % ( sys.argv[ 0 ], urllib.quote_plus( repr( video[ "trailer" ] ) ), ), ) ]
         # add the movie information item
         items += [ ( xbmc.getLocalizedString( 30930 ), "XBMC.Action(Info)", ) ]
         # add items to listitem with replaceItems = True so only ours show
         listitem.addContextMenuItems( items, replaceItems=True )
         # add the item to the media list
         ok = xbmcplugin.addDirectoryItem( handle=int( sys.argv[ 1 ] ), url=url, listitem=listitem, isFolder=False, totalItems=total )
         # return
         return ok
     except:
         print "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
コード例 #3
0
    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
コード例 #4
0
 def _download_video( self ):
     try:
         # get filepath and tmp_filepath
         tmp_url_split=self.args.trailer_url.split("?")[ 0 ]
         tmp_path, self.filepath = get_legal_filepath( g_title,
                                                       tmp_url_split,
                                                       self.settings[ "play_mode" ],
                                                       self.settings[ "download_path" ],
                                                       self.settings[ "use_title" ],
                                                       self.settings[ "use_trailer" ] )
     #
         tmp_path = self.filepath
     #
         # only download if the trailer doesn't exist
         if ( not os.path.isfile( self.filepath.encode( "utf-8" ) ) ):
             # only need to retrieve video if not in tmp path
             if ( not os.path.isfile( tmp_path.encode( "utf-8" ) ) ):
                 # fetch the video
                 urllib.urlretrieve( self.args.trailer_url.encode( "utf-8" ), tmp_path, self._report_hook )
             # create the conf file for xbox and copy to final location
             ok = self._finalize_download( tmp_path )
             # if the copy failed raise an error
             if ( not ok ): raise
     except:
         print "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 ], )
         # filepath is not always released immediately, we may need to try more than one attempt, sleeping between
         urllib.urlcleanup()
         remove_tries = 3
         while remove_tries and os.path.isfile( tmp_path ):
             try:
                 os.remove( tmp_path )
             except:
                 remove_tries -= 1
                 xbmc.sleep( 1000 )
         pDialog.close()
         self.filepath = ""
コード例 #5
0
 def _add_video(self, video, total):
     try:
         # set the default icon
         icon = "DefaultVideo.png"
         # set an overlay if one is practical
         overlay = (
             xbmcgui.ICON_OVERLAY_NONE,
             xbmcgui.ICON_OVERLAY_HD,
         )["720p.mov" in video["trailer"]
           or "1080p.mov" in video["trailer"]]
         # only need to add label and thumbnail, setInfo() and addSortMethod() takes care of label2
         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
         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["runtime"],
                 "Cast": video["cast"],
                 "Date": video["postdate"]
             })
         # set release date property
         listitem.setProperty("releasedate", release_date)
         # get filepath and tmp_filepath
         tmp_path, filepath = get_legal_filepath(
             video["title"], video["trailer"], 2,
             self.settings["download_path"], self.settings["use_title"],
             self.settings["use_trailer"])
         # set context menu items
         items = [(
             xbmc.getLocalizedString(30900),
             "XBMC.RunPlugin(%s?Fetch_Showtimes=True&title=%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"))):
             url = filepath
             # just add play trailer if trailer exists and user preference to always play existing
             items += [(
                 xbmc.getLocalizedString(30920),
                 "XBMC.PlayMedia(%s)" % (url),
             )]
         elif (self.settings["play_mode"] == 0):
             url = video["trailer"]
             # we want both play and download if user preference is to stream
             items += [(
                 xbmc.getLocalizedString(30910),
                 "XBMC.RunPlugin(%s?Download_Trailer=True&trailer_url=%s)" %
                 (
                     sys.argv[0],
                     urllib.quote_plus(repr(video["trailer"])),
                 ),
             )]
             items += [(
                 xbmc.getLocalizedString(30920),
                 "XBMC.PlayMedia(%s)" % (url),
             )]
         else:
             url = "%s?Download_Trailer=True&trailer_url=%s" % (
                 sys.argv[0], urllib.quote_plus(repr(video["trailer"])))
             # only add download if user prefernce is not stream
             items += [(
                 xbmc.getLocalizedString(30910),
                 "XBMC.RunPlugin(%s?Download_Trailer=True&trailer_url=%s)" %
                 (
                     sys.argv[0],
                     urllib.quote_plus(repr(video["trailer"])),
                 ),
             )]
         # add the movie information item
         items += [(
             xbmc.getLocalizedString(30930),
             "XBMC.Action(Info)",
         )]
         # add items to listitem with replaceItems = True so only ours show
         listitem.addContextMenuItems(items, replaceItems=True)
         # add the item to the media list
         ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                          url=url,
                                          listitem=listitem,
                                          isFolder=False,
                                          totalItems=total)
         # return
         return ok
     except:
         print "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