def _download_video( self ): try: # spam log file LOG( ">>> _download_video(title: %s)" % ( repr( self.g_title ), ), heading=True ) # get filepath and tmp_filepath tmppath, self.filepath = get_legal_filepath( self.g_title, self.params[ "download" ], 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" ) ) ): # only need to retrieve video if not in tmp path if ( not os.path.isfile( tmppath.encode( "utf-8" ) ) ): # fetch the video urllib.urlretrieve( self.params[ "download" ], tmppath.encode( "utf-8" ), self._report_hook ) # create the conf file for xbox and copy to final location ok = self._finalize_download( tmppath ) # if the copy failed raise an error if ( not ok ): raise except Exception, e: # oops, notify user what error occurred LOG( str( e ), xbmc.LOGERROR ) # 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( tmppath ): try: os.remove( tmppath.encode( "utf-8" ) ) except: remove_tries -= 1 xbmc.sleep( 1000 ) pDialog.close() self.filepath = ""
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 )