<s> import common <EOL> import urllib <EOL> import os . path <EOL> import xbmc , xbmcgui <EOL> class Downloader ( object ) : <EOL> def __init__ ( self ) : <EOL> self . pDialog = None <EOL> def downloadWithJDownloader ( self , url , title ) : <EOL> common . runPlugin ( '<STR_LIT>' + url ) <EOL> common . showNotification ( '<STR_LIT>' ) <EOL> def downloadMovie ( self , url , path , title , extension ) : <EOL> if not os . path . exists ( path ) : <EOL> common . log ( '<STR_LIT>' ) <EOL> return None <EOL> if title == '<STR_LIT>' : <EOL> common . log ( '<STR_LIT>' ) <EOL> return None <EOL> file_path = xbmc . makeLegalFilename ( os . path . join ( path , title + extension ) ) <EOL> file_path = urllib . unquote_plus ( file_path ) <EOL> if os . path . isfile ( file_path ) : <EOL> self . pDialog = xbmcgui . Dialog ( ) <EOL> if not common . ask ( '<STR_LIT>' + os . path . basename ( file_path ) ) : <EOL> title = common . showOSK ( urllib . unquote_plus ( title ) , common . translate ( <NUM_LIT> ) ) <EOL> if not title : <EOL> return None <EOL> file_path = xbmc . makeLegalFilename ( os . path . join ( path , title + extension ) ) <EOL> file_path = urllib . unquote_plus ( file_path ) <EOL> success = self . __download ( url , file_path ) <EOL> if success : <EOL> return file_path <EOL> else : <EOL> return None <EOL> def __download ( self , url , file_path ) : <EOL> try : <EOL> self . pDialog = xbmcgui . DialogProgress ( ) <EOL> self . pDialog . create ( '<STR_LIT>' , common . translate ( <NUM_LIT> ) , common . translate ( <NUM_LIT> ) ) <EOL> urllib . urlretrieve ( url , file_path , self . video_report_hook ) <EOL> self . pDialog . close ( ) <EOL> return True <EOL> except IOError : <EOL> self . pDialog . close ( ) <EOL> common . showError ( common . translate ( <NUM_LIT> ) ) <EOL> except KeyboardInterrupt : <EOL> self . pDialog . close ( ) <EOL> return False <EOL> def video_report_hook ( self , count , blocksize , totalsize ) : <EOL> percent = int ( float ( count * blocksize * <NUM_LIT:100> ) / totalsize ) <EOL> self . pDialog . update ( percent , common . translate ( <NUM_LIT> ) , common . translate ( <NUM_LIT> ) ) <EOL> if self . pDialog . iscanceled ( ) : <EOL> raise KeyboardInterrupt </s>
