3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
18 def Update_to_MP4(path):
22 avilist = glob.glob(path + "/*.avi")
23 mkvlist = glob.glob(path+"/*.mkv")
24 avilist=avilist+mkvlist
26 if avif.rfind("sa.avi")==-1:
27 dir = os.path.split(avif)[0]
28 title = os.path.split(avif)[1]
29 title = title.replace(".avi", "")
30 title = title.replace(".mkv", "")
31 avipath = os.path.join(dir, title + ".avi")
32 mkvpath = os.path.join(dir, title + ".mkv")
33 mp4path = os.path.join(dir, title + ".mp4")
34 if not os.path.exists(mp4path):
35 if os.path.exists(avipath):
36 avidtime = int(time.time()-os.path.getmtime(avipath))
38 if os.path.exists(mkvpath):
39 mkvdtime = int(time.time()-os.path.getmtime(mkvpath))
41 recdblist.printutf8(mkvpath+":"+mp4path)
42 tv2mp4.mkv2mp4(mkvpath,mp4path)
44 recdblist.printutf8(avipath+":"+mp4path)
45 tv2mp4.avi2mp4(avipath,mp4path)
47 recdblist.printutf8(avipath+":"+mp4path)
48 tv2mp4.avi2mp4(avipath,mp4path)
50 if not os.path.exists(avipath):
51 if os.path.exists(mkvpath):
52 mkvdtime = int(time.time()-os.path.getmtime(mkvpath))
54 recdblist.printutf8(mkvpath+":"+mp4path)
55 tv2mp4.mkv2mp4(mkvpath,mp4path)
57 avilist = glob.glob(path + "/*.avi")
58 mkvlist = glob.glob(path+"/*.mkv")
59 mp4list = glob.glob(path+"/*.mp4")
60 tslist = glob.glob(path+"/*.ts")
61 b25list = glob.glob(path+"/*.ts.b25")
62 filelist=avilist+mkvlist+tslist+b25list+mp4list
64 tbtime=datetime.datetime.now()+datetime.timedelta(seconds=60)
65 tbtime2=datetime.datetime.now()+datetime.timedelta(seconds=1200)
67 if fn.rfind("sa.avi")==-1 and fn.rfind(".120.avi")==-1 and os.path.getsize(fn)>1*1000*1000:
68 dir = os.path.split(fn)[0]
69 file = os.path.split(fn)[1]
70 title = os.path.splitext(file)[0]
71 title = unicode(title,'utf-8')
72 ext = os.path.splitext(file)[1]
74 title=title.replace(".ts","")
75 dbs=rec10d.rec10db.select_by_name_time_timeline(title,tbtime,tbtime2)
77 proc=check_process(dir, title)
78 chtxtt=rec10d.rec10db.select_chtxt_by_title_timeline_log(title)
83 add.append([recdblist.REC_AUTO_SUGGEST_DECODE,title,nchtxt])
85 add.append([recdblist.REC_AUTO_SUGGEST_ENCODE,title,nchtxt])
87 add.append([recdblist.REC_AUTO_SUGGEST_AVI2FP,title,nchtxt])
89 # add.append([recdblist.REC_AUTO_SUGGEST_AP2FP,title,nchtxt])
92 rec10d.rec10db.new_auto_proc()
94 rec10d.rec10db.add_auto_proc(a[0],a[1],a[2])
109 def check_process(path,title):
110 path1 = os.path.join(path,title+".mkv")
111 if os.path.exists(path1):
112 if int(time.time()-os.path.getmtime(path1))>300:
116 elif os.path.exists(os.path.join(path,title+".mp4")):
117 if int(time.time()-os.path.getmtime(os.path.join(path,title+".mp4")))>300:
121 elif os.path.exists(os.path.join(path,title+".264")):
122 if int(time.time()-os.path.getmtime(os.path.join(path,title+".264")))>300:
126 elif os.path.exists(os.path.join(path,title+".ts.log")):
127 if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))<300:
131 elif os.path.exists(os.path.join(path,title+".ts")):
132 if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))>300:
136 elif os.path.exists(os.path.join(path,title+".sa.avi")):
137 if int(time.time()-os.path.getmtime(os.path.join(path,title+".sa.avi")))>300:
141 elif os.path.exists(os.path.join(path,title+".ts.b25")):
142 if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts.b25")))>300:
146 def update_all_timeline_epg():
147 now=datetime.datetime.now()
148 et=now+datetime.timedelta(days=7)
149 update_timeline_epg(now.strftime("%Y-%m-%d %H:%M:%S"), et.strftime("%Y-%m-%d %H:%M:%S"))
150 def update_timeline_epg(btime,etime):
151 update_timeline_epg_schedule(btime,etime)
152 update_timeline_dup(btime,etime)
153 def update_timeline_epg_schedule(btime,etime):
154 dbl=rec10d.rec10db.select_bytime_all_timeline(btime, etime)
158 #[chtxtt, title, btime, etime,exp,longexp,category]
159 if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS:
160 ret=epgdb.searchtime2(db['title'], db['btime'], db['deltatime'], db['chtxt'])
161 if len(ret)>4 and len(ret[2])>18:
162 rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4])
163 if not (db['btime'] == ret[2] and db['etime']==ret[3]):
164 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
166 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
168 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
169 elif db['type']==recdblist.REC_RESERVE or db['type']==recdblist.REC_FINAL_RESERVE :
170 ret=epgdb.searchtime2(db['title'], db['btime'],"5", db['chtxt'])
171 if len(ret)>4 and len(ret[2])>18:
172 rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4])
173 if not (db['btime'] == ret[2] and db['etime']==ret[3]):
174 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
176 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
178 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
179 def update_timeline_dup(epgbtime,epgetime):
180 dbl=rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime)
182 if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS:
183 dbn=epgdb.count_epgschedule(db['epgbtime'], db['epgetime'])
185 bctypet=chdb.chtxtsearch(db['chtxt'])['bctype']
186 if bctypet.find("cs") > -1 or bctypet.find("bs") > -1 :
187 if dbn[1]>status.getRecordingMax()[1]:
188 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
190 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
192 if dbn[0]>status.getRecordingMax()[0]:
193 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
195 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
198 def kill_dead_encode(path):
199 rawlist = glob.glob(path + "/*.264")
201 if int(time.time()-os.path.getmtime(fn))>3000:
202 tspath=unicode(fn.replace(".264",".ts"),'utf-8')
203 m2vpath=unicode(fn.replace(".264",".m2v"),'utf-8')
204 x264path=unicode(fn.replace(".264",".264"),'utf-8')
205 os.environ['LANG']="ja_JP.UTF-8"
207 #ktmp=u"ps auxw | grep \""+tspath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'"
208 #kmmp=u"ps auxw | grep \""+m2vpath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'"
209 #ktmt=commands.getoutput(ktmp.encode('utf-8'))
210 #kmmt=commands.getoutput(kmmp.encode('utf-8'))
212 ktmp=u"ps auxw | grep \""+x264path+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep x264 | awk \"{print $2}\""
213 #recdblist.printutf8(ktmp)
214 ktmt=commands.getoutput(ktmp.encode('utf-8'))
219 ktmp=u"kill -9 '"+ktmp+u"'"
220 os.system(ktmp.encode('utf-8'))
227 kmmp=u"kill -9 '"+kmmp+u"'"
228 os.system(kmmp.encode('utf-8'))