Changeset 1807 for CodeSnippets/VideoTools/eac3to.py
- Timestamp:
- 11/19/08 17:32:54 (16 months ago)
- Location:
- CodeSnippets/VideoTools
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
CodeSnippets/VideoTools
-
Property
svn:ignore set
to
config.dat
-
Property
svn:ignore set
to
-
CodeSnippets/VideoTools/eac3to.py
r1799 r1807 5 5 """ 6 6 7 import os, sys, glob, time, datetime, subprocess,logging7 import os, sys, glob, time, datetime, logging 8 8 from pprint import pprint 9 9 … … 14 14 from shared.config import VideoToolsConfig 15 15 from shared.tk_tools import askopenfilename2, askdirectory2, TkListbox 16 from shared.tools import make_slug, human_filesize 16 from shared.tools import make_slug, human_filesize, subprocess2 17 17 18 18 DEBUG = False … … 60 60 self["vol_info"] = vol_info 61 61 self["lable"] = vol_info[0] 62 62 63 63 def debug(self): 64 64 print "_"*79 … … 88 88 self["abs_path"] = abs_path # File path + filename 89 89 self["stat"] = stat # os.stat 90 90 91 91 self.cfg = cfg 92 92 … … 130 130 def get_command(self, stream_selection): 131 131 cmd = [self.cfg["eac3to"], self["abs_path"]] 132 132 133 133 value_dict = {} 134 134 for k,v in self["streams"].iteritems(): … … 136 136 if v not in value_dict: 137 137 value_dict[v] = [] 138 138 139 139 value_dict[v].append(k) 140 140 141 141 # pprint(value_dict) 142 142 … … 147 147 return True 148 148 return False 149 149 150 150 for stream_info in STREAMINFOS: 151 151 if in_list(stream_txt, stream_info["txt_filter"]): 152 152 return stream_info["ext"] 153 153 154 154 raise RuntimeError( 155 155 "No STREAMINFOS entry matched for '%s'" % stream_txt 156 156 ) 157 157 158 158 selected_streams = {} 159 159 for stream_txt in stream_selection: … … 163 163 print "Stream '%s' doesn't exist. Skip file." % stream_txt 164 164 return 165 165 166 166 file_ext = get_file_ext(stream_txt) 167 167 168 168 for id in ids: 169 169 filename = "%s - %i - %s%s" % ( … … 174 174 ) 175 175 out_filepath = os.path.join(self["out_path"], filename) 176 176 177 177 cmd.append("%i:" % id) 178 178 cmd.append(out_filepath) 179 179 180 180 return cmd 181 181 … … 189 189 print ">", line 190 190 no, info = line.split(":",1) 191 191 192 192 try: 193 193 no = int(no) 194 194 except ValueError: 195 195 continue 196 196 197 197 info = info.strip() 198 198 199 199 self["streams"][no] = info 200 200 201 201 202 202 def get_stream_info(self): … … 216 216 print "run '%s'..." % " ".join(cmd) 217 217 process, output = subprocess2(cmd) 218 218 219 219 f = file(self["eac3to_txt_path"], "w") 220 220 f.write(output) 221 221 f.close() 222 222 223 223 return output 224 224 225 225 #------------------------------------------------------------------------- 226 226 227 227 def debug(self): 228 228 print "_"*79 … … 250 250 result = [] 251 251 for drive in drives: 252 drive_letter = drive["letter"] 252 253 try: 253 vol_info = win32api.GetVolumeInformation(drive .letter)254 vol_info = win32api.GetVolumeInformation(drive_letter) 254 255 except Exception, err: 255 #~ print "Skip drive '%s': %s" % (drive.letter, err)256 print "Skip drive '%s': %s" % (drive_letter, err) 256 257 continue 257 258 … … 273 274 filetypes = [('M2TS File','*.m2ts')], 274 275 ) 275 276 276 277 vol_info = path.replace("\\", "_").replace(":","_") # Fallback 277 278 for part in reversed(path.split(os.sep)[:-1]): … … 280 281 vol_info = part 281 282 break 282 283 283 284 drive = Drive(os.path.splitdrive(path)[0], cfg) 284 285 drive["stream_dir"] = os.path.split(path)[0] 285 286 drive.set_vol_info((vol_info,)) 286 287 287 288 drive.debug() 288 289 289 290 drives = [drive,] 290 291 291 292 cfg["last sourcedir"] = path 292 293 293 294 return drives 294 295 … … 306 307 print "Error: Path '%s' doesn't exist -> skip." % path 307 308 continue 308 309 309 310 glob_path = os.path.join(path, cfg["glob"]) 310 311 print "Looking in", glob_path … … 313 314 for abs_path in sorted(file_list): 314 315 filename = os.path.basename(abs_path) 315 316 316 317 stat = os.stat(abs_path) 317 318 … … 344 345 for index, videofile in enumerate(videofiles): 345 346 filesize = videofile["stat"].st_size 346 347 347 348 line = "%s - %s" % (videofile["abs_path"], human_filesize(filesize)) 348 349 item_list.append(line) 349 350 350 351 if filesize>cfg["skip_size"]: 351 352 activated.append(index) 352 353 353 354 # size = stat.st_size 354 355 # if size<cfg["skip_size"]: 355 356 # # Skip small files 356 # continue 357 357 # continue 358 358 359 lb = TkListbox( 359 360 title = "Please select", … … 364 365 print "selected items:" 365 366 pprint(lb.selection) # list of selected items. 366 367 367 368 curselection = lb.curselection # tuple containing index of selected items 368 print "curselection:", curselection 369 369 print "curselection:", curselection 370 370 371 new_list = [ 371 372 item … … 380 381 381 382 382 def subprocess2(cmd): 383 print "_"*80 384 print "subprocess2():" 385 pprint(cmd) 386 print " -"*40 387 process = subprocess.Popen( 388 cmd, 389 stdout=subprocess.PIPE, 390 shell=True, 391 ) 392 output = "" 393 char_count = 0 394 while True: 395 char = process.stdout.read(1) 396 if char=="": 397 break 398 399 if char in ("\r", "\x08"): 400 continue 401 402 if char == "\n": 403 char_count = 0 404 else: 405 char_count += 1 406 407 output += char 408 sys.stdout.write(char) 409 if char_count>79: 410 sys.stdout.write("\n") 411 char_count = 0 412 sys.stdout.flush() 413 414 return process, output 415 416 383 384 385 417 386 def select_streams(videofiles): 418 387 """ … … 426 395 if not stream_txt in streams_txt: 427 396 streams_txt.append(stream_txt) 428 # 397 # 429 398 # lb = TkListbox( 430 399 # title = "Please select", … … 433 402 # ) 434 403 # print lb.selection 435 404 436 405 selection = TkListbox( 437 406 title = "Please select", … … 439 408 items = streams_txt 440 409 ).selection 441 410 442 411 return selection 443 412 … … 445 414 print "convert_streams():", videofile, stream_selection 446 415 videofile.debug() 447 448 449 450 451 if __name__ == "__main__": 416 417 418 419 420 if __name__ == "__main__": 452 421 cfg = VideoToolsConfig() 453 422 cfg.debug() 454 423 455 424 if DEBUG: 456 425 print "DEBUG!!!" … … 473 442 # Select via Tk the files witch realy convert 474 443 videofiles = select_videofiles(videofiles) 475 444 476 445 if not videofiles: 477 446 print "No stream files found -> abort, ok." … … 497 466 print "ERROR: No streams found!" 498 467 continue 499 468 500 469 501 470