3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
7 __date__ ="$2009/09/14 17:38:25$"
20 recordedpath=configreader.getpath("recorded")
21 recpath=configreader.getpath("recpath")
24 録画フォルダを検索し、各QUEの実行状況を表示する
26 b25list = glob.glob(path + "/*.b25")
28 ##b25f is title.ts.b25 avi is title.avi
29 dir = os.path.split(b25f)[0]
30 title = os.path.split(b25f)[1]
31 title = title.replace(".ts.b25", "")
32 avipath = os.path.join(dir, title + ".avi")
33 mkvpath = os.path.join(dir, title + ".mkv")
34 tspath = os.path.join(dir, title + ".ts")
35 b25f = b25f.replace(".ts.b25", ".avi")
37 if os.path.isfile(tspath):##tsファイルが存在している
38 dtime = time.time()-os.path.getmtime(tspath)
41 if os.path.getsize(tspath) > 1 * 1000 * 1000:##最終更新から22分以上経過かつ1MB以上
47 if os.path.isfile(mkvpath):##tsファイルが存在している
48 dtime = time.time()-os.path.getmtime(mkvpath)
51 if os.path.getsize(avipath) > 1 * 1000 * 1000:##最終更新から22分以上経過かつ1MB以上
57 print title + ":" + mode
58 def search_avi(temppath,recpath):
62 avilist = glob.glob(temppath + "/*.avi")
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(".avi", "")
69 avipath = os.path.join(dir, title + ".avi")
70 dtime = time.time()-os.path.getmtime(avipath)
73 if veryfySize(avipath):
76 def search_mkv(temppath,recpath):
80 avilist = glob.glob(temppath + "/*.mkv")
83 ##b25f is title.ts.b25 avi is title.avi
84 dir = os.path.split(avif)[0]
85 title = os.path.split(avif)[1]
86 title = title.replace(".mkv", "")
87 avipath = os.path.join(dir, title + ".mkv")
88 dtime = time.time()-os.path.getmtime(avipath)
91 if veryfySize(avipath):
96 #vsize=[297,497,596,1196]#SD 30m 1h 1.5h 2h
97 vsize=[245,275,295,591,830]
98 vsize=vsize+[325,560,590,602,690,860]
99 #vsize=vsize+[458,916]#HD 30m 1h
100 #vsize=vsize+[381,895,447]
103 if os.path.getsize(path)>(size-10)*1024*1024 and os.path.getsize(path)<(size+10)*1024*1024:
106 def searchFolder(title,path):
108 titleにマッチするフォルダを探し出す。
110 folderpath=os.listdir(path)
113 for ft in folderpath:
114 fullpath=os.path.join(path, ft)
115 if os.path.isdir(fullpath):
116 lfpath.append(fullpath)
117 ftt=os.listdir(fullpath)
120 folderpath.append(os.path.join(fullpath, ft2))
122 lfpath.append(fullpath)
126 if os.path.isdir(dirp):
127 cmpp=os.path.dirname(dirp)
130 cmpp=os.path.basename(dirp)
131 appp=os.path.dirname(dirp)
132 p=n_gram.trigram(title.decode("utf-8"),cmpp.decode("utf-8"))
134 ngram.append((p,appp))
135 ngram=list(set(ngram))
139 #print title + ngram[0][1] + " : "+str(ngram[0][0])
146 def execMove(title,temppath,recpath):
147 srcpath=os.path.join(temppath,title+".mkv")
148 desttitle=destName(title, temppath, recpath)
149 sf=searchFolder(title, recpath)
151 destpath=os.path.join(sf,desttitle+".mkv")
154 shutil.move(srcpath, destpath)
155 #shutil.copy(srcpath, destpath)
156 delpath=[os.path.join(temppath,title+".ts")]
157 delpath.append(os.path.join(temppath,title+".avi"))
158 delpath.append(os.path.join(temppath,title+".ts.b25"))
159 delpath.append(os.path.join(temppath,title+".ts.tsmix"))
160 delpath.append(os.path.join(temppath,title+".ts.log"))
161 delpath.append(os.path.join(temppath,title+".sa.avi"))
162 delpath.append(os.path.join(temppath,title+".log"))
169 def destName(title,temppath,recpath):
171 titleから移動先に作るべきファイル名を作り出す。
173 dstpath=os.path.join(recpath,title+".avi")
174 srcpath=os.path.join(temppath,title+".avi")
175 if os.path.exists(dstpath):
176 gmtime=time.gmtime(os.path.getmtime(srcpath))
177 times=time.strftime("%y%m%d",gmtime)
178 title=title+"_"+times
180 def destNameMKV(title,temppath,recpath):
182 titleから移動先に作るべきファイル名を作り出す。
184 dstpath=os.path.join(recpath,title+".mkv")
185 srcpath=os.path.join(temppath,title+".mkv")
186 if os.path.exists(dstpath):
187 gmtime=time.gmtime(os.path.getmtime(srcpath))
188 times=time.strftime("%y%m%d",gmtime)
189 title=title+"_"+times
192 def detName(path,title):
194 type A ---title#<number>
195 type B ---title#<number>subtitle
196 type C ---title subtitle
197 type D ---title(without number)
199 #if re.match("#\d\s[0,10]\z|#[0-9]\s[0,10]\z", title)
201 #elif re.match("#\d\s[0,10].|#[0-9]\s[0,10].", title)
204 def detNameType(title):
206 type A ---title#<number>
207 type B ---title#<number>subtitle
208 type C ---title subtitle
209 type D ---title(without number)
212 #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
213 rA=re.compile("(.+)#(\d*)\s*\Z")
215 rB=re.compile("(.+)#(\d*)\s*(\D*)")
219 print "title="+tA.group(1)
220 print "num="+tA.group(2)
223 print "title="+tB.group(1)
224 print "num="+tB.group(2)
225 print "subtitle="+tB.group(3)
226 if __name__ == "__main__":
227 usage="usage: %prog read -h"
228 version="%prog 0.7.0beta1"
229 parser=optparse.OptionParser(usage=usage,version=version)
230 parser.add_option("-s","--search",action="store",type="string",dest="ltitle",default="",metavar="TITLE",help="test to search where the title should be contained(test for -e)")
231 parser.add_option("-A","--Auto",action="store_true",dest="auto",default=False,help="auto classifying mode(not a test)")
232 parser.add_option("-e","--exec",action="store",type="string",dest="etitle",default="",metavar="TITLE",help="exec move(not a test)")
233 parser.add_option("-l","--list",action="store_true",dest="list",default=False,help="File listing mode(test for -a)")
234 (opts,args)=parser.parse_args(sys.argv)
236 sf=searchFolder(opts.ltitle, recordedpath)
237 print os.path.join(sf, destNameMKV(opts.ltitle,recpath,sf)+".mkv")
239 sa=search_mkv(recpath, recordedpath)
242 sf=searchFolder(t,recordedpath)
245 print t+" : "+os.path.join(sf, destNameMKV(t, recpath,sf)+".mkv")
247 execMove(t, recpath, recordedpath)
249 print t+" can't find matching folder."
251 sa=search_mkv(recpath, recordedpath)
253 sf=searchFolder(t,recordedpath)
255 print t+" : "+os.path.join(sf, destNameMKV(t, recpath,sf)+".mkv")
256 elif opts.etitle!="":
257 execMove(opts.etitle,recpath, recordedpath)