Changeset 1799

Show
Ignore:
Timestamp:
11/16/08 08:46:16 (16 months ago)
Author:
JensDiemer
Message:

eac3to.py bugfix if out path doesn't exist.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • CodeSnippets/VideoTools/eac3to.py

    r1797 r1799  
    6060        self["vol_info"] = vol_info 
    6161        self["lable"] = vol_info[0] 
    62          
     62 
    6363    def debug(self): 
    6464        print "_"*79 
     
    8888        self["abs_path"] = abs_path # File path + filename 
    8989        self["stat"] = stat # os.stat 
    90          
     90 
    9191        self.cfg = cfg 
    9292 
    9393        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"]) 
    9496 
    9597        self["name_prefix"] = self["name"].replace(".", "_") 
     
    128130    def get_command(self, stream_selection): 
    129131        cmd = [self.cfg["eac3to"], self["abs_path"]] 
    130          
     132 
    131133        value_dict = {} 
    132134        for k,v in self["streams"].iteritems(): 
     
    134136            if v not in value_dict: 
    135137                value_dict[v] = [] 
    136          
     138 
    137139            value_dict[v].append(k) 
    138          
     140 
    139141#        pprint(value_dict) 
    140142 
     
    145147                        return True 
    146148                return False 
    147              
     149 
    148150            for stream_info in STREAMINFOS: 
    149151                if in_list(stream_txt, stream_info["txt_filter"]): 
    150152                    return stream_info["ext"] 
    151                  
     153 
    152154            raise RuntimeError( 
    153155                "No STREAMINFOS entry matched for '%s'" % stream_txt 
    154156            ) 
    155          
     157 
    156158        selected_streams = {} 
    157159        for stream_txt in stream_selection: 
     
    161163                print "Stream '%s' doesn't exist. Skip file." % stream_txt 
    162164                return 
    163              
     165 
    164166            file_ext = get_file_ext(stream_txt) 
    165              
     167 
    166168            for id in ids: 
    167169                filename = "%s - %i - %s%s" % ( 
     
    172174                ) 
    173175                out_filepath = os.path.join(self["out_path"], filename) 
    174                  
     176 
    175177                cmd.append("%i:" % id) 
    176178                cmd.append(out_filepath) 
    177                          
     179 
    178180        return cmd 
    179181 
     
    187189                print ">", line 
    188190            no, info = line.split(":",1) 
    189              
     191 
    190192            try: 
    191193                no = int(no) 
    192194            except ValueError: 
    193195                continue 
    194              
     196 
    195197            info = info.strip() 
    196              
     198 
    197199            self["streams"][no] = info 
    198   
     200 
    199201 
    200202    def get_stream_info(self): 
     
    214216            print "run '%s'..." % " ".join(cmd) 
    215217            process, output = subprocess2(cmd) 
    216              
     218 
    217219            f = file(self["eac3to_txt_path"], "w") 
    218220            f.write(output) 
    219221            f.close() 
    220              
     222 
    221223        return output 
    222224 
    223225    #------------------------------------------------------------------------- 
    224      
     226 
    225227    def debug(self): 
    226228        print "_"*79 
     
    271273        filetypes = [('M2TS File','*.m2ts')], 
    272274    ) 
    273      
     275 
    274276    vol_info = path.replace("\\", "_").replace(":","_") # Fallback 
    275277    for part in reversed(path.split(os.sep)[:-1]): 
     
    278280            vol_info = part 
    279281            break 
    280      
     282 
    281283    drive = Drive(os.path.splitdrive(path)[0], cfg) 
    282284    drive["stream_dir"] = os.path.split(path)[0] 
    283285    drive.set_vol_info((vol_info,)) 
    284      
     286 
    285287    drive.debug() 
    286      
     288 
    287289    drives = [drive,] 
    288      
     290 
    289291    cfg["last sourcedir"] = path 
    290      
     292 
    291293    return drives 
    292294 
     
    304306            print "Error: Path '%s' doesn't exist -> skip." % path 
    305307            continue 
    306          
     308 
    307309        glob_path = os.path.join(path, cfg["glob"]) 
    308310        print "Looking in", glob_path 
     
    311313        for abs_path in sorted(file_list): 
    312314            filename = os.path.basename(abs_path) 
    313              
     315 
    314316            stat = os.stat(abs_path) 
    315317 
     
    342344    for index, videofile in enumerate(videofiles): 
    343345        filesize = videofile["stat"].st_size 
    344          
     346 
    345347        line = "%s - %s" % (videofile["abs_path"], human_filesize(filesize)) 
    346348        item_list.append(line) 
    347          
     349 
    348350        if filesize>cfg["skip_size"]: 
    349351            activated.append(index) 
    350      
     352 
    351353#    size = stat.st_size 
    352354#    if size<cfg["skip_size"]: 
    353355#        # Skip small files 
    354 #        continue   
    355      
     356#        continue 
     357 
    356358    lb = TkListbox( 
    357359        title = "Please select", 
     
    362364    print "selected items:" 
    363365    pprint(lb.selection) # list of selected items. 
    364      
     366 
    365367    curselection = lb.curselection # tuple containing index of selected items 
    366     print "curselection:", curselection       
    367          
     368    print "curselection:", curselection 
     369 
    368370    new_list = [ 
    369371        item 
     
    397399        if char in ("\r", "\x08"): 
    398400            continue 
    399          
     401 
    400402        if char == "\n": 
    401403            char_count = 0 
     
    407409        if char_count>79: 
    408410            sys.stdout.write("\n") 
    409             char_count = 0             
     411            char_count = 0 
    410412        sys.stdout.flush() 
    411413 
    412414    return process, output 
    413415 
    414      
     416 
    415417def select_streams(videofiles): 
    416418    """ 
     
    424426            if not stream_txt in streams_txt: 
    425427                streams_txt.append(stream_txt) 
    426 #     
     428# 
    427429#    lb = TkListbox( 
    428430#        title = "Please select", 
     
    431433#    ) 
    432434#    print lb.selection 
    433      
     435 
    434436    selection = TkListbox( 
    435437        title = "Please select", 
     
    437439        items = streams_txt 
    438440    ).selection 
    439      
     441 
    440442    return selection 
    441443 
     
    443445    print "convert_streams():", videofile, stream_selection 
    444446    videofile.debug() 
    445      
    446      
    447  
    448  
    449 if __name__ == "__main__":     
     447 
     448 
     449 
     450 
     451if __name__ == "__main__": 
    450452    cfg = VideoToolsConfig() 
    451453    cfg.debug() 
    452      
     454 
    453455    if DEBUG: 
    454456        print "DEBUG!!!" 
     
    471473    # Select via Tk the files witch realy convert 
    472474    videofiles = select_videofiles(videofiles) 
    473      
     475 
    474476    if not videofiles: 
    475477        print "No stream files found -> abort, ok." 
     
    495497            print "ERROR: No streams found!" 
    496498            continue 
    497          
     499 
    498500 
    499501