3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
15 rT=re.compile("(.+)_(\d+)\Z")
17 rT2=re.compile("(.+)_(.+)_(\d*)\Z")#_(aichi)_2010-02-06T01:59:00.mkv
19 rT3=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+:\d+:\d+\Z")#_(aichi)_2010-02-06T01:59:00.mkv
21 rT4=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+-\d+-\d+\Z")#_(aichi)_2010-02-06T01-59-00.mkv
23 rT5=re.compile("(.+)_(.+)_(.+)\Z")#_(aichi)_2010-02-06T01-59-00.mkv
37 def detNameType(title):
39 type A ---title#<number>
40 type B ---title#<number>subtitle
41 type C ---title subtitle
42 type D ---title(without number)
44 recdblist.printutf8(title)
45 #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
46 rA=re.compile("(.+)#(\d*)\s*\Z")
48 rB=re.compile("(.+)#(\d*)\s*(\D*)")
51 recdblist.printutf8("typeA")
52 recdblist.printutf8("title="+tA.group(1))
53 recdblist.printutf8("num="+tA.group(2))
55 recdblist.printutf8("typeB")
56 recdblist.printutf8("title="+tB.group(1))
57 recdblist.printutf8("num="+tB.group(2))
58 recdblist.printutf8("subtitle="+tB.group(3))
59 def search_file(temppath,recpath,ext):
63 avilist = glob.glob(temppath + "/*"+ext)
66 ##b25f is title.ts.b25 avi is title.avi
67 dir = os.path.split(avif)[0]
68 title = os.path.split(avif)[1]
69 title = title.replace(ext, "")
70 avipath = os.path.join(dir, title + ext)
71 dtime = time.time()-os.path.getmtime(avipath)
74 if veryfySize(avipath):
77 def get_move_dest_path(title,temppath,recpath,ext):
78 dstpath=os.path.join(recpath,title+ext)
79 srcpath=os.path.join(temppath,title+ext)
80 if os.path.exists(dstpath):
81 gmtime=time.gmtime(os.path.getmtime(srcpath))
84 iff=u"("+configreader.getenv("iff")+u")_"
89 title=title+u"_"+iff+gmtime.strftime("%Y-%m-%dT%H-%M-%S")
91 def get_delpath(temppath,title):
92 delpath=[os.path.join(temppath,title+".ts")]
93 delpath.append(os.path.join(temppath,title+".avi"))
94 delpath.append(os.path.join(temppath,title+".120.avi"))
95 delpath.append(os.path.join(temppath,title+".timecode.txt"))
96 delpath.append(os.path.join(temppath,title+".aac"))
97 delpath.append(os.path.join(temppath,title+".ts.b25"))
98 delpath.append(os.path.join(temppath,title+".ts.tsmix"))
99 delpath.append(os.path.join(temppath,title+".ts.log"))
100 delpath.append(os.path.join(temppath,title+".sa.avi"))
101 delpath.append(os.path.join(temppath,title+".sa.avi.log"))
102 delpath.append(os.path.join(temppath,title+".log"))
104 def searchFolder(title,path,threshold=500):
106 titleにマッチするフォルダを探し出す。
108 folderpath=os.listdir(path)
111 for ft in folderpath:
112 fullpath=os.path.join(path.encode('utf-8'), ft)
113 if os.path.isdir(fullpath):
114 lfpath.append(fullpath)
115 ftt=os.listdir(fullpath)
119 folderpath.append(os.path.join(fullpath, ft2))
120 except Exception, inst:
125 lfpath.append(fullpath)
130 if os.path.isdir(dirp):
131 cmpp=os.path.dirname(dirp)
134 cmpp=os.path.basename(dirp)
135 appp=os.path.dirname(dirp)
136 ntitle=getTitle(title)
137 #recdblist.printutf8(cmpp)
138 cmpp=getTitle(os.path.splitext(cmpp)[0])
139 #recdblist.printutf8(cmpp+"\n")
140 p=n_gram.trigram(ntitle,cmpp)
142 ngram.append((p,appp))
143 ngram=list(set(ngram))
147 #recdblist.printutf8(title + ngram[0][1] + " : "+str(ngram[0][0]))
148 if ngram[0][0]>threshold:
154 def execMove(title,temppath,recpath,ext,autodel):
155 srcpath=os.path.join(temppath,title+ext)
156 #desttitle=destName(title, temppath, recpath)
158 sf=searchFolder(title, recpath)
160 destpath=os.path.join(sf,destNameMKV(title, temppath, sf)+ext)
161 recdblist.printutf8("moving now..")
162 recdblist.printutf8(srcpath+" : "+destpath)
164 shutil.move(srcpath, destpath)
165 #shutil.copy(srcpath, destpath)
167 delpath=get_delpath(temppath, title)