3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
7 __date__ ="$2009/09/14 17:38:25$"
19 recordedpath=configreader.getpath("recorded")
20 recpath=configreader.getpath("recpath")
23 録画フォルダを検索し、各QUEの実行状況を表示する
25 b25list = glob.glob(path + "/*.b25")
27 ##b25f is title.ts.b25 avi is title.avi
28 dir = os.path.split(b25f)[0]
29 title = os.path.split(b25f)[1]
30 title = title.replace(".ts.b25", "")
31 avipath = os.path.join(dir, title + ".avi")
32 tspath = os.path.join(dir, title + ".ts")
33 b25f = b25f.replace(".ts.b25", ".avi")
35 if os.path.isfile(tspath):##tsファイルが存在している
36 dtime = time.time()-os.path.getmtime(tspath)
39 if os.path.getsize(tspath) > 1 * 1000 * 1000:##最終更新から22分以上経過かつ1MB以上
45 if os.path.isfile(avipath):##tsファイルが存在している
46 dtime = time.time()-os.path.getmtime(avipath)
49 if os.path.getsize(avipath) > 1 * 1000 * 1000:##最終更新から22分以上経過かつ1MB以上
55 print title + ":" + mode
56 def search_avi(temppath,recpath):
60 avilist = glob.glob(temppath + "/*.avi")
63 ##b25f is title.ts.b25 avi is title.avi
64 dir = os.path.split(avif)[0]
65 title = os.path.split(avif)[1]
66 title = title.replace(".avi", "")
67 avipath = os.path.join(dir, title + ".avi")
68 dtime = time.time()-os.path.getmtime(avipath)
71 if veryfySize(avipath):
75 vsize=[297,497,596,1196]#SD 30m 1h 1.5h 2h
76 vsize=vsize+[458,916]#HD 30m 1h
77 vsize=vsize+[381,895,447]
80 if os.path.getsize(path)>(size-10)*1024*1024 and os.path.getsize(path)<(size+10)*1024*1024:
83 def searchFolder(title,path):
87 folderpath=os.listdir(path)
91 fullpath=os.path.join(path, ft)
92 if os.path.isdir(fullpath):
93 lfpath.append(fullpath)
94 ftt=os.listdir(fullpath)
97 folderpath.append(os.path.join(fullpath, ft2))
99 lfpath.append(fullpath)
103 if os.path.isdir(dirp):
104 cmpp=os.path.dirname(dirp)
107 cmpp=os.path.basename(dirp)
108 appp=os.path.dirname(dirp)
109 p=n_gram.trigram(title.decode("utf-8"),cmpp.decode("utf-8"))
111 ngram.append((p,appp))
112 ngram=list(set(ngram))
122 def execMove(title,temppath,recpath):
123 srcpath=os.path.join(temppath,title+".avi")
124 desttitle=destName(title, temppath, recpath)
125 sf=searchFolder(title, recpath)
127 destpath=os.path.join(sf,desttitle+".avi")
128 shutil.move(srcpath, destpath)
129 delpath=[os.path.join(temppath,title+".ts")]
130 delpath.append(os.path.join(temppath,title+".ts.b25"))
131 delpath.append(os.path.join(temppath,title+".ts.b25.log"))
132 delpath.append(os.path.join(temppath,title+".ts.tsmix"))
133 delpath.append(os.path.join(temppath,title+".ts.log"))
134 delpath.append(os.path.join(temppath,title+".sa.avi"))
135 delpath.append(os.path.join(temppath,title+".ts.enc.log"))
136 delpath.append(os.path.join(temppath,title+".ts.b25.rec.log"))
142 def destName(title,temppath,recpath):
144 titleから移動先に作るべきファイル名を作り出す。
146 dstpath=os.path.join(recpath,title+".avi")
147 srcpath=os.path.join(temppath,title+".avi")
148 if os.path.exists(dstpath):
149 gmtime=time.gmtime(os.path.getmtime(srcpath))
150 times=time.strftime("%y%m%d",gmtime)
151 title=title+"_"+times
153 if __name__ == "__main__":
154 usage="usage: %prog read -h"
155 version="%prog 0.7.0alpha"
156 parser=optparse.OptionParser(usage=usage,version=version)
157 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)")
158 parser.add_option("-A","--Auto",action="store_true",dest="auto",default=False,help="auto classifying mode(not a test)")
159 parser.add_option("-e","--exec",action="store",type="string",dest="etitle",default="",metavar="TITLE",help="exec move(not a test)")
160 parser.add_option("-l","--list",action="store_true",dest="list",default=False,help="File listing mode(test for -a)")
161 (opts,args)=parser.parse_args(sys.argv)
163 sf=searchFolder(opts.ltitle, recordedpath)
164 print os.path.join(sf, destName(opts.ltitle,recpath,sf)+".avi")
166 sa=search_avi(recpath, recordedpath)
169 sf=searchFolder(t,recordedpath)
172 print t+" : "+os.path.join(sf, destName(t, recpath,sf)+".avi")
174 execMove(t, recpath, recordedpath)
176 print t+" can't find matching folder."
178 sa=search_avi(recpath, recordedpath)
180 sf=searchFolder(t,recordedpath)
182 print t+" : "+os.path.join(sf, destName(t, recpath,sf)+".avi")
183 elif opts.etitle!="":
184 execMove(opts.etitle,recpath, recordedpath)