def download_list(self): # Clicked on button 'open' in filechooserdialog self.listdownloading = True fc = self.wTree.get_widget("filechooserdialog") pb = self.wTree.get_widget("dprogressbar") mainDownload_button = self.wTree.get_widget("mainDownload_button") mainClose_button = self.wTree.get_widget("mainClose_button") os.chdir( self.config.get( "general", "save_videos_in" ) ) fc.hide() pb.set_fraction(0) chosen_list = fc.get_filename() print "%(list)s selected" % {"list" : chosen_list} print "-----" mainDownload_button.set_sensitive(False) mainClose_button.set_sensitive(False) pb.set_text(_("Downloading a list...")) file = open( chosen_list, "r" ) i = 0 successful = 0 # videos downloaded successfully while True: pb.set_fraction(0) pb.set_text(_("Fetching video information...")) line = file.readline() if not line: break if line[-1] == "\n": line = line[:-1] print "----" print _("Trying to download %(link)s") % {"link" : line} v_no = i+1 # example: You're downloading the v_no. video && You're downloading the 5. video data = get_data(line) data.start() while data.status == -1: gtk.main_iteration_do(False) sleep(0.01) gtk.main_iteration_do(True) if data.status == 0: saveAs = os.path.join( self.config.get( "general", "save_videos_in" ), data.data[2] ) print _("Saving file as \"%(filename)s\"...") % {"filename" : saveAs} down = fdownload( data.data[0], # http://*.*/* data.data[2] # .flv ) down.start() pb.set_text(_("Downloading video %(number)s") % {"number" : v_no}) progress = down.downloaded()/100 while down.get_filesize() == 0: gtk.main_iteration_do(False) sleep(0.01) gtk.main_iteration_do(True) filesize = down.get_filesize() print _("Filesize: %(filesize)s KB") % {"filesize" : filesize} while progress < 1: gtk.main_iteration_do(False) sleep(0.005) pb.set_fraction(progress) progress = down.downloaded()/100 gtk.main_iteration_do(True) pb.set_fraction(1) pb.set_text(_("Finished download #%(number)s") % {"number" : v_no}) successful += 1 if self.config.getboolean( "general", "convert" ) and data.data[3]: pb.set_text(_("Converting file")) output = convert( saveAs, self.config.get( "general", "convert_filename_extension" ), self.config.get( "general", "convertcmd" ) ) output.start() while output.status == -1: gtk.main_iteration_do(False) sleep(0.01) gtk.main_iteration_do(True) pb.set_text(_("Converted file.")) if self.deletesourcefile: os.remove(saveAs) print _("Deleted input (.flv) file") else: print _("Wrong URL / unsupported video portal") pb.set_text(_("Download #%(number)s failed") % {"number" : v_no}) i += 1 print "----" pb.set_text(_("%(successful)s of %(all)s successful") % {"successful" : successful, "all" : i}) mainDownload_button.set_sensitive(True) mainClose_button.set_sensitive(True) self.listdownloading = False print "-----"
try: data = get_data(i) data.start() while data.status == -1: sleep(0.02) if data.status == 0: if options.saveAs != None: saveAs = options.saveAs else: saveAs = os.path.join( options.destination, data.data[2] ) print 'Saving file as "%(file)s"...' % {"file" : saveAs} down = fdownload( data.data[0], saveAs ) down.start() progress = down.downloaded() last_progress = progress last_ETA = 0.00 putWinString = False sleep(1) # give "it" some time to get the filesize, otherwise it'd be just '100' filesize = down.get_filesize() while filesize == 0: # if it was not enough sleep(1) filesize = down.get_filesize() print _("Filesize: %(filesize)s KB") % {"filesize" : filesize} while True: progress_dif = progress-last_progress kb_per_sec = filesize*(
def download_single( self, widget, event = None ): entry_url = self.wTree.get_widget("entry_url") pb = self.wTree.get_widget("dprogressbar") mainDownload_button = self.wTree.get_widget("mainDownload_button") mainClose_button = self.wTree.get_widget("mainClose_button") url = entry_url.get_text() os.chdir( self.config.get( "general", "save_videos_in" ) ) pb.set_fraction(0) pb.set_text(_("Fetching video information...")) if url == "": pb.set_text(_("No URL specified")) else: print "----" print _("Trying to download %(url)s") % {"url" : url} pb.set_fraction(0) mainDownload_button.set_sensitive(False) mainClose_button.set_sensitive(False) data = get_data(url) data.start() while data.status == -1: gtk.main_iteration_do(False) sleep(0.01) gtk.main_iteration_do(True) if data.status == 0: saveAs = os.path.join( self.config.get( "general", "save_videos_in" ), data.data[2] ) print "Saving file as \"%(filename)s\"..." % {"filename" : saveAs} down = fdownload( data.data[0], data.data[2] ) down.start() pb.set_fraction(0) pb.set_text(_("Downloading video...")) progress = down.downloaded()/100 while down.get_filesize() == 0: gtk.main_iteration_do(False) sleep(0.01) gtk.main_iteration_do(True) filesize = down.get_filesize() print "Filesize: %(filesize)s KB" % {"filesize" : filesize} while progress < 1: gtk.main_iteration_do(False) sleep(0.01) pb.set_fraction(progress) progress = down.downloaded()/100 gtk.main_iteration_do(True) pb.set_fraction(1) pb.set_text(_("Download finished.")) if self.config.getboolean( "general", "convert" ) and data.data[3]: pb.set_text(_("Converting file")) output = convert( saveAs, self.config.get( "general", "convert_filename_extension" ), self.config.get( "general", "convertcmd" ) ) output.start() while output.status == -1: gtk.main_iteration_do(False) sleep(0.01) gtk.main_iteration_do(True) pb.set_text(_("Converted file.")) if self.config.getboolean( "general", "delete_source_file_after_converting" ): os.remove(saveAs) print _("Deleted input (.flv) file") else: pb.set_text(_("Wrong URL / unsupported video portal")) mainDownload_button.set_sensitive(True) mainClose_button.set_sensitive(True) print "----"