4 # Rec10 TS Recording Tools
5 # Copyright (C) 2009 Yukikaze
8 __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 tspath = os.path.join(dir, title + ".ts")
69 b25path = os.path.join(dir, title + ".ts.b25")
70 b25logpath = os.path.join(dir, title + ".ts.b25.log")
71 sapath = os.path.join(dir, title + ".sa.avi")
72 dtime = time.time()-os.path.getmtime(avipath)
74 #print title+str(dtime)
76 if veryfySize(avipath):
80 vsize=[297,596,458,916]
83 if os.path.getsize(path)>(size-5)*1024*1024 and os.path.getsize(path)<(size+5)*1024*1024:
86 def searchFolder(title,path):
90 folderpath=os.listdir(path)
94 fullpath=os.path.join(path, ft)
95 if os.path.isdir(fullpath):
96 lfpath.append(fullpath)
97 ftt=os.listdir(fullpath)
100 folderpath.append(os.path.join(fullpath, ft2))
102 lfpath.append(fullpath)
106 if os.path.isdir(dirp):
107 cmpp=os.path.dirname(dirp)
110 cmpp=os.path.basename(dirp)
111 appp=os.path.dirname(dirp)
112 p=n_gram.trigram(title.decode("utf-8"),cmpp.decode("utf-8"))
114 ngram.append((p,appp))
115 ngram=list(set(ngram))
125 def execMove(title,temppath,recpath):
126 srcpath=os.path.join(temppath,title+".avi")
127 desttitle=destName(title, temppath, recpath)
128 sf=searchFolder(title, recpath)
130 destpath=os.path.join(sf,desttitle+".avi")
131 shutil.move(srcpath, destpath)
132 delpath=[os.path.join(temppath,title+".ts")]
133 delpath.append(os.path.join(temppath,title+".ts.b25"))
134 delpath.append(os.path.join(temppath,title+".ts.b25.log"))
135 delpath.append(os.path.join(temppath,title+".ts.tsmix"))
136 delpath.append(os.path.join(temppath,title+".sa.avi"))
142 def destName(title,temppath,recpath):
144 titleから移動先に作るべきファイル名を作り出す。
146 dstpath=os.path.join(recpath,title+".avi")
147 srcpath=os.path.join(temppath,title+".avi")
149 if os.path.exists(dstpath):
150 gmtime=time.gmtime(os.path.getmtime(srcpath))
151 times=time.strftime("%y%m%d",gmtime)
152 title=title+"_"+times
154 if __name__ == "__main__":
155 usage="usage: %prog [-l Title] [-a]"
156 version="%prog 0.7.0alpha"
157 parser=optparse.OptionParser(usage=usage,version=version)
158 parser.add_option("-s","--search",action="store",type="string",dest="ltitle",default="",metavar="TITLE",help="test to search where the title should be contained.")
159 parser.add_option("-A","--Auto",action="store_true",dest="auto",default=False,help="auto disposing mode")
160 parser.add_option("-s","--search",action="store",type="string",dest="etitle",default="",metavar="TITLE",help="exec move.")
161 parser.add_option("-l","--list",action="store_true",dest="list",default=False,help="File listing mode")
162 (opts,args)=parser.parse_args(sys.argv)
164 sf=searchFolder(opts.ltitle, recordedpath)
165 print os.path.join(sf, destName(opts.ltitle,recpath,sf)+".avi")
167 sa=search_avi(recpath, recordedpath)
170 sf=searchFolder(t,recpath)
173 print t+" : "+os.path.join(sf, destName(t, recpath,sf)+".avi")
175 execMove(t, recpath, recordedpath)
177 sa=search_avi(recpath, recordedpath)
179 sf=searchFolder(t,recpath)
181 print t+" : "+os.path.join(sf, destName(t, recpath,sf)+".avi")
182 elif opts.etitle!="":
183 execMove(opts.etitle,recpath, recordedpath)