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 mkvpath = os.path.join(dir, title + ".mkv")
33 tspath = os.path.join(dir, title + ".ts")
34 b25f = b25f.replace(".ts.b25", ".avi")
36 if os.path.isfile(tspath):##tsファイルが存在している
37 dtime = time.time()-os.path.getmtime(tspath)
40 if os.path.getsize(tspath) > 1 * 1000 * 1000:##最終更新から22分以上経過かつ1MB以上
46 if os.path.isfile(mkvpath):##tsファイルが存在している
47 dtime = time.time()-os.path.getmtime(mkvpath)
50 if os.path.getsize(avipath) > 1 * 1000 * 1000:##最終更新から22分以上経過かつ1MB以上
56 print title + ":" + mode
57 def search_avi(temppath,recpath):
61 avilist = glob.glob(temppath + "/*.avi")
64 ##b25f is title.ts.b25 avi is title.avi
65 dir = os.path.split(avif)[0]
66 title = os.path.split(avif)[1]
67 title = title.replace(".avi", "")
68 avipath = os.path.join(dir, title + ".avi")
69 dtime = time.time()-os.path.getmtime(avipath)
72 if veryfySize(avipath):
75 def search_mkv(temppath,recpath):
79 avilist = glob.glob(temppath + "/*.mkv")
82 ##b25f is title.ts.b25 avi is title.avi
83 dir = os.path.split(avif)[0]
84 title = os.path.split(avif)[1]
85 title = title.replace(".mkv", "")
86 avipath = os.path.join(dir, title + ".mkv")
87 dtime = time.time()-os.path.getmtime(avipath)
90 if veryfySize(avipath):
95 #vsize=[297,497,596,1196]#SD 30m 1h 1.5h 2h
97 #vsize=vsize+[458,916]#HD 30m 1h
98 #vsize=vsize+[381,895,447]
101 if os.path.getsize(path)>(size-10)*1024*1024 and os.path.getsize(path)<(size+10)*1024*1024:
104 def searchFolder(title,path):
106 titleにマッチするフォルダを探し出す。
108 folderpath=os.listdir(path)
111 for ft in folderpath:
112 fullpath=os.path.join(path, ft)
113 if os.path.isdir(fullpath):
114 lfpath.append(fullpath)
115 ftt=os.listdir(fullpath)
118 folderpath.append(os.path.join(fullpath, ft2))
120 lfpath.append(fullpath)
124 if os.path.isdir(dirp):
125 cmpp=os.path.dirname(dirp)
128 cmpp=os.path.basename(dirp)
129 appp=os.path.dirname(dirp)
130 p=n_gram.trigram(title.decode("utf-8"),cmpp.decode("utf-8"))
132 ngram.append((p,appp))
133 ngram=list(set(ngram))
143 def execMove(title,temppath,recpath):
144 srcpath=os.path.join(temppath,title+".mkv")
145 desttitle=destName(title, temppath, recpath)
146 sf=searchFolder(title, recpath)
148 destpath=os.path.join(sf,desttitle+".mkv")
151 shutil.move(srcpath, destpath)
152 #shutil.copy(srcpath, destpath)
153 delpath=[os.path.join(temppath,title+".ts")]
154 delpath.append(os.path.join(temppath,title+".ts.b25"))
155 delpath.append(os.path.join(temppath,title+".ts.tsmix"))
156 delpath.append(os.path.join(temppath,title+".ts.log"))
157 delpath.append(os.path.join(temppath,title+".sa.avi"))
158 delpath.append(os.path.join(temppath,title+".log"))
165 def destName(title,temppath,recpath):
167 titleから移動先に作るべきファイル名を作り出す。
169 dstpath=os.path.join(recpath,title+".avi")
170 srcpath=os.path.join(temppath,title+".avi")
171 if os.path.exists(dstpath):
172 gmtime=time.gmtime(os.path.getmtime(srcpath))
173 times=time.strftime("%y%m%d",gmtime)
174 title=title+"_"+times
176 def destNameMKV(title,temppath,recpath):
178 titleから移動先に作るべきファイル名を作り出す。
180 dstpath=os.path.join(recpath,title+".mkv")
181 srcpath=os.path.join(temppath,title+".mkv")
182 if os.path.exists(dstpath):
183 gmtime=time.gmtime(os.path.getmtime(srcpath))
184 times=time.strftime("%y%m%d",gmtime)
185 title=title+"_"+times
188 def detName(path,title):
191 if __name__ == "__main__":
192 usage="usage: %prog read -h"
193 version="%prog 0.7.0beta1"
194 parser=optparse.OptionParser(usage=usage,version=version)
195 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)")
196 parser.add_option("-A","--Auto",action="store_true",dest="auto",default=False,help="auto classifying mode(not a test)")
197 parser.add_option("-e","--exec",action="store",type="string",dest="etitle",default="",metavar="TITLE",help="exec move(not a test)")
198 parser.add_option("-l","--list",action="store_true",dest="list",default=False,help="File listing mode(test for -a)")
199 (opts,args)=parser.parse_args(sys.argv)
201 sf=searchFolder(opts.ltitle, recordedpath)
202 print os.path.join(sf, destNameMKV(opts.ltitle,recpath,sf)+".mkv")
204 sa=search_mkv(recpath, recordedpath)
207 sf=searchFolder(t,recordedpath)
210 print t+" : "+os.path.join(sf, destNameMKV(t, recpath,sf)+".mkv")
212 execMove(t, recpath, recordedpath)
214 print t+" can't find matching folder."
216 sa=search_mkv(recpath, recordedpath)
218 sf=searchFolder(t,recordedpath)
220 print t+" : "+os.path.join(sf, destNameMKV(t, recpath,sf)+".mkv")
221 elif opts.etitle!="":
222 execMove(opts.etitle,recpath, recordedpath)