#! /usr/bin/python # http://learn.tsinghua.edu.cn/homepage/2001010752/izixia.html # http://pan.cdut.cn import re, string, os.path pattern = re.compile('[mM][pP]3$') fd_all = open("./all.lftp",'r') line = fd_all.readline() while line!= '': dir_long, mp3filename = os.path.split(line) # this is a tuple dir_long = os.path.normpath(dir_long) if not os.path.exists(dir_long): os.mkdir(dir_long) # if the line have a mp3 file in it if len(mp3filename)!= 0 and pattern.search(mp3filename)!= None: url = string.join(['http://166.111.158.99/music/',line],'') # no separator url = string.replace(url,' ','%20') single = re.sub(pattern, 'm3u', line) fd_single = open(single, 'a+') fd_single.writelines(url) fd_single.close() dirlist = string.split(dir_long,'/') while len(dirlist)!= 0: # see pop at the end of this loop #make the last dir recusively new2dir = string.join(dirlist,'/') m3ufile = os.path.join(new2dir, dirlist[-1]) # m3u file has the same m3ufile = string.join([m3ufile, '.m3u'], '')# name with its directory # create the m3u file as well as its path if path doesn't exist fd_part = open(m3ufile,'a+') fd_part.writelines(url) fd_part.close() dirlist.pop() # good... line = fd_all.readline()