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)
150 sf=searchFolder(title, recpath)
152 destpath=os.path.join(sf,destNameMKV(title, temppath, sf)+".mkv")
153 #os.path.join(sf,desttitle+".mkv")
157 print srcpath+" : "+destpath
158 shutil.move(srcpath, destpath)
159 #shutil.copy(srcpath, destpath)
160 delpath=[os.path.join(temppath,title+".ts")]
161 delpath.append(os.path.join(temppath,title+".avi"))
162 delpath.append(os.path.join(temppath,title+".ts.b25"))
163 delpath.append(os.path.join(temppath,title+".ts.tsmix"))
164 delpath.append(os.path.join(temppath,title+".ts.log"))
165 delpath.append(os.path.join(temppath,title+".sa.avi"))
166 delpath.append(os.path.join(temppath,title+".sa.avi.log"))
167 delpath.append(os.path.join(temppath,title+".log"))
174 def destName(title,temppath,recpath):
176 titleから移動先に作るべきファイル名を作り出す。
178 dstpath=os.path.join(recpath,title+".avi")
179 srcpath=os.path.join(temppath,title+".avi")
180 if os.path.exists(dstpath):
181 gmtime=time.gmtime(os.path.getmtime(srcpath))
182 times=time.strftime("%y%m%d",gmtime)
183 title=title+"_"+times
185 def destNameMKV(title,temppath,recpath):
187 titleから移動先に作るべきファイル名を作り出す。
189 dstpath=os.path.join(recpath,title+".mkv")
190 srcpath=os.path.join(temppath,title+".mkv")
191 if os.path.exists(dstpath):
192 gmtime=time.gmtime(os.path.getmtime(srcpath))
193 times=time.strftime("%y%m%d",gmtime)
194 title=title+"_"+times
197 def detName(path,title):
199 type A ---title#<number>
200 type B ---title#<number>subtitle
201 type C ---title subtitle
202 type D ---title(without number)
204 #if re.match("#\d\s[0,10]\z|#[0-9]\s[0,10]\z", title)
206 #elif re.match("#\d\s[0,10].|#[0-9]\s[0,10].", title)
209 def detNameType(title):
211 type A ---title#<number>
212 type B ---title#<number>subtitle
213 type C ---title subtitle
214 type D ---title(without number)
217 #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
218 rA=re.compile("(.+)#(\d*)\s*\Z")
220 rB=re.compile("(.+)#(\d*)\s*(\D*)")
224 print "title="+tA.group(1)
225 print "num="+tA.group(2)
228 print "title="+tB.group(1)
229 print "num="+tB.group(2)
230 print "subtitle="+tB.group(3)
231 if __name__ == "__main__":
232 usage="usage: %prog read -h"
233 version="%prog 0.7.0beta1"
234 parser=optparse.OptionParser(usage=usage,version=version)
235 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)")
236 parser.add_option("-A","--Auto",action="store_true",dest="auto",default=False,help="auto classifying mode(not a test)")
237 parser.add_option("-e","--exec",action="store",type="string",dest="etitle",default="",metavar="TITLE",help="exec move(not a test)")
238 parser.add_option("-l","--list",action="store_true",dest="list",default=False,help="File listing mode(test for -a)")
239 (opts,args)=parser.parse_args(sys.argv)
241 sf=searchFolder(opts.ltitle, recordedpath)
242 print os.path.join(sf, destNameMKV(opts.ltitle,recpath,sf)+".mkv")
244 sa=search_mkv(recpath, recordedpath)
247 sf=searchFolder(t,recordedpath)
250 print t+" : "+os.path.join(sf, destNameMKV(t, recpath,sf)+".mkv")
252 execMove(t, recpath, recordedpath)
254 print t+" can't find matching folder."
256 sa=search_mkv(recpath, recordedpath)
258 sf=searchFolder(t,recordedpath)
260 print t+" : "+os.path.join(sf, destNameMKV(t, recpath,sf)+".mkv")
261 elif opts.etitle!="":
262 execMove(opts.etitle,recpath, recordedpath)