3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
14 rT=re.compile("(.+)_(\d+)\Z")
16 rT2=re.compile("(.+)_(.+)_(\d*)\Z")#_(aichi)_2010-02-06T01:59:00.mkv
18 rT3=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+:\d+:\d+\Z")#_(aichi)_2010-02-06T01:59:00.mkv
20 rT4=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+-\d+-\d+\Z")#_(aichi)_2010-02-06T01-59-00.mkv
22 rT5=re.compile("(.+)_(.+)_(.+)\Z")#_(aichi)_2010-02-06T01-59-00.mkv
36 def detNameType(title):
38 type A ---title#<number>
39 type B ---title#<number>subtitle
40 type C ---title subtitle
41 type D ---title(without number)
43 recdblist.printutf8(title)
44 #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
45 rA=re.compile("(.+)#(\d*)\s*\Z")
47 rB=re.compile("(.+)#(\d*)\s*(\D*)")
50 recdblist.printutf8("typeA")
51 recdblist.printutf8("title="+tA.group(1))
52 recdblist.printutf8("num="+tA.group(2))
54 recdblist.printutf8("typeB")
55 recdblist.printutf8("title="+tB.group(1))
56 recdblist.printutf8("num="+tB.group(2))
57 recdblist.printutf8("subtitle="+tB.group(3))
58 def search_file(temppath,recpath,ext):
62 avilist = glob.glob(temppath + "/*"+ext)
65 ##b25f is title.ts.b25 avi is title.avi
66 dir = os.path.split(avif)[0]
67 title = os.path.split(avif)[1]
68 title = title.replace(ext, "")
69 avipath = os.path.join(dir, title + ext)
70 dtime = time.time()-os.path.getmtime(avipath)
73 if veryfySize(avipath):
76 def get_move_dest_path(title,temppath,recpath,ext):
77 dstpath=os.path.join(recpath,title+ext)
78 srcpath=os.path.join(temppath,title+ext)
79 if os.path.exists(dstpath):
80 gmtime=time.gmtime(os.path.getmtime(srcpath))
83 iff=u"("+configreader.getenv("iff")+u")_"
88 title=title+u"_"+iff+gmtime.strftime("%Y-%m-%dT%H-%M-%S")
90 def get_delpath(temppath,title):
91 delpath=[os.path.join(temppath,title+".ts")]
92 delpath.append(os.path.join(temppath,title+".avi"))
93 delpath.append(os.path.join(temppath,title+".120.avi"))
94 delpath.append(os.path.join(temppath,title+".timecode.txt"))
95 delpath.append(os.path.join(temppath,title+".aac"))
96 delpath.append(os.path.join(temppath,title+".ts.b25"))
97 delpath.append(os.path.join(temppath,title+".ts.tsmix"))
98 delpath.append(os.path.join(temppath,title+".ts.log"))
99 delpath.append(os.path.join(temppath,title+".sa.avi"))
100 delpath.append(os.path.join(temppath,title+".sa.avi.log"))
101 delpath.append(os.path.join(temppath,title+".log"))
103 def searchFolder(title,path,threshold=500):
105 titleにマッチするフォルダを探し出す。
107 folderpath=os.listdir(path)
110 for ft in folderpath:
111 fullpath=os.path.join(path.encode('utf-8'), ft)
112 if os.path.isdir(fullpath):
113 lfpath.append(fullpath)
114 ftt=os.listdir(fullpath)
118 folderpath.append(os.path.join(fullpath, ft2))
119 except Exception, inst:
124 lfpath.append(fullpath)
129 if os.path.isdir(dirp):
130 cmpp=os.path.dirname(dirp)
133 cmpp=os.path.basename(dirp)
134 appp=os.path.dirname(dirp)
135 ntitle=getTitle(title)
136 #recdblist.printutf8(cmpp)
137 cmpp=getTitle(os.path.splitext(cmpp)[0])
138 #recdblist.printutf8(cmpp+"\n")
139 p=n_gram.trigram(ntitle,cmpp)
141 ngram.append((p,appp))
142 ngram=list(set(ngram))
146 #recdblist.printutf8(title + ngram[0][1] + " : "+str(ngram[0][0]))
147 if ngram[0][0]>threshold:
153 def execMove(title,temppath,recpath,ext,autodel):
154 srcpath=os.path.join(temppath,title+ext)
155 #desttitle=destName(title, temppath, recpath)
157 sf=searchFolder(title, recpath)
159 destpath=os.path.join(sf,destNameMKV(title, temppath, sf)+ext)
160 recdblist.printutf8("moving now..")
161 recdblist.printutf8(srcpath+" : "+destpath)
163 shutil.move(srcpath, destpath)
164 #shutil.copy(srcpath, destpath)
166 delpath=get_delpath(temppath, title)