3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
17 def Update_to_MP4(path):
21 avilist = glob.glob(path + "/*.avi")
22 mkvlist = glob.glob(path+"/*.mkv")
23 avilist=avilist+mkvlist
25 if avif.rfind("sa.avi")==-1:
26 dir = os.path.split(avif)[0]
27 title = os.path.split(avif)[1]
28 title = title.replace(".avi", "")
29 title = title.replace(".mkv", "")
30 avipath = os.path.join(dir, title + ".avi")
31 mkvpath = os.path.join(dir, title + ".mkv")
32 mp4path = os.path.join(dir, title + ".mp4")
33 if not os.path.exists(mp4path):
34 if os.path.exists(avipath):
35 avidtime = int(time.time()-os.path.getmtime(avipath))
37 if os.path.exists(mkvpath):
38 mkvdtime = int(time.time()-os.path.getmtime(mkvpath))
40 recdblist.printutf8(mkvpath+":"+mp4path)
41 tv2mp4.mkv2mp4(mkvpath,mp4path)
43 recdblist.printutf8(avipath+":"+mp4path)
44 tv2mp4.avi2mp4(avipath,mp4path)
46 recdblist.printutf8(avipath+":"+mp4path)
47 tv2mp4.avi2mp4(avipath,mp4path)
49 if not os.path.exists(avipath):
50 if os.path.exists(mkvpath):
51 mkvdtime = int(time.time()-os.path.getmtime(mkvpath))
53 recdblist.printutf8(mkvpath+":"+mp4path)
54 tv2mp4.mkv2mp4(mkvpath,mp4path)
56 avilist = glob.glob(path + "/*.avi")
57 mkvlist = glob.glob(path+"/*.mkv")
58 mp4list = glob.glob(path+"/*.mp4")
59 tslist = glob.glob(path+"/*.ts")
60 b25list = glob.glob(path+"/*.ts.b25")
61 filelist=avilist+mkvlist+tslist+b25list+mp4list
63 tbtime=datetime.datetime.now()+datetime.timedelta(seconds=60)
64 tbtime2=datetime.datetime.now()+datetime.timedelta(seconds=1200)
66 if fn.rfind("sa.avi")==-1 and fn.rfind(".120.avi")==-1 and os.path.getsize(fn)>1*1000*1000:
67 dir = os.path.split(fn)[0]
68 file = os.path.split(fn)[1]
69 title = os.path.splitext(file)[0]
70 title = unicode(title,'utf-8')
71 ext = os.path.splitext(file)[1]
73 title=title.replace(".ts","")
74 dbs=rec10d.rec10db.select_by_name_time_timeline(title,tbtime,tbtime2)
76 proc=check_process(dir, title)
77 chtxtt=rec10d.rec10db.select_chtxt_by_title_timeline_log(title)
82 add.append([recdblist.REC_AUTO_SUGGEST_DECODE,title,nchtxt])
84 add.append([recdblist.REC_AUTO_SUGGEST_ENCODE,title,nchtxt])
86 add.append([recdblist.REC_AUTO_SUGGEST_AVI2FP,title,nchtxt])
88 # add.append([recdblist.REC_AUTO_SUGGEST_AP2FP,title,nchtxt])
91 rec10d.rec10db.new_auto_proc()
93 rec10d.rec10db.add_auto_proc(a[0],a[1],a[2])
108 def check_process(path,title):
109 path1 = os.path.join(path,title+".mkv")
110 if os.path.exists(path1):
111 if int(time.time()-os.path.getmtime(path1))>300:
115 elif os.path.exists(os.path.join(path,title+".mp4")):
116 if int(time.time()-os.path.getmtime(os.path.join(path,title+".mp4")))>300:
120 elif os.path.exists(os.path.join(path,title+".264")):
121 if int(time.time()-os.path.getmtime(os.path.join(path,title+".264")))>300:
125 elif os.path.exists(os.path.join(path,title+".ts.log")):
126 if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))<300:
130 elif os.path.exists(os.path.join(path,title+".ts")):
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+".sa.avi")):
136 if int(time.time()-os.path.getmtime(os.path.join(path,title+".sa.avi")))>300:
140 elif os.path.exists(os.path.join(path,title+".ts.b25")):
141 if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts.b25")))>300:
145 def update_all_timeline_epg():
146 now=datetime.datetime.now()
147 et=now+datetime.timedelta(days=7)
148 update_timeline_epg(now.strftime("%Y-%m-%d %H:%M:%S"), et.strftime("%Y-%m-%d %H:%M:%S"))
149 def update_timeline_epg(btime,etime):
150 update_timeline_epg_schedule(btime,etime)
151 update_timeline_dup(btime,etime)
152 def update_timeline_epg_schedule(btime,etime):
153 dbl=rec10d.rec10db.select_bytime_all_timeline(btime, etime)
157 #[chtxtt, title, btime, etime,exp,longexp,category]
158 if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS:
159 ret=epgdb.searchtime2(db['title'], db['btime'], db['deltatime'], db['chtxt'])
160 if len(ret)>4 and len(ret[2])>18:
161 rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1])
162 if not (db['btime'] == ret[2] and db['etime']==ret[3]):
163 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
165 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
167 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
168 elif db['type']==recdblist.REC_RESERVE or db['type']==recdblist.REC_FINAL_RESERVE :
169 ret=epgdb.searchtime2(db['title'], db['btime'],"5", db['chtxt'])
170 if len(ret)>4 and len(ret[2])>18:
171 rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1])
172 if not (db['btime'] == ret[2] and db['etime']==ret[3]):
173 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
175 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
177 rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
178 def update_timeline_dup(epgbtime,epgetime):
179 dbl=rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime)
181 if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS:
182 dbn=epgdb.count_epgschedule(db['epgbtime'], db['epgetime'])
184 bctypet=chdb.chtxtsearch(db['chtxt'])['bctype']
185 if bctypet.find("cs") > -1 or bctypet.find("bs") > -1 :
186 if dbn[1]>status.getRecordingMax()[1]:
187 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
189 rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
191 if dbn[0]>status.getRecordingMax()[0]:
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")
197 def kill_dead_encode(path):
198 rawlist = glob.glob(path + "/*.264")
200 if int(time.time()-os.path.getmtime(fn))>3000:
201 tspath=unicode(fn.replace(".264",".ts"),'utf-8')
202 m2vpath=unicode(fn.replace(".264",".m2v"),'utf-8')
203 os.environ['LANG']="ja_JP.UTF-8"
204 ktmp=u"kill -9 `ps auxw | grep \""+tspath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'`"
205 kmmp=u"kill -9 `ps auxw | grep \""+m2vpath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'`"
206 #recdblist.printutf8(ktmp)
207 #recdblist.printutf8(kmmp)
208 os.system(ktmp.encode('utf-8'))
209 os.system(kmmp.encode('utf-8'))