OSDN Git Service

change db mode.
[rec10/rec10-git.git] / rec10 / trunk / src / timerec.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
5 import datetime
6 import os
7 import os.path
8 import re
9 import sys
10 import time
11 import shutil
12
13 import auto_rec
14 import auto_process
15 import chdb
16 import checker
17 import configreader
18 import epgdb
19 import rec10d
20 import recdb
21 import status
22 import tv2avi
23 import tv2mkv
24 import tv2mp4
25 import install
26 import recdblist
27 recpath = configreader.getpath('recpath')
28 movepath = configreader.getpath('move_destpath')
29 path = str(os.path.dirname(os.path.abspath(__file__))) + "/"
30 def task():
31     """
32     数分毎に実行されるタスク処理
33     予定によって子プロセスを生成し処理する。
34     """
35     try:
36         if rec10d.rec10db.select_installed_in_status()==0:
37             install.install()
38     except:
39         install.install()
40     recdb.delete_old("24")
41     recdb.delete_old_auto_bayes("1")
42     recdb.delete_old_auto_keyword("1")
43     tasks = recdb.getnow("3")
44     inum = recdb.countRecNow_minutes("10")
45     recdblist.printutf8(u"rec10処理開始"+ datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
46     recdblist.printutf8(u"直近録画予約件数:" + str(inum) + u"BS/CS録画中件数:" + str(status.getBSCSRecording()) + u"TE録画中件数:" + str(status.getTERecording()) )
47     encodenum=0
48     b25num=0
49     dnow=datetime.datetime.now()
50     if dnow.minute%10<5:
51         pid = os.fork()
52         if pid != 0:
53             ""
54         else:
55             for k in recdb.get_key():
56                 search_keyword(k)
57             sys.exit()
58     else:
59         pid = os.fork()
60         if pid!=0:
61             ""
62         else:
63             time.sleep(10)
64             auto_process.auto_check(recpath)
65             sys.exit()
66     update = chdb.update()
67     if len(update) > 0:
68         pid = os.fork()
69         if pid != 0:
70             ""
71         else:
72             i = 0
73             for bctype in update:
74                 recnum = 0
75                 if bctype.find('te') > -1:
76                     recnum = status.getTERecording() + recdb.countRecNow_minutes_TE("10")
77                     recdblist.printutf8(u"放送種別:"+bctype + u"||該当チューナー実行中件数:" + str(status.getTERecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_TE("10")))
78                     recnum = int(configreader.getenv("te_max")) -recnum
79                 else:
80                     recnum = status.getBSCSRecording() + recdb.countRecNow_minutes_BSCS("10")
81                     recdblist.printutf8(u"放送種別:"+bctype + u"||該当チューナー実行中件数:" + str(status.getBSCSRecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_BSCS("10")))
82                     recnum = int(configreader.getenv("bscs_max")) -recnum
83                 if recnum >0 :
84                     print update
85                     rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "0")
86                     epgdb.updatebc(bctype)
87                     update = chdb.update()
88                     i = i + 1
89                 if i > 0:
90                     break
91             sys.exit()
92     for task in tasks:
93         typetxt = task["type"]
94         try:
95             chtxt = task['chtxt']
96         except:
97             chtxt = ""
98         try:
99             title = task['title']
100         except:
101             title = ""
102         try:
103             btime = task['btime']
104             bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
105         except:
106             btime = ""
107             bt = datetime.datetime.strptime("2009-01-01 00:00:00", "%Y-%m-%d %H:%M:%S")
108         try:
109             etime = task['etime']
110             et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
111         except:
112             etime = ""
113             et = datetime.datetime.strptime("2009-01-01 00:00:00", "%Y-%m-%d %H:%M:%S")
114         try:
115             opt = task['opt']
116         except:
117             opt = ""
118         tnow = datetime.datetime.now()
119         dtt = bt-tnow
120         dt = dtt.days * 24 * 60 * 60 + dtt.seconds
121         if task["type"] == recdblist.REC_RESERVE:#"res,"+chtxt+","+title+","+btime+","+etime+","+opt
122             pid = os.fork()
123             if pid != 0:#親プロセスの場合
124                 ""
125             else:#子プロセスの場合 アップデートを行って終了
126                 type_reserve(task["type"],chtxt,title,bt,et,opt)
127                 sys.exit()
128         elif task["type"] == recdblist.REC_KEYWORD:#"key,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt
129             deltatime = task['deltatime']
130             pid = os.fork()
131             if pid != 0:#親プロセスの場合
132                 ""
133             else:#子プロセスの場合 アップデートを行って終了
134                 type_keyword(task["type"],chtxt,title, bt, et, opt, deltatime)
135                 sys.exit()
136         elif task["type"] == recdblist.REC_KEYWORD_EVERY_SOME_DAYS:#"keyevery,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt+","+deltaday
137             deltatime = task['deltatime']
138             deltaday = task['deltaday']
139             pid = os.fork()
140             if pid != 0:#親プロセスの場合
141                 ""
142             else:#子プロセスの場合 アップデートを行って終了
143                 type_keyword_every_day(task["type"],chtxt, title, bt, et, opt, deltatime, deltaday)
144                 sys.exit()
145         elif task["type"] == recdblist.REC_FINAL_RESERVE:#"rec,"+chtxt+","+title+","+btime+","+etime+","+opt
146             pid = os.fork()
147             if pid != 0:#親プロセスの場合
148                 ""
149             else:#子プロセスの場合 アップデートを行って終了
150                 type_final(task["type"],chtxt, title, bt, et, opt)
151                 sys.exit()
152         elif task["type"] == recdblist.REC_TS_DECODE_QUE:
153             b25num=b25num+1
154             pid = os.fork()
155             if pid != 0:#親プロセスの場合
156                 ""
157             else:#子プロセスの場合 アップデートを行って終了
158                 time.sleep(5*b25num)
159                 type_decode_que(task["type"],chtxt, title, bt, et, opt)
160                 sys.exit()
161         elif task["type"] == recdblist.REC_ENCODE_QUE:
162             encodenum=encodenum+1
163             pid = os.fork()
164             if pid != 0:#親プロセスの場合
165                 ""
166             else:#子プロセスの場合 アップデートを行って終了
167                 time.sleep(5*encodenum)
168                 type_encode_que(task["type"],chtxt, title, bt, et, opt)
169                 sys.exit()
170         elif task["type"] == recdblist.REC_AVI_TO_MKV:
171             if dt < 10 * 60:
172                 pid = os.fork()
173                 if pid > 0:#親プロセスの場合
174                     ""
175                 else:
176                     makeMP4=0
177                     try:
178                         if configreader.getenv("make_mp4")==1:
179                             makeMP4=1
180                     except:
181                         ""
182                     if re.search("m", opt):
183                         makeMP4=0
184                     if re.search("4", opt):
185                         makeMP4=1
186                     recdb.del_reckey(recdblist.REC_AVI_TO_MKV, title, chtxt, btime)
187                     recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt)
188                     if makeMP4==1:
189                         tv2mp4.raw2mp4(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mp4"),opt)
190                     else:
191                         tv2mkv.raw2mkv(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mkv"),opt)
192                     recdb.del_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime)
193                     sys.exit()
194         elif task["type"] == recdblist.REC_AVI_TO_MP4:
195             if dt < 10 * 60:
196                 pid = os.fork()
197                 if pid > 0:#親プロセスの場合
198                     ""
199                 else:
200                     makeMP4=0
201                     try:
202                         if configreader.getenv("make_mp4")==1:
203                             makeMP4=1
204                     except:
205                         ""
206                     if re.search("m", opt):
207                         makeMP4=0
208                     if re.search("4", opt):
209                         makeMP4=1
210                     recdb.del_reckey(recdblist.REC_AVI_TO_MP4, title, chtxt, btime)
211                     recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt)
212                     if makeMP4==1:
213                         tv2mp4.ts2mp4(pin, pout, opt)
214                         tv2mp4.raw2mp4(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mp4"),opt)
215                     else:
216                         tv2mkv.raw2mkv(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mkv"),opt)
217                     recdb.del_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime)
218                     sys.exit()
219         elif task["type"] == recdblist.REC_MKV_TO_MP4:
220             if dt < 10 * 60:
221                 pid = os.fork()
222                 if pid > 0:#親プロセスの場合
223                     ""
224                 else:
225                     recdb.del_reckey(recdblist.REC_MKV_TO_MP4, title, chtxt, btime)
226                     recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt)
227                     tv2mp4.mkv2mp4(os.path.join(recpath,title+".mkv"),os.path.join(recpath,title+".mp4"))
228                     recdb.del_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime)
229                     sys.exit()
230     sys.exit()
231 def search_keyword(key):
232     tnow = datetime.datetime.now()
233     nows =tnow.strftime("%Y-%m-%d %H:%M:%S")
234     for k in key:
235         recdatum = epgdb.searchtime_auto(k,nows, "144")
236         for recdata in recdatum:
237             if recdata[1] != "":
238                 chtxtt = recdata[0]
239                 titlet = recdata[1]
240                 btimet = recdata[2]
241                 etimet = recdata[3]
242                 btt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S")
243                 ett = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S")
244                 btimet = btt.strftime("%Y-%m-%d %H:%M:%S")
245                 etimet = ett.strftime("%Y-%m-%d %H:%M:%S")
246                 if status.getSettings_auto_jbk()==1:
247                     topt=status.getSettings_auto_opt()
248                     try:
249                         maxnum=0
250                         if len(ch['ch'])>2:
251                             maxnum=epgdb.count_schedule_timeline(btimet, etimet)[1]
252                             maxnum=int(configreader.getenv("bscs_max"))-maxnum
253                         else:
254                             maxnum=epgdb.count_schedule_timeline(btimet, etimet)[0]
255                             maxnum=int(configreader.getenv("te_max"))-maxnum
256                         if maxnum>0:
257                             topt=status.getSettings_auto_opt()
258                             recdb.recreserv(titlet,chtxtt, btimet, etimet,topt)
259                     except Exception, inst:
260                         print "error occures in search_keyword_auto_jbk"
261                         print str(type(inst))
262                         print str(inst)
263                 else:
264                     try:
265                         recdb.add_auto_keyword(chtxtt, titlet, btimet, etimet)
266                     except Exception, inst:
267                         print "error occures in search_keyword"
268                         print str(type(inst))
269                         print str(inst)
270 def type_reserve(typetxt,chtxt,title,bt,et,opt):
271     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
272     etime = et.strftime("%Y-%m-%d %H:%M:%S")
273     typetxtnow=typetxt
274     typetxtfinal=""
275     if typetxt==recdblist.REC_RESERVE:
276         typetxtfinal=recdblist.REC_FINAL_RESERVE
277     tnow = datetime.datetime.now()
278     dtt = bt-tnow
279     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
280     if (dt < 58 * 60 and dt > 30 * 60):
281         bctypet = chdb.chtxtsearch(chtxt)['bctype']
282         chdatat = rec10d.rec10db.select_by_bctype_epg_ch(bctypet)
283         dt1 = datetime.datetime.strptime(chdatat[0][5], "%Y-%m-%d %H:%M:%S")-datetime.datetime.now()
284         dt1 = dt1.days * 24 * 60 * 60 + dt1.seconds
285         if dt1 < 60 * 60:
286             recdata = epgdb.searchtime2(title, btime, "5", chtxt)
287             chtxtn = recdata[0]
288             titlen = recdata[1]
289             btimen = recdata[2]
290             etimen = recdata[3]
291             exp = recdata[4]
292             longexp = recdata[5]
293             category=recdata[6]
294             bt = datetime.datetime.strptime(btimen, "%Y-%m-%d %H:%M:%S")
295             et = datetime.datetime.strptime(etimen, "%Y-%m-%d %H:%M:%S")
296             btimen = bt.strftime("%Y-%m-%d %H:%M:%S")
297             etimen = et.strftime("%Y-%m-%d %H:%M:%S")
298             if chtxt != "":
299                 try:
300                     recdb.del_reckey(typetxtnow, title, chtxt, btime)
301                     recdb.rec_reckey(typetxtfinal, titlen, chtxtn, btimen, etimen, opt)
302                     recdb.rec_reclog(titlen, chtxtn, btimen, etimen, opt, exp, longexp, category)
303                     auto_rec.add_key(chtxt, titlen,exp+" "+longexp)
304                     auto_rec.add_key("ALL", titlen,exp+" "+longexp)
305                     recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen)
306                 except Exception, inst:
307                     print "Error happened in Oikake DB"
308                     print str(type(inst))
309                     print str(inst)
310             else:
311                 recdblist.printutf8(u"追いかけ機能エラー:番組データが見付かりません。")
312         else:
313             if rec10d.rec10db.select_by_bctype_epg_ch(bctypet)[0][6] != "0":
314                 rec10d.rec10db.update_status_by_bctype_epg_ch(bctypet, "3")
315         sys.exit()
316     elif (dt <= 30 * 60 and dt > 20 * 60):
317         recdata = epgdb.searchtime2(title, btime, "5", chtxt)
318         chtxtn = recdata[0]
319         titlen = recdata[1]
320         btimen = recdata[2]
321         etimen = recdata[3]
322         exp = recdata[4]
323         longexp = recdata[5]
324         category=recdata[6]
325         bt = datetime.datetime.strptime(btimen, "%Y-%m-%d %H:%M:%S")
326         et = datetime.datetime.strptime(etimen, "%Y-%m-%d %H:%M:%S")
327         btimen = bt.strftime("%Y-%m-%d %H:%M:%S")
328         etimen = et.strftime("%Y-%m-%d %H:%M:%S")
329         if chtxt != "":
330             try:
331                 recdb.del_reckey(typetxtnow, title, chtxt, btime)
332                 recdb.rec_reckey(typetxtfinal, titlen, chtxtn, btimen, etimen, opt)
333                 recdb.rec_reclog(titlen, chtxtn, btimen, etimen, opt, exp, longexp, category)
334                 auto_rec.add_key(chtxt, titlen,exp+" "+longexp)
335                 auto_rec.add_key("ALL", titlen,exp+" "+longexp)
336                 recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen)
337             except Exception, inst:
338                 print "Error happened in Oikake DB"
339                 print type(inst)
340                 print inst
341     elif dt <= 20 * 60:
342         try:
343             recdb.del_reckey(typetxtnow, title, chtxt, btime)
344             recdb.rec_reckey(typetxtfinal, title, chtxt, btime, etime, opt)
345         except Exception, inst:
346             print type(inst)
347             print inst
348 def type_final(typetxt,chtxt,title,bt,et,opt):
349     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
350     etime = et.strftime("%Y-%m-%d %H:%M:%S")
351     typetxtnow=typetxt
352     typetxting=""
353     typetxtdecque=""
354     if typetxt==recdblist.REC_FINAL_RESERVE:
355         typetxting=recdblist.REC_TS_RECORDING
356         typetxtdecque=recdblist.REC_TS_DECODE_QUE
357     tnow = datetime.datetime.now()
358     dtt = bt-tnow
359     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
360     print dt
361     if dt < 6 * 60 and dt > 0:
362         newtitle=title
363         recdb.del_reckey(typetxtnow, title, chtxt, btime)
364         testpath=[os.path.join(recpath,title+".ts.b25")]
365         testpath.append(os.path.join(recpath,title+".ts"))
366         testpath.append(os.path.join(recpath,title+".avi"))
367         testpath.append(os.path.join(recpath,title+".mp4"))
368         testpath.append(os.path.join(recpath,title+".log"))
369         tcheck=0
370         for ti in testpath:
371             if os.path.exists(ti):
372                 tcheck=tcheck+1
373         if re.search("N", opt) or tcheck>0:
374             iff=""
375             try:
376                 iff=u"("+configreader.getenv("iff")+u")_"
377             except:
378                 iff=""
379             newtime=bt
380             newtitle=newtitle+u"_"+iff+newtime.strftime("%Y-%m-%dT%H-%M-%S")
381         recdb.rec_reckey(typetxting, newtitle, chtxt, btime, etime, opt)
382         recdblist.printutf8(u"録画開始 "+newtitle+" "+btime+" "+etime)
383         tv2avi.timetv2b25(recpath + "/" + newtitle + ".avi", chtxt, btime, etime, opt)
384         recdb.del_reckey(typetxting, newtitle, chtxt, btime)
385         if not re.search("R", opt):
386             tnow = datetime.datetime.now()
387             bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
388             et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
389             dt = tnow-bt
390             bt = tnow + datetime.timedelta(seconds=600)
391             et = et + dt + datetime.timedelta(seconds=600)
392             btime = bt.strftime("%Y-%m-%d %H:%M:%S")
393             etime = et.strftime("%Y-%m-%d %H:%M:%S")
394             recdb.rec_reckey(typetxtdecque, newtitle, chtxt, btime, etime, opt)
395         else:
396             try:
397                 shutil.copy(os.path.join(recpath,title+".ts.b25"), os.path.join(movepath,title+".ts.b25"))
398             except:
399                 ""
400             recdb.rec_reckey(recdblist.REC_MOVE_END, newtitle, chtxt, btime, etime, opt)
401         sys.exit()
402 def type_keyword(typetxt,chtxt,title,bt,et,opt,deltatime):
403     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
404     etime = et.strftime("%Y-%m-%d %H:%M:%S")
405     typetxtnow=typetxt
406     typetxtres=""
407     if typetxt==recdblist.REC_KEYWORD:
408         typetxtres=recdblist.REC_RESERVE
409     tnow = datetime.datetime.now()
410     dtt = bt-tnow
411     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
412     print dt
413     if dt < 90 * 60:
414         recdata = epgdb.searchtime2(title, btime, deltatime, chtxt)
415         if recdata[1] != "":
416             chtxtt = recdata[0]
417             titlet = recdata[1]
418             btimet = recdata[2]
419             etimet = recdata[3]
420             exp = recdata[4]
421             longexp = recdata[5]
422             category=recdata[6]
423             bt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S")
424             et = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S")
425             btimet = bt.strftime("%Y-%m-%d %H:%M:%S")
426             etimet = et.strftime("%Y-%m-%d %H:%M:%S")
427             #try:
428             recdb.del_reckey(typetxtnow, title, chtxt, btime)
429             recdb.rec_reckey(typetxtres, titlet, chtxtt, btimet, etimet, opt)
430             recdb.rec_reclog(titlet, chtxtt, btimet, etimet, opt, exp,longexp,category)
431             auto_rec.add_key(chtxt, titlet,exp+" "+longexp)
432             auto_rec.add_key("ALL", titlet,exp+" "+longexp)
433             recdblist.printutf8(u"key "+title+u" : "+titlet+u" "+btimet+u" "+etimet)
434             #except Exception, inst:
435             #    recdblist.printutf8("Error happened in REC_KEYWORD DB")
436             #    recdblist.printutf8(type(inst))
437             #    recdblist.printutf8(inst)
438         else:
439             recdblist.printutf8("nothing match")
440
441 def type_keyword_every_day(type,chtxt,title,bt,et,opt,deltatime,deltaday):
442     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
443     etime = et.strftime("%Y-%m-%d %H:%M:%S")
444     tnow = datetime.datetime.now()
445     dtt = bt-tnow
446     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
447     dd = datetime.timedelta(days=int(deltaday))
448     if dtt.days < 0:
449         recdb.del_reckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime)
450         bt = bt + dd
451         et = et + dd
452         btxt = bt.strftime("%Y-%m-%d %H:%M:%S")
453         etxt = et.strftime("%Y-%m-%d %H:%M:%S")
454         recdb.everyreserv(title, chtxt, btxt, etxt, deltatime, opt, deltaday)
455     elif dt < 120 * 60:
456         recdb.del_reckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime)
457         bt = bt + dd
458         et = et + dd
459         btxt = bt.strftime("%Y-%m-%d %H:%M:%S")
460         etxt = et.strftime("%Y-%m-%d %H:%M:%S")
461         recdb.everyreserv(title, chtxt, btxt, etxt, deltatime, opt, deltaday)
462
463         recdata = epgdb.searchtime2(title, btime, deltatime, chtxt)
464         if recdata[1] != "":
465             chtxtt = recdata[0]
466             titlet = recdata[1]
467             btimet = recdata[2]
468             etimet = recdata[3]
469             exp = recdata[4]
470             longexp = recdata[5]
471             category=recdata[6]
472             bt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S")
473             et = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S")
474             btimet = bt.strftime("%Y-%m-%d %H:%M:%S")
475             etimet = et.strftime("%Y-%m-%d %H:%M:%S")
476             #try:
477             recdb.keyreserv(titlet, chtxtt, btimet, etimet, deltatime, opt)
478         else:
479             recdb.keyreserv(title, chtxt, btime, etime, deltatime, opt)
480 def type_decode_que(typetxt,chtxt,title,bt,et,opt):
481     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
482     etime = et.strftime("%Y-%m-%d %H:%M:%S")
483     tnow = datetime.datetime.now()
484     dtt = bt-tnow
485     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
486     typetxtnow=typetxt
487     typetxting=""
488     typetxtmiss=""
489     typetxtencque=""
490     if typetxt== recdblist.REC_TS_DECODE_QUE:
491         typetxting=recdblist.REC_TS_DECODING
492         typetxtmiss=recdblist.REC_MISS_DECODE
493         typetxtencque=recdblist.REC_ENCODE_QUE
494     tnow = datetime.datetime.now()
495     dtt = bt-tnow
496     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
497     if dt < 10 * 60:
498         if status.getB25Decoding() < 2:
499             pin = recpath + "/" + title
500             recdb.del_reckey(typetxtnow, title, chtxt, btime)
501             recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt)
502             tv2avi.b252ts(pin, chtxt, btime, etime, opt)
503             recdb.del_reckey(typetxting, title, chtxt, btime)
504             if not os.access(recpath + "/" + title + ".ts", os.F_OK):
505                 recdb.del_reckey(typetxting, title, chtxt, btime)
506                 recdb.rec_reckey(typetxtmiss, title, chtxt, btime, etime, opt)
507             else:
508                 ch=checker.checkB25Decode(recpath + "/" + title + ".ts.b25", recpath + "/" + title + ".ts")
509                 print ch
510                 if ch == 1:
511                     os.remove(recpath + "/" + title + ".ts.b25")
512             bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
513             et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
514             dt = et-bt
515             if not re.search("D", opt):
516                 tnow = datetime.datetime.now()
517                 bt = tnow + datetime.timedelta(seconds=600)
518                 et = bt + dt
519                 btime = bt.strftime("%Y-%m-%d %H:%M:%S")
520                 etime = et.strftime("%Y-%m-%d %H:%M:%S")
521                 recdb.rec_reckey(typetxtencque, title, chtxt, btime, etime, opt)
522             else:
523                 try:
524                     shutil.copy(os.path.join(recpath,title+".ts"), os.path.join(movepath,title+".ts"))
525                 except Exception, inst:
526                     errtxt="Error happened in type_decode_que in timerec.\n"
527                     errtxt=errtxt+"move ts error.\n"
528                     errtxt=errtxt+str(type(inst))+"\n"
529                     errtxt=errtxt+str(inst)
530                     recdblist.addlog(os.path.join(recpath,title+".ts"), errtxt, "timerec-move(Decode) error")
531                 recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt)
532         else:
533             recdb.del_reckey(typetxtnow, title, chtxt, btime)
534             bt = bt + datetime.timedelta(seconds=600)
535             et = et + datetime.timedelta(seconds=600)
536             btime = bt.strftime("%Y-%m-%d %H:%M:%S")
537             etime = et.strftime("%Y-%m-%d %H:%M:%S")
538             recdb.rec_reckey(typetxtnow, title, chtxt, btime, etime, opt)
539     sys.exit()
540
541 def type_encode_que(typetxt,chtxt,title,bt,et,opt):
542     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
543     etime = et.strftime("%Y-%m-%d %H:%M:%S")
544     tnow = datetime.datetime.now()
545     dtt = bt-tnow
546     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
547     typetxtnow=typetxt
548     typetxting=""
549     typetxtfin=""
550     if typetxt==recdblist.REC_ENCODE_QUE:
551         typetxting=recdblist.REC_ENCODE_LOCAL
552         typetxtfin=recdblist.REC_FIN_LOCAL
553     if dt < 10 * 60:
554         if status.getEncoding() < int(configreader.getenv("enc_max")):
555             recdb.del_reckey(typetxtnow, title, chtxt, btime)
556             recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt)
557             recdblist.printutf8(opt)
558             pin = recpath + "/" + title + ".ts"
559             if re.search("d", opt):
560                 pin = recpath + "/" + title + ".m2v"
561                 if not os.path.exists(pin) or os.path.getsize(pin)<100*1000:
562                     paac2 = recpath + "/" + title + "_2.aac"
563                     pmp32 = recpath + "/" + title + "_2.mp3"
564                     if not os.path.exists(paac2) and not os.path.exists(pmp32):
565                         tv2avi.dualaudio2sep(os.path.join(recpath, title+".ts"),"167")
566                 time.sleep(3)
567             elif re.search("5", opt):
568                 pin = recpath + "/" + title + ".m2v"
569                 if not os.path.exists(pin) or os.path.getsize(pin)<100*1000:
570                     paac2 = recpath + "/" + title + "_2.aac"
571                     pmp32 = recpath + "/" + title + "_2.mp3"
572                     if not os.path.exists(paac2) and not os.path.exists(pmp32):
573                         tv2avi.pentaaudio2sep(os.path.join(recpath, title+".ts"))
574                 time.sleep(3)
575             makeMP4=0
576             try:
577                 if configreader.getenv("make_mp4")==1:
578                     makeMP4=1
579             except:
580                 ""
581             if re.search("m", opt):
582                 makeMP4=0
583             if re.search("4", opt):
584                 makeMP4=1
585             recdblist.printutf8(pin)
586             if makeMP4==1:
587                 pout = recpath + "/" + title + ".mp4"
588                 tv2mp4.ts2mp4(pin, pout, opt)
589             else:
590                 pout = recpath + "/" + title + ".mkv"
591                 tv2mkv.ts2mkv(pin, pout, opt)
592             recdb.del_reckey(typetxting, title, chtxt, btime)
593             time.sleep(10)
594             if re.search("E", opt):
595                 try:
596                     if os.path.exists(os.path.join(recpath,title+".mp4")):
597                         shutil.copy(os.path.join(recpath,title+".mp4"), os.path.join(movepath,title+".mp4"))
598                     elif os.path.exists(os.path.join(recpath,title+".mkv")):
599                         shutil.copy(os.path.join(recpath,title+".mkv"), os.path.join(movepath,title+".mkv"))
600                 except Exception, inst:
601                     errtxt="Error happened in type_encode_que in timerec.\n"
602                     errtxt=errtxt+"move mkv/mp4 error.\n"
603                     errtxt=errtxt+str(type(inst))+"\n"
604                     errtxt=errtxt+str(inst)
605                     recdblist.addlog(os.path.join(recpath,title+".ts"), errtxt, "timerec-move(Encode) error")
606                 recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt)
607             recdb.rec_reckey(typetxtfin, title, chtxt, btime, etime, opt)
608             sys.exit()
609         else:
610             recdb.del_reckey(typetxtnow, title, chtxt, btime)
611             bt = bt + datetime.timedelta(seconds=600)
612             et = et + datetime.timedelta(seconds=600)
613             btime = bt.strftime("%Y-%m-%d %H:%M:%S")
614             etime = et.strftime("%Y-%m-%d %H:%M:%S")
615             recdb.rec_reckey(typetxtnow, title, chtxt, btime, etime, opt)
616             sys.exit()