Changeset 1799
- Timestamp:
- 11/16/08 08:46:16 (16 months ago)
- Files:
-
- 1 modified
-
CodeSnippets/VideoTools/eac3to.py (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
CodeSnippets/VideoTools/eac3to.py
r1797 r1799 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 93 93 self["out_path"] = os.path.join(cfg["out_dir"], drive["lable"]) 94 if not os.path.isdir(self["out_path"]): 95 os.makedirs(self["out_path"]) 94 96 95 97 self["name_prefix"] = self["name"].replace(".", "_") … … 128 130 def get_command(self, stream_selection): 129 131 cmd = [self.cfg["eac3to"], self["abs_path"]] 130 132 131 133 value_dict = {} 132 134 for k,v in self["streams"].iteritems(): … … 134 136 if v not in value_dict: 135 137 value_dict[v] = [] 136 138 137 139 value_dict[v].append(k) 138 140 139 141 # pprint(value_dict) 140 142 … … 145 147 return True 146 148 return False 147 149 148 150 for stream_info in STREAMINFOS: 149 151 if in_list(stream_txt, stream_info["txt_filter"]): 150 152 return stream_info["ext"] 151 153 152 154 raise RuntimeError( 153 155 "No STREAMINFOS entry matched for '%s'" % stream_txt 154 156 ) 155 157 156 158 selected_streams = {} 157 159 for stream_txt in stream_selection: … … 161 163 print "Stream '%s' doesn't exist. Skip file." % stream_txt 162 164 return 163 165 164 166 file_ext = get_file_ext(stream_txt) 165 167 166 168 for id in ids: 167 169 filename = "%s - %i - %s%s" % ( … … 172 174 ) 173 175 out_filepath = os.path.join(self["out_path"], filename) 174 176 175 177 cmd.append("%i:" % id) 176 178 cmd.append(out_filepath) 177 179 178 180 return cmd 179 181 … … 187 189 print ">", line 188 190 no, info = line.split(":",1) 189 191 190 192 try: 191 193 no = int(no) 192 194 except ValueError: 193 195 continue 194 196 195 197 info = info.strip() 196 198 197 199 self["streams"][no] = info 198 200 199 201 200 202 def get_stream_info(self): … … 214 216 print "run '%s'..." % " ".join(cmd) 215 217 process, output = subprocess2(cmd) 216 218 217 219 f = file(self["eac3to_txt_path"], "w") 218 220 f.write(output) 219 221 f.close() 220 222 221 223 return output 222 224 223 225 #------------------------------------------------------------------------- 224 226 225 227 def debug(self): 226 228 print "_"*79 … … 271 273 filetypes = [('M2TS File','*.m2ts')], 272 274 ) 273 275 274 276 vol_info = path.replace("\\", "_").replace(":","_") # Fallback 275 277 for part in reversed(path.split(os.sep)[:-1]): … … 278 280 vol_info = part 279 281 break 280 282 281 283 drive = Drive(os.path.splitdrive(path)[0], cfg) 282 284 drive["stream_dir"] = os.path.split(path)[0] 283 285 drive.set_vol_info((vol_info,)) 284 286 285 287 drive.debug() 286 288 287 289 drives = [drive,] 288 290 289 291 cfg["last sourcedir"] = path 290 292 291 293 return drives 292 294 … … 304 306 print "Error: Path '%s' doesn't exist -> skip." % path 305 307 continue 306 308 307 309 glob_path = os.path.join(path, cfg["glob"]) 308 310 print "Looking in", glob_path … … 311 313 for abs_path in sorted(file_list): 312 314 filename = os.path.basename(abs_path) 313 315 314 316 stat = os.stat(abs_path) 315 317 … … 342 344 for index, videofile in enumerate(videofiles): 343 345 filesize = videofile["stat"].st_size 344 346 345 347 line = "%s - %s" % (videofile["abs_path"], human_filesize(filesize)) 346 348 item_list.append(line) 347 349 348 350 if filesize>cfg["skip_size"]: 349 351 activated.append(index) 350 352 351 353 # size = stat.st_size 352 354 # if size<cfg["skip_size"]: 353 355 # # Skip small files 354 # continue 355 356 # continue 357 356 358 lb = TkListbox( 357 359 title = "Please select", … … 362 364 print "selected items:" 363 365 pprint(lb.selection) # list of selected items. 364 366 365 367 curselection = lb.curselection # tuple containing index of selected items 366 print "curselection:", curselection 367 368 print "curselection:", curselection 369 368 370 new_list = [ 369 371 item … … 397 399 if char in ("\r", "\x08"): 398 400 continue 399 401 400 402 if char == "\n": 401 403 char_count = 0 … … 407 409 if char_count>79: 408 410 sys.stdout.write("\n") 409 char_count = 0 411 char_count = 0 410 412 sys.stdout.flush() 411 413 412 414 return process, output 413 415 414 416 415 417 def select_streams(videofiles): 416 418 """ … … 424 426 if not stream_txt in streams_txt: 425 427 streams_txt.append(stream_txt) 426 # 428 # 427 429 # lb = TkListbox( 428 430 # title = "Please select", … … 431 433 # ) 432 434 # print lb.selection 433 435 434 436 selection = TkListbox( 435 437 title = "Please select", … … 437 439 items = streams_txt 438 440 ).selection 439 441 440 442 return selection 441 443 … … 443 445 print "convert_streams():", videofile, stream_selection 444 446 videofile.debug() 445 446 447 448 449 if __name__ == "__main__": 447 448 449 450 451 if __name__ == "__main__": 450 452 cfg = VideoToolsConfig() 451 453 cfg.debug() 452 454 453 455 if DEBUG: 454 456 print "DEBUG!!!" … … 471 473 # Select via Tk the files witch realy convert 472 474 videofiles = select_videofiles(videofiles) 473 475 474 476 if not videofiles: 475 477 print "No stream files found -> abort, ok." … … 495 497 print "ERROR: No streams found!" 496 498 continue 497 499 498 500 499 501