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