From: <iwa...@us...> - 2003-08-08 07:08:45
|
Update of /cvsroot/quickrip/quickrip In directory sc8-pr-cvs1:/tmp/cvs-serv30475 Modified Files: base.py Log Message: Threading working in base for scanDVD. gtkmain does threading accordingly. Status is also shown for Scan. Index: base.py =================================================================== RCS file: /cvsroot/quickrip/quickrip/base.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** base.py 8 Aug 2003 00:30:01 -0000 1.9 --- base.py 8 Aug 2003 07:08:41 -0000 1.10 *************** *** 19,32 **** class CommandThread(threading.Thread): """Handle threading of external commands""" ! def __init__(self, command, updatefunc, flushbuffer): threading.Thread.__init__(self) self.updateFunc = updatefunc self.flushbuffer = flushbuffer self.command = command ! def run(self): self.pipe = popen2.Popen4(self.command) pid = self.pipe.pid while 1: try: --- 19,34 ---- class CommandThread(threading.Thread): """Handle threading of external commands""" ! def __init__(self, command, updatefunc, finalfunc, flushbuffer, data): threading.Thread.__init__(self) self.updateFunc = updatefunc + self.finalFunc = finalfunc self.flushbuffer = flushbuffer self.command = command ! self.data = data def run(self): self.pipe = popen2.Popen4(self.command) pid = self.pipe.pid + totallines = [] while 1: try: *************** *** 35,55 **** else: line = self.pipe.fromchild.readline() if not line: break else: ! self.updateFunc(line) except: # For PyGtk... weird! continue ! # Clean up process table ! try: ! self.kill_pipe() ! except: ! pass try: os.waitpid(pid, os.WNOHANG) except: pass sys.exit(2) --- 37,61 ---- else: line = self.pipe.fromchild.readline() + if not line: break else: ! totallines.append(line) ! if self.updateFunc != None: ! self.updateFunc(line, self.data) except: # For PyGtk... weird! continue ! # Clean up process table--you already handle exceptions in the function ! self.kill_pipe() ! try: os.waitpid(pid, os.WNOHANG) except: pass + + if self.finalFunc != None: + self.finalFunc(totallines, self.data) sys.exit(2) *************** *** 65,70 **** - - class QuickRip: """QuickRip base class, including the following methods: --- 71,74 ---- *************** *** 175,187 **** ! def run(self, program, arguments, updatefunc, flushbuffer=0): """Runs a program; supply program name (string) and arguments (list)""" command = arguments command[:0] = [self.config[program]] ! self.thread = CommandThread(command, updatefunc, flushbuffer) self.thread.start() - def kill_pipe(self): """Kills current process (pipe)""" --- 179,192 ---- ! def run(self, program, arguments, finalfunc=None, updatefunc=None, ! flushbuffer=0, data=None): """Runs a program; supply program name (string) and arguments (list)""" command = arguments command[:0] = [self.config[program]] ! self.thread = CommandThread(command, updatefunc, finalfunc, ! flushbuffer, data) self.thread.start() def kill_pipe(self): """Kills current process (pipe)""" *************** *** 192,216 **** pass - def getDVDInfo(self): """Find number of titles on DVD""" arguments = ['-vo', 'null', '-ao', 'null', '-v', 'dvd://', '-identify', '-quiet', '-nocache'] 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.up_DVDInfo) ! def up_DVDInfo(self, line): ! if self.re_error.search(line): self.ui_noTitles() ! elif self.re_title.search(line): ! self.numtitles = int(re_title.search(line).group(1)) print "***GOT NUMTITLES***" ! def getTitleInfo(self, no): ! """Find number of chapters, audio/subtitle languages & length for title""" ! arguments = ['-i', self.config['dvd_device'], '-T', str(no)] re_error = re.compile('No such file or directory') re_time = re.compile('.*title playback time: (.*):(.*):(\d*)\.\d* (\d*) sec') --- 197,248 ---- pass + # The following functions are threaded, but are processed in the order + # in which they appear here. - biggs + def scanDVD(self): + """Scan the DVD and build up a data structure for the titles""" + self.ui_startScanning() + + # Reset values to default (in case user scans two different discs in same session) + self.titles = [] + self.numtitles = 0 """Find number of titles on DVD""" arguments = ['-vo', 'null', '-ao', 'null', '-v', 'dvd://', '-identify', '-quiet', '-nocache'] 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): ! rettext = "" # recompile lines from array to big string ! for line in lines: # there's prolly a better way to do this :) ! rettext += line ! if self.re_error.search(rettext): ! print "no titles" self.ui_noTitles() ! elif self.re_title.search(rettext): ! self.numtitles = int(self.re_title.search(rettext).group(1)) print "***GOT NUMTITLES***" + if self.numtitles is 0: + return + + self.ui_dispDVD(self.numtitles) ! for i in range(int(self.numtitles) + 1): ! if i is not 0: ! """Find number of chapters, audio/subtitle languages & length for title""" ! arguments = ['-i', self.config['dvd_device'], '-T', str(i)] ! self.run('tcprobe', arguments, self.total_TitleInfo, None, 0, i) + def total_TitleInfo(self, lines, data): re_error = re.compile('No such file or directory') re_time = re.compile('.*title playback time: (.*):(.*):(\d*)\.\d* (\d*) sec') *************** *** 221,226 **** alangs = [] slangs = [] ! for line in self.run('tcprobe', arguments): if re_error.search(line): self.ui_noTitles() --- 253,261 ---- alangs = [] slangs = [] + chapters = 0 + time = 0 + time_label = "0 hrs 0 mins 0 secs" ! for line in lines: if re_error.search(line): self.ui_noTitles() *************** *** 245,295 **** chapters = re_chap.search(line).group(1) ! return chapters, alangs, slangs, time, time_label ! ! ! def scanDVD(self): ! """Scan the DVD and build up a data structure for the titles""" ! self.ui_startScanning() ! ! # Reset values to default (in case user scans two different discs in same session) ! self.titles = [] ! self.numtitles = 0 ! ! self.getDVDInfo() ! ! if self.numtitles is 0: ! return ! self.ui_dispDVD(self.numtitles) ! ! for i in range(int(self.numtitles) + 1): ! if i is not 0: ! # Get title information from disc ! chapters, alangs, slangs, time, time_label = self.getTitleInfo(i) ! # Clean up title ! if i < 10: title_label = "".join(["0", str(i)]) ! else: title_label = str(i) ! ! title = {} ! title['id'] = i ! title['name'] = title_label ! title['numchapters'] = int(chapters) ! title['time'] = int(time) ! title['timelabel'] = time_label ! title['size'] = 680 ! title['vbr'] = self.calcRate(int(time), 96, 680) ! title['abr'] = 128 #biggs added ! title['rip'] = "no" ! title['alangs'] = alangs ! title['alang'] = 'en' ! title['slangs'] = slangs ! title['slang'] = ' ' # biggs changed to a double space ! ! self.titles.append(title) ! self.ui_dispTitle(title) ! self.ui_finishScanning() def ripDVD(self): --- 280,309 ---- 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)]) ! else: title_label = str(i) ! title = {} ! title['id'] = i ! title['name'] = title_label ! title['numchapters'] = int(chapters) ! title['time'] = int(time) ! title['timelabel'] = time_label ! title['size'] = 680 ! title['vbr'] = self.calcRate(int(time), 96, 680) ! title['abr'] = 128 #biggs added ! title['rip'] = "no" ! title['alangs'] = alangs ! title['alang'] = 'en' ! title['slangs'] = slangs ! title['slang'] = ' ' # biggs changed to a double space ! self.titles.append(title) ! self.ui_dispTitle(title) + if len(self.titles) == self.numtitles: + self.ui_finishScanning() def ripDVD(self): *************** *** 445,450 **** import output print output.bold("NOT IMPLEMENTED YET!") - - ## INHERIT THE CLASS AND SUBSTITUE THESE CLASS METHODS WITH YOUR --- 459,462 ---- |