3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
20 def Update_to_MP4(path):
24 avilist = glob.glob(path + "/*.avi")
25 mkvlist = glob.glob(path+"/*.mkv")
26 avilist=avilist+mkvlist
28 if avif.rfind("sa.avi")==-1:
29 dir = os.path.split(avif)[0]
30 title = os.path.split(avif)[1]
31 title = title.replace(".avi", "")
32 title = title.replace(".mkv", "")
33 avipath = os.path.join(dir, title + ".avi")
34 mkvpath = os.path.join(dir, title + ".mkv")
35 mp4path = os.path.join(dir, title + ".mp4")
36 if not os.path.exists(mp4path):
37 if os.path.exists(avipath):
38 avidtime = int(time.time()-os.path.getmtime(avipath))
40 if os.path.exists(mkvpath):
41 mkvdtime = int(time.time()-os.path.getmtime(mkvpath))
43 recdblist.printutf8(mkvpath+":"+mp4path)
44 tv2mp4.mkv2mp4(mkvpath,mp4path)
46 recdblist.printutf8(avipath+":"+mp4path)
47 tv2mp4.avi2mp4(avipath,mp4path)
49 recdblist.printutf8(avipath+":"+mp4path)
50 tv2mp4.avi2mp4(avipath,mp4path)
52 if not os.path.exists(avipath):
53 if os.path.exists(mkvpath):
54 mkvdtime = int(time.time()-os.path.getmtime(mkvpath))
56 recdblist.printutf8(mkvpath+":"+mp4path)
57 tv2mp4.mkv2mp4(mkvpath,mp4path)
59 avilist = glob.glob(path + "/*.avi")
60 mkvlist = glob.glob(path+"/*.mkv")
61 mp4list = glob.glob(path+"/*.mp4")
62 tslist = glob.glob(path+"/*.ts")
63 b25list = glob.glob(path+"/*.ts.b25")
64 filelist=avilist+mkvlist+tslist+b25list+mp4list
66 tbtime=datetime.datetime.now()+datetime.timedelta(seconds=60)
67 tbtime2=datetime.datetime.now()+datetime.timedelta(seconds=1200)
69 if os.path.exists(fn):
70 if fn.rfind("sa.avi")==-1 and fn.rfind(".120.avi")==-1 and os.path.getsize(fn)>1*1000*1000:
71 dir = os.path.split(fn)[0]
72 file = os.path.split(fn)[1]
73 title = os.path.splitext(file)[0]
74 title = unicode(title,'utf-8')
75 ext = os.path.splitext(file)[1]
77 title=title.replace(".ts","")
78 dbs=rec10d.rec10db.select_by_name_time_timeline(title,tbtime,tbtime2)
80 proc=check_process(dir, title)
81 chtxtt=rec10d.rec10db.select_chtxt_by_title_timeline_log(title)
86 add.append([recdblist.REC_AUTO_SUGGEST_DECODE,title,nchtxt])
88 add.append([recdblist.REC_AUTO_SUGGEST_ENCODE,title,nchtxt])
90 add.append([recdblist.REC_AUTO_SUGGEST_AVI2FP,title,nchtxt])
92 # add.append([recdblist.REC_AUTO_SUGGEST_AP2FP,title,nchtxt])
95 rec10d.rec10db.new_auto_proc()
97 rec10d.rec10db.add_auto_proc(a[0],a[1],a[2])
100 処理がどの段階まで言ったのかを調査し返す。
112 def check_process(path,title):
113 path1 = os.path.join(path,title+".mkv")
114 if os.path.exists(path1):
115 if int(time.time()-os.path.getmtime(path1))>300:
119 elif os.path.exists(os.path.join(path,title+".mp4")):
120 if int(time.time()-os.path.getmtime(os.path.join(path,title+".mp4")))>300:
124 elif os.path.exists(os.path.join(path,title+".264")):
125 if int(time.time()-os.path.getmtime(os.path.join(path,title+".264")))>300:
129 elif os.path.exists(os.path.join(path,title+".ts.log")):
130 if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))<300:
134 elif os.path.exists(os.path.join(path,title+".ts")):
135 if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))>300:
139 elif os.path.exists(os.path.join(path,title+".sa.avi")):
140 if int(time.time()-os.path.getmtime(os.path.join(path,title+".sa.avi")))>300:
144 elif os.path.exists(os.path.join(path,title+".ts.b25")):
145 if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts.b25")))>300:
149 def update_all_timeline_epg():
150 now=datetime.datetime.now()
151 et=now+datetime.timedelta(days=7)
152 update_timeline_epg(now.strftime("%Y-%m-%d %H:%M:%S"), et.strftime("%Y-%m-%d %H:%M:%S"))
153 def update_timeline_epg(btime,etime):
154 update_timeline_epg_schedule(btime,etime)
155 update_timeline_dup(btime,etime)
156 def update_timeline_epg_schedule(btime,etime):
157 dbl=rec10d.rec10db.select_bytime_all_timeline(btime, etime)
161 #[chtxtt, title, btime, etime,exp,longexp,category]
162 if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS:
163 ret=epgdb.searchtime2(db['title'], db['btime'], db['deltatime'], db['chtxt'])
164 if len(ret)>4 and len(ret[2])>18:
165 rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4])
166 if not (db['btime'] == ret[2] and db['etime']==ret[3]):
167 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
169 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
171 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
172 elif db['type']==recdblist.REC_RESERVE or db['type']==recdblist.REC_FINAL_RESERVE :
173 ret=epgdb.searchtime2(db['title'], db['btime'],"5", db['chtxt'])
174 if len(ret)>4 and len(ret[2])>18:
175 rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4])
176 if not (db['btime'] == ret[2] and db['etime']==ret[3]):
177 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
179 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
181 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
182 def update_timeline_dup(epgbtime,epgetime):
183 dbl=rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime)
185 if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS:
186 dbn=epgdb.count_epgschedule(db['epgbtime'], db['epgetime'])
188 bctypet=chdb.chtxtsearch(db['chtxt'])['bctype']
189 if bctypet.find("cs") > -1 or bctypet.find("bs") > -1 :
190 if dbn[1]>status.getRecordingMax()[1]:
191 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
193 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
195 if dbn[0]>status.getRecordingMax()[0]:
196 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
198 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
201 def kill_dead_encode(path):
202 rawlist = glob.glob(path + "/*.264")
204 if int(time.time()-os.path.getmtime(fn))>3000:
207 tspath=unicode(fn.replace(".264",".ts"),'utf-8')
208 m2vpath=unicode(fn.replace(".264",".m2v"),'utf-8')
209 x264path=unicode(fn.replace(".264",".264"),'utf-8')
210 os.environ['LANG']="ja_JP.UTF-8"
212 #ktmp=u"ps auxw | grep \""+tspath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'"
213 #kmmp=u"ps auxw | grep \""+m2vpath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'"
214 #ktmt=commands.getoutput(ktmp.encode('utf-8'))
215 #kmmt=commands.getoutput(kmmp.encode('utf-8'))
217 ktmp=u"ps auxw | grep \""+x264path+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep x264 | awk '{print $2}'"
218 #recdblist.printutf8(ktmp)
219 ktmt=commands.getoutput(ktmp.encode('utf-8'))
225 ktmp=u"kill -9 `"+ktmp+u"`"
227 recdblist.printutf8(ktmp)
228 os.system(ktmp.encode('utf-8'))
235 kmmp=u"kill -9 '"+kmmp+u"'"
236 os.system(kmmp.encode('utf-8'))
239 def deltmpfile(path,title,ext):
240 level= 0##0:b25 1:ts(del tsmix and ts.b25) 5:x264(del 2 and so on) 10:mp4/mkv
242 if re.search(".ts",ext):
244 smsize = 100*1000*1000
245 elif re.search(".264",ext):
247 smsize = 10*1000*1000
248 elif re.search(".mp4",ext):
250 smsize = 10*1000*1000
251 elif re.search(".mkv",ext):
253 smsize = 10*1000*1000
256 if os.path.exists(os.path.join(path,title+".ts")) and os.path.exists(os.path.join(path,title+".ts.b25")):
257 if os.path.getsize(os.path.join(path,title+".ts"))*10>os.path.getsize(os.path.join(path,title+".ts.b25")):
258 dp.append(os.path.join(path,title+".ts.b25"))
260 if configreader.getenv("remove_ts")=="1":
261 dp.append(os.path.join(path,title+".ts"))
263 dp.append(os.path.join(path,title+".avi"))
264 dp.append(os.path.join(path,title+".264"))
265 dp.append(os.path.join(path,title+".120.avi"))
266 dp.append(os.path.join(path,title+".noodml.avi"))
267 dp.append(os.path.join(path,title+".aac"))
268 dp.append(os.path.join(path,title+".m2v"))
269 dp.append(os.path.join(path,title+"_1.aac"))
270 dp.append(os.path.join(path,title+"_2.aac"))
271 dp.append(os.path.join(path,title+"_1.mp3"))
272 dp.append(os.path.join(path,title+"_2.mp3"))
273 dp.append(os.path.join(path,title+".srt"))
275 dp.append(os.path.join(path,title+".mp4"))
276 if os.path.exists(os.path.join(path,title+ext)):
277 if os.path.getsize(os.path.join(path,title+ext))>smsize: