From: <iwa...@us...> - 2003-08-10 01:22:06
|
Update of /cvsroot/quickrip/quickrip In directory sc8-pr-cvs1:/tmp/cvs-serv19121 Modified Files: base.py Log Message: Halfway working on threads for base among other things. Progress dialog changed to threaded mode. Index: base.py =================================================================== RCS file: /cvsroot/quickrip/quickrip/base.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** base.py 9 Aug 2003 10:50:07 -0000 1.13 --- base.py 10 Aug 2003 01:22:03 -0000 1.14 *************** *** 20,26 **** class CommandThread(threading.Thread): """Handle threading of external commands""" ! def __init__(self, parent, command, updatefunc, finalfunc, flushbuffer, data, lock): threading.Thread.__init__(self) - self.parent = parent self.updateFunc = updatefunc self.finalFunc = finalfunc --- 20,25 ---- class CommandThread(threading.Thread): """Handle threading of external commands""" ! def __init__(self, command, updatefunc, finalfunc, flushbuffer, data, lock): threading.Thread.__init__(self) self.updateFunc = updatefunc self.finalFunc = finalfunc *************** *** 31,44 **** def run(self): self.lock.acquire() ! self.parent.pipe = popen2.Popen4(self.command) ! pid = self.parent.pipe.pid totallines = [] while 1: try: if self.flushbuffer: ! line = self.parent.pipe.fromchild.read(1000) else: ! line = self.parent.pipe.fromchild.readline() if not line: --- 30,44 ---- def run(self): + # self.lock = thread.allocate_lock() self.lock.acquire() ! self.pipe = popen2.Popen4(self.command) ! pid = self.pipe.pid totallines = [] while 1: try: if self.flushbuffer: ! line = self.pipe.fromchild.read(1000) else: ! line = self.pipe.fromchild.readline() if not line: *************** *** 64,67 **** --- 64,68 ---- self.lock.release() + sys.exit(2) *************** *** 70,75 **** """Kills current process (pipe)""" try: ! os.kill(self.parent.pipe.pid, 9) ! os.waitpid(self.parent.pipe.pid, os.WNOHANG) except: pass --- 71,76 ---- """Kills current process (pipe)""" try: ! os.kill(self.pipe.pid, 9) ! os.waitpid(self.pipe.pid, os.WNOHANG) except: pass *************** *** 184,188 **** ! def run(self, program, arguments, finalfunc=None, updatefunc=None, flushbuffer=0, data=None, lock=None): """Runs a program; supply program name (string) and arguments (list)""" --- 185,189 ---- ! def run(self, program, arguments, finalfunc, updatefunc=None, flushbuffer=0, data=None, lock=None): """Runs a program; supply program name (string) and arguments (list)""" *************** *** 190,194 **** command[:0] = [self.config[program]] ! self.thread = CommandThread(self, command, updatefunc, finalfunc, flushbuffer, data, self.lock) self.thread.start() --- 191,195 ---- command[:0] = [self.config[program]] ! self.thread = CommandThread(command, updatefunc, finalfunc, flushbuffer, data, self.lock) self.thread.start() *************** *** 207,211 **** """Scan the DVD and build up a data structure for the titles""" self.ui_startScanning() ! self.lock = thread.allocate_lock() # Reset values to default (in case user scans two different discs in same session) --- 208,212 ---- """Scan the DVD and build up a data structure for the titles""" self.ui_startScanning() ! self.lock = thread.allocate_lock() #threading.allocate_lock() # Reset values to default (in case user scans two different discs in same session) *************** *** 217,222 **** self.re_title = re.compile('There are (\d*) titles on this DVD') self.re_error = re.compile('libdvdread: Could not open device') ! self.run('mplayer', arguments, self.total_DVDInfo) def total_DVDInfo(self, lines, data): --- 218,231 ---- self.re_title = re.compile('There are (\d*) titles on this DVD') self.re_error = re.compile('libdvdread: Could not open device') ! self.run('mplayer', arguments, self.total_DVDInfo) #self.up_DVDInfo) + # def up_DVDInfo(self, line, data): + # could do some status update here as well... + # if self.re_error.search(line): + # print "no titles" + # self.ui_noTitles() + # elif self.re_title.search(line): + # self.numtitles = int(re_title.search(line).group(1)) + # print "***GOT NUMTITLES***" def total_DVDInfo(self, lines, data): *************** *** 254,260 **** --- 263,274 ---- alangs = [] slangs = [] + chapters = None #Needed for error checking below + time = None + time_label = None for line in lines: if re_error.search(line): + print "error on " + str(data) + print line self.ui_noTitles() return *************** *** 277,280 **** --- 291,300 ---- if re_chap.search(line): chapters = re_chap.search(line).group(1) + + if chapters == None or time == None or time_label == None: + print "Error during execution:" + print line + self.ui_noTitles() + return i = data *************** *** 289,293 **** title['timelabel'] = time_label title['size'] = 680 ! title['vbr'] = self.calcRate(int(time), 96, 680) title['abr'] = 128 #biggs added title['rip'] = "no" --- 309,313 ---- title['timelabel'] = time_label title['size'] = 680 ! title['vbr'] = max(2000, self.calcRate(int(time), 96, 680)) title['abr'] = 128 #biggs added title['rip'] = "no" *************** *** 326,331 **** resolution = "720" - self.lock = thread.allocate_lock() - i = 0 for title in self.torip: --- 346,349 ---- *************** *** 334,373 **** # Look for cropping - self.found_cropping = 0 sstep = int(title['time']) / 31 if not sstep: sstep = 1 ! arguments = ["-dvd", str(title['id']), "-vop", "cropdetect", "-nosound", "-vo", "null", "-frames", "10", "-sstep", str(sstep)] ! self.run('mplayer', arguments, self.total_Crop, None, 0, title, self.lock) ! ! # Wait until cropping is found before proceeding to build rip commands ! # (locking threads won't stop QuickRip from building commands in background) ! while 1: ! if self.found_cropping: ! del self.found_cropping ! break ! ! # Clean up output dir in case QuickRip crashed out there ! os.popen("".join(["rm ", self.config['outputdir'], "frameno.avi 2>/dev/null"])) ! ! self.newpass = 1 ! if self.config['videocodec'] is 2: ! self.scvd(title, output, resolution) ! ! elif self.config['audiocodec'] is 1: ! output = os.path.join(self.config['outputdir'], "".join([str(title['name']), ".ogm"])) ! self.oggAudio(title) ! sleep(5) # makes sure the audio thread has time to start and get a lock ! self.aviVideo(title, output, resolution, 0) ! ! else: ! output = os.path.join(self.config['outputdir'], "".join([str(title['name']), ".avi"])) ! self.mp3Audio(title) ! sleep(5) # makes sure the audio thread has time to start and get a lock ! self.aviVideo(title, output, resolution, 1) ! ! def total_Crop(self, lines, title): ! re_crop = re.compile('-vop crop=(\d+:\d+:\d+:\d+)') crop_options = {} common_crop = "" --- 352,367 ---- # Look for cropping sstep = int(title['time']) / 31 if not sstep: sstep = 1 ! arguments = ["-dvd ", str(title['id']), "-vop", "cropdetect", "-nosound", "-vo", "null", "-frames", "10", "-sstep", str(sstep)] ! self.run('mplayer', arguments, self.preRip, None, title) ! # Clean up output dir in case QuickRip crashed out there ! # os.popen("".join(["rm ", self.config['outputdir'], "frameno.avi 2>/dev/null"])) ! ! def preRip(self, lines, data): ! re_crop = re.compile('.*-vop crop=(\d*:\d*:\d*:\d*).*') ! title = data crop_options = {} common_crop = "" *************** *** 382,414 **** except: crop_options[crop] = 1 - title['crop'] = common_crop - self.found_cropping = 1 - - - def mencode(self, arguments, passtype): - """Run mencoder with given arguments and report progress""" - self.perc = 0 - self.trem = 0 - self.run('mencoder', arguments, self.total_Mencode, self.update_Mencode, 1, passtype, self.lock) - - - def update_Mencode(self, line, passtype): - if self.newpass: - self.ui_newPass(passtype) - self.newpass = 0 - re_progress = re.compile('(\d+)\%\) .*Trem:\s*(\d+\w+)\s+') - if re_progress.search(line): - self.perc = re_progress.search(line).group(1) - self.trem = re_progress.search(line).group(2) - self.ui_updateProgress(self.perc, self.trem, passtype) ! def total_Mencode(self, lines, passtype): ! self.newpass = 1 def mp3Audio(self, title): """Rip the audio from a DVD title and encode as MP3""" try: os.popen("".join(["rm ", os.path.join(self.config['outputdir'], "frameno.avi")])) except: --- 376,404 ---- except: crop_options[crop] = 1 + title['crop'] = common_crop ! if self.config['videocodec'] is 2: ! self.scvd(title, output, resolution) ! elif self.config['audiocodec'] is 1: ! output = os.path.join(self.config['outputdir'], "".join([str(title['name']), ".ogm"])) ! self.oggAudio(title) ! self.aviVideo(title, output, resolution, 0) ! else: ! output = os.path.join(self.config['outputdir'], "".join([str(title['name']), ".avi"])) ! self.mp3Audio(title) ! self.aviVideo(title, output, resolution, 1) + def oggAudio(self, title): + """Rip the audio from a DVD title and encode as OGG""" + import output + print output.bold("OGG NOT IMPLEMENTED YET!") def mp3Audio(self, title): """Rip the audio from a DVD title and encode as MP3""" + self.ui_newPass("mp3audio") + try: + print "Trying to clean files inline, this may lag" os.popen("".join(["rm ", os.path.join(self.config['outputdir'], "frameno.avi")])) except: *************** *** 419,423 **** else: vol = "" ! lameopts = "".join(["cbr=", str(config.abr[self.config['audiobitrate']]), str(vol)]) arguments = ["-dvd", str(title['id']), "-alang", title['alang'], "-oac", \ --- 409,413 ---- else: vol = "" ! lameopts = "".join(["cbr=", str(config.abr[self.title['abr']]), str(vol)]) arguments = ["-dvd", str(title['id']), "-alang", title['alang'], "-oac", \ *************** *** 427,439 **** self.mencode(arguments, "mp3audio") - - def oggAudio(self, title): - """Rip the audio from a DVD title and encode as OGG""" - import output - print output.bold("NOT IMPLEMENTED YET!") - - def aviVideo(self, title, output, resolution, merge=1): """Rip the video from a DVD title, and optionally merge with audio""" if self.config['videocodec']: --- 417,423 ---- self.mencode(arguments, "mp3audio") def aviVideo(self, title, output, resolution, merge=1): """Rip the video from a DVD title, and optionally merge with audio""" + self.ui_newPass("video") if self.config['videocodec']: *************** *** 451,455 **** if merge: ! oac = "copy" else: oac = "null" --- 435,439 ---- if merge: ! oac = "frameno" else: oac = "null" *************** *** 460,472 **** if int(self.config['aspectratio']) is not 0: ! arguments.insert(4, "-aspect") ! arguments.insert(5, self.aro[self.config['aspectratio']]) ! if title['slang'] != ' ': ! arguments.insert(4, "-slang") ! arguments.insert(5, title['slang']) self.mencode(arguments, "video") def ogmerge(self, number, title, output, resolution): --- 444,475 ---- if int(self.config['aspectratio']) is not 0: ! arguments.insert(3, "-aspect") ! arguments.insert(4, self.aro[self.config['aspectratio']]) ! if title['slang']: ! arguments.insert(3, "-slang") ! arguments.insert(4, title['slang']) self.mencode(arguments, "video") + def mencode(self, arguments, passtype): + """Run mencoder with given arguments and report progress""" + self.run('mencoder', arguments, self.mencodeReturned, self.mencodeProgress, 1, passtype) + + def mencodeProgress(self, line, data): + """Run mencoder with given arguments and report progress""" + self.run('mencoder', arguments, self.mencodeReturned, self.mencodeProgress, 1, passtype) + perc = 0 + trem = 0 + passtype = data + re_progress = re.compile('(\d+)\%\) .*Trem:\s*(\d+\w+)\s+') + if re_progress.search(line): + perc = re_progress.search(line).group(1) + trem = re_progress.search(line).group(2) + self.ui_updateProgress(perc, trem, passtype) + + def mencodeReturned(self, lines, data): + print "Done Mencoding" + self.ui_updateProgress(1.0, "0", data) def ogmerge(self, number, title, output, resolution): *************** *** 479,483 **** """Rip the title to an SVCD MPEG using transcode""" import output ! print output.bold("NOT IMPLEMENTED YET!") ## INHERIT THE CLASS AND SUBSTITUE THESE CLASS METHODS WITH YOUR --- 482,486 ---- """Rip the title to an SVCD MPEG using transcode""" import output ! print output.bold("SVCD NOT IMPLEMENTED YET!") ## INHERIT THE CLASS AND SUBSTITUE THESE CLASS METHODS WITH YOUR |