3 # Rec10 TS Recording Tools
\r
4 # Copyright (C) 2009-2011 Yukikaze
\r
20 def updateToMP4(path):
\r
25 avilist = glob.glob(path + "/*.avi")
\r
26 mkvlist = glob.glob(path+"/*.mkv")
\r
27 avilist=avilist+mkvlist
\r
28 for avif in avilist:
\r
29 if avif.rfind("sa.avi")==-1:
\r
30 dir = os.path.split(avif)[0]
\r
31 title = os.path.split(avif)[1]
\r
32 title = title.replace(".avi", "")
\r
33 title = title.replace(".mkv", "")
\r
34 avipath = os.path.join(dir, title + ".avi")
\r
35 mkvpath = os.path.join(dir, title + ".mkv")
\r
36 mp4path = os.path.join(dir, title + ".mp4")
\r
37 if not os.path.exists(mp4path):
\r
38 if os.path.exists(avipath):
\r
39 avidtime = int(time.time()-os.path.getmtime(avipath))
\r
41 if os.path.exists(mkvpath):
\r
42 mkvdtime = int(time.time()-os.path.getmtime(mkvpath))
\r
44 recdblist.printutf8(mkvpath+":"+mp4path)
\r
45 tv2mp4.mkv2mp4(mkvpath,mp4path)
\r
47 recdblist.printutf8(avipath+":"+mp4path)
\r
48 tv2mp4.avi2mp4(avipath,mp4path)
\r
50 recdblist.printutf8(avipath+":"+mp4path)
\r
51 tv2mp4.avi2mp4(avipath,mp4path)
\r
53 if not os.path.exists(avipath):
\r
54 if os.path.exists(mkvpath):
\r
55 mkvdtime = int(time.time()-os.path.getmtime(mkvpath))
\r
57 recdblist.printutf8(mkvpath+":"+mp4path)
\r
58 tv2mp4.mkv2mp4(mkvpath,mp4path)
\r
59 def autoCheck(path):
\r
60 avilist = glob.glob(path + "/*.avi")
\r
61 mkvlist = glob.glob(path+"/*.mkv")
\r
62 mp4list = glob.glob(path+"/*.mp4")
\r
63 tslist = glob.glob(path+"/*.ts")
\r
64 b25list = glob.glob(path+"/*.ts.b25")
\r
65 filelist=avilist+mkvlist+tslist+b25list+mp4list
\r
67 tbtime=datetime.datetime.now()+datetime.timedelta(seconds=60)
\r
68 tbtime2=datetime.datetime.now()+datetime.timedelta(seconds=1200)
\r
70 if os.path.exists(fn):
\r
71 if fn.rfind("sa.avi")==-1 and fn.rfind(".120.avi")==-1 and os.path.getsize(fn)>1*1000*1000:
\r
72 dir = os.path.split(fn)[0]
\r
73 file = os.path.split(fn)[1]
\r
74 title = os.path.splitext(file)[0]
\r
75 title = unicode(title,'utf-8',errors='replace')
\r
76 ext = os.path.splitext(file)[1]
\r
78 title=title.replace(".ts","")
\r
79 dbs=rec10d.rec10db.select_by_name_time_timeline(title,tbtime,tbtime2)
\r
81 proc=checkProcess(dir, title)
\r
82 chtxtt=rec10d.rec10db.select_chtxt_by_title_timeline_log(title)
\r
87 add.append([recdblist.REC_AUTO_SUGGEST_DECODE,title,nchtxt])
\r
89 add.append([recdblist.REC_AUTO_SUGGEST_ENCODE,title,nchtxt])
\r
91 add.append([recdblist.REC_AUTO_SUGGEST_AVI2FP,title,nchtxt])
\r
93 # add.append([recdblist.REC_AUTO_SUGGEST_AP2FP,title,nchtxt])
\r
96 rec10d.rec10db.new_auto_proc()
\r
98 rec10d.rec10db.add_auto_proc(a[0],a[1],a[2])
\r
101 処理がどの段階まで言ったのかを調査し返す。
\r
113 def checkProcess(path,title):
\r
114 path1 = os.path.join(path,title+".mkv")
\r
115 if os.path.exists(path1):
\r
116 if int(time.time()-os.path.getmtime(path1))>300:
\r
120 elif os.path.exists(os.path.join(path,title+".mp4")):
\r
121 if int(time.time()-os.path.getmtime(os.path.join(path,title+".mp4")))>300:
\r
125 elif os.path.exists(os.path.join(path,title+".264")):
\r
126 if int(time.time()-os.path.getmtime(os.path.join(path,title+".264")))>300:
\r
130 elif os.path.exists(os.path.join(path,title+".ts.log")):
\r
131 if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))<300:
\r
135 elif os.path.exists(os.path.join(path,title+".ts")):
\r
136 if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))>300:
\r
139 return "tssplitting"
\r
140 elif os.path.exists(os.path.join(path,title+".sa.avi")):
\r
141 if int(time.time()-os.path.getmtime(os.path.join(path,title+".sa.avi")))>300:
\r
144 return "tssplitting"
\r
145 elif os.path.exists(os.path.join(path,title+".ts.b25")):
\r
146 if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts.b25")))>300:
\r
150 def update_all_timeline_epg():
\r
151 now=datetime.datetime.now()
\r
152 et=now+datetime.timedelta(days=7)
\r
153 update_timeline_epg(now.strftime("%Y-%m-%d %H:%M:%S"), et.strftime("%Y-%m-%d %H:%M:%S"))
\r
154 def update_timeline_epg(btime,etime):
\r
155 update_timeline_epg_schedule(btime,etime)
\r
156 update_timeline_dup(btime,etime)
\r
157 def update_timeline_epg_schedule(btime,etime):
\r
158 dbl=rec10d.rec10db.select_bytime_all_timeline(btime, etime)
\r
162 #[chtxtt, title, btime, etime,exp,longexp,category]
\r
163 if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS:
\r
164 ret=epgdb.searchTime(db['title'], db['btime'], db['deltatime'], db['chtxt'])
\r
165 if len(ret)>4 and len(ret[2])>18:
\r
166 rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4],ret[6])
\r
167 if not (db['btime'] == ret[2] and db['etime']==ret[3]):
\r
168 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
\r
170 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
\r
172 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
\r
173 elif db['type']==recdblist.REC_RESERVE or db['type']==recdblist.REC_FINAL_RESERVE :
\r
174 ret=epgdb.searchTime(db['title'], db['btime'],"5", db['chtxt'])
\r
175 if len(ret)>4 and len(ret[2])>18:
\r
176 rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4],ret[6])
\r
177 if not (db['btime'] == ret[2] and db['etime']==ret[3]):
\r
178 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
\r
180 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
\r
182 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
\r
183 def update_timeline_dup(epgbtime,epgetime):
\r
184 dbl=rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime)
\r
186 if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS:
\r
187 dbn=epgdb.countEpgSchedule(db['epgbtime'], db['epgetime'])
\r
189 bctypet=chdb.searchCHFromChtxt(db['chtxt'])['bctype']
\r
190 if bctypet.find("cs") > -1 or bctypet.find("bs") > -1 :
\r
191 if dbn[1]>status.getRecordingMax()[1]:
\r
192 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
\r
194 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
\r
196 if dbn[0]>status.getRecordingMax()[0]:
\r
197 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
\r
199 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
\r
202 def killDeadEncode(path):
\r
203 rawlist = glob.glob(path + "/*.264")
\r
205 if int(time.time()-os.path.getmtime(fn))>3000:
\r
206 m2vpath=unicode(fn.replace(".264",".m2v"),'utf-8')
\r
207 x264path=os.path.split(fn)[1]
\r
208 folderpath=unicode(os.path.split(fn)[0],'utf-8')
\r
209 x264path=re.sub("\\[","[",x264path)
\r
210 x264path=re.sub("\[","\\\[",x264path)
\r
211 x264path=re.sub("\\]","]",x264path)
\r
212 x264path=re.sub("]","\\]",x264path)
\r
213 tspath=unicode(x264path.replace(".264",".ts"),'utf-8')
\r
214 m2vpath=unicode(x264path.replace(".264",".m2v"),'utf-8')
\r
215 x264path=unicode(x264path,'utf-8')
\r
216 os.environ['LANG']="ja_JP.UTF-8"
\r
218 ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+x264path+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep x264 | awk '{print $2}'")
\r
219 ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+tspath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'")
\r
220 ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+m2vpath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep ffmpeg | awk '{print $2}'")
\r
221 recdblist.printutf8(u"エンコード処理異常終了タスク終了")
\r
223 recdblist.printutf8(istr)
\r
224 ktmt=commands.getoutput(istr.encode('utf-8'))
\r
234 ktmp=u"kill -9 `"+istr+u"`"
\r
235 recdblist.printutf8(ktmp)
\r
237 os.system(ktmp.encode('utf-8'))
\r
240 def deleteTmpFile(path,title,ext):
\r
241 level= 0##0:b25 1:ts(del tsmix and ts.b25) 5:x264(del 2 and so on) 10:mp4/mkv
\r
243 if re.search(".ts",ext):
\r
245 smsize = 100*1000*1000
\r
246 elif re.search(".264",ext):
\r
248 smsize = 10*1000*1000
\r
249 elif re.search(".mp4",ext):
\r
251 smsize = 10*1000*1000
\r
252 elif re.search(".mkv",ext):
\r
254 smsize = 10*1000*1000
\r
257 if os.path.exists(os.path.join(path,title+".ts")) and os.path.exists(os.path.join(path,title+".ts.b25")):
\r
258 if os.path.getsize(os.path.join(path,title+".ts"))*12>os.path.getsize(os.path.join(path,title+".ts.b25")):
\r
259 dp.append(os.path.join(path,title+".ts.b25"))
\r
260 elif os.path.getsize(os.path.join(path,title+".ts"))>200*1000*1000:
\r
261 dp.append(os.path.join(path,title+".ts.b25"))
\r
263 if configreader.getConfEnv("remove_ts")=="1":
\r
264 dp.append(os.path.join(path,title+".ts"))
\r
266 dp.append(os.path.join(path,title+".avi"))
\r
267 dp.append(os.path.join(path,title+".264"))
\r
268 dp.append(os.path.join(path,title+".120.avi"))
\r
269 dp.append(os.path.join(path,title+".noodml.avi"))
\r
270 dp.append(os.path.join(path,title+".aac"))
\r
271 dp.append(os.path.join(path,title+".m2v"))
\r
272 dp.append(os.path.join(path,title+"_1.aac"))
\r
273 dp.append(os.path.join(path,title+"_2.aac"))
\r
274 dp.append(os.path.join(path,title+"_1.mp3"))
\r
275 dp.append(os.path.join(path,title+"_2.mp3"))
\r
276 dp.append(os.path.join(path,title+".srt"))
\r
278 dp.append(os.path.join(path,title+".mp4"))
\r
279 if os.path.exists(os.path.join(path,title+ext)):
\r
280 if os.path.getsize(os.path.join(path,title+ext))>smsize:
\r