From: <te...@us...> - 2003-08-09 10:50:10
|
Update of /cvsroot/quickrip/quickrip In directory sc8-pr-cvs1:/tmp/cvs-serv7306 Modified Files: base.py Log Message: All threading/piping now works, for scanning and ripping. Now I just need to add MPEG-2 and OGM support and base.py should be complete :-) Index: base.py =================================================================== RCS file: /cvsroot/quickrip/quickrip/base.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** base.py 9 Aug 2003 02:02:34 -0000 1.12 --- base.py 9 Aug 2003 10:50:07 -0000 1.13 *************** *** 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 --- 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 *************** *** 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: --- 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: *************** *** 64,68 **** self.lock.release() - sys.exit(2) --- 64,67 ---- *************** *** 71,76 **** """Kills current process (pipe)""" try: ! os.kill(self.pipe.pid, 9) ! os.waitpid(self.pipe.pid, os.WNOHANG) except: pass --- 70,75 ---- """Kills current process (pipe)""" try: ! os.kill(self.parent.pipe.pid, 9) ! os.waitpid(self.parent.pipe.pid, os.WNOHANG) except: pass *************** *** 191,195 **** command[:0] = [self.config[program]] ! self.thread = CommandThread(command, updatefunc, finalfunc, flushbuffer, data, self.lock) self.thread.start() --- 190,194 ---- command[:0] = [self.config[program]] ! self.thread = CommandThread(self, command, updatefunc, finalfunc, flushbuffer, data, self.lock) self.thread.start() *************** *** 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) --- 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) *************** *** 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): --- 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): *************** *** 265,271 **** for line in lines: - # print str(data) + line if re_error.search(line): - print "error on " + str(data) self.ui_noTitles() return --- 256,260 ---- *************** *** 289,294 **** chapters = re_chap.search(line).group(1) - # return chapters, alangs, slangs, time, time_label - # Clean up title i = data if i < 10: title_label = "".join(["0", str(i)]) --- 278,281 ---- *************** *** 339,342 **** --- 326,331 ---- resolution = "720" + self.lock = thread.allocate_lock() + i = 0 for title in self.torip: *************** *** 345,370 **** # 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)] ! re_crop = re.compile('.*-vop crop=(\d*:\d*:\d*:\d*).*') ! crop_options = {} ! common_crop = "" ! cc_hits = 0 ! for line in self.run('mplayer', arguments): ! if re_crop.search(line): ! crop = re_crop.search(line).group(1) ! try: ! crop_options[crop] = crop_options[crop] + 1 ! if crop_options[crop] > cc_hits: ! common_crop = crop ! except: ! crop_options[crop] = 1 ! title['crop'] = common_crop # Clean up output dir in case QuickRip crashed out there os.popen("".join(["rm ", self.config['outputdir'], "frameno.avi 2>/dev/null"])) if self.config['videocodec'] is 2: self.scvd(title, output, resolution) --- 334,355 ---- # 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) *************** *** 373,376 **** --- 358,362 ---- 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) *************** *** 378,400 **** output = os.path.join(self.config['outputdir'], "".join([str(title['name']), ".avi"])) self.mp3Audio(title) self.aviVideo(title, output, resolution, 1) def mencode(self, arguments, passtype): """Run mencoder with given arguments and report progress""" ! perc = 0 ! trem = 0 re_progress = re.compile('(\d+)\%\) .*Trem:\s*(\d+\w+)\s+') ! for line in self.run('mencoder', arguments, 1): ! 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 mp3Audio(self, title): """Rip the audio from a DVD title and encode as MP3""" - self.ui_newPass("mp3audio") - try: os.popen("".join(["rm ", os.path.join(self.config['outputdir'], "frameno.avi")])) --- 364,413 ---- 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 = "" + cc_hits = 0 + for line in lines: + if re_crop.search(line): + crop = re_crop.search(line).group(1) + try: + crop_options[crop] = crop_options[crop] + 1 + if crop_options[crop] > cc_hits: + common_crop = crop + 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")])) *************** *** 423,427 **** 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']: --- 436,439 ---- *************** *** 439,443 **** if merge: ! oac = "frameno" else: oac = "null" --- 451,455 ---- if merge: ! oac = "copy" else: oac = "null" *************** *** 448,457 **** 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") --- 460,469 ---- 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") |