OSDN Git Service

fix small bugs.
[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("2")
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                     recdb.del_reckey(recdblist.REC_AVI_TO_MKV, title, chtxt, btime)
177                     recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt)
178                     #tv2mp4.avi2mp4(os.path.join(recpath,title+".avi"),os.path.join(recpath,title+".mkv"),opt)
179                     tv2mkv.avi2mkv(os.path.join(recpath,title+".avi"),os.path.join(recpath,title+".mkv"),opt)
180                     recdb.del_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime)
181                     sys.exit()
182         elif task["type"] == recdblist.REC_AVI_TO_MP4:
183             if dt < 10 * 60:
184                 pid = os.fork()
185                 if pid > 0:#親プロセスの場合
186                     ""
187                 else:
188                     recdb.del_reckey(recdblist.REC_AVI_TO_MP4, title, chtxt, btime)
189                     recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt)
190                     tv2mp4.avi2mp4(os.path.join(recpath,title+".avi"),os.path.join(recpath,title+".mp4"),opt)
191                     recdb.del_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime)
192                     sys.exit()
193         elif task["type"] == recdblist.REC_MKV_TO_MP4:
194             if dt < 10 * 60:
195                 pid = os.fork()
196                 if pid > 0:#親プロセスの場合
197                     ""
198                 else:
199                     recdb.del_reckey(recdblist.REC_MKV_TO_MP4, title, chtxt, btime)
200                     recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt)
201                     tv2mp4.mkv2mp4(os.path.join(recpath,title+".mkv"),os.path.join(recpath,title+".mp4"))
202                     recdb.del_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime)
203                     sys.exit()
204     sys.exit()
205 def search_keyword(key):
206     tnow = datetime.datetime.now()
207     nows =tnow.strftime("%Y-%m-%d %H:%M:%S")
208     for k in key:
209         recdatum = epgdb.searchtime_auto(k,nows, "144")
210         for recdata in recdatum:
211             if recdata[1] != "":
212                 chtxtt = recdata[0]
213                 titlet = recdata[1]
214                 btimet = recdata[2]
215                 etimet = recdata[3]
216                 btt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S")
217                 ett = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S")
218                 btimet = btt.strftime("%Y-%m-%d %H:%M:%S")
219                 etimet = ett.strftime("%Y-%m-%d %H:%M:%S")
220                 if status.getSettings_auto_jbk()==1:
221                     topt=status.getSettings_auto_opt()
222                     try:
223                         maxnum=0
224                         if len(ch['ch'])>2:
225                             maxnum=epgdb.count_schedule_timeline(btimet, etimet)[1]
226                             maxnum=int(configreader.getenv("bscs_max"))-maxnum
227                         else:
228                             maxnum=epgdb.count_schedule_timeline(btimet, etimet)[0]
229                             maxnum=int(configreader.getenv("te_max"))-maxnum
230                         if maxnum>0:
231                             topt=status.getSettings_auto_opt()
232                             recdb.recreserv(titlet,chtxtt, btimet, etimet,topt)
233                     except Exception, inst:
234                         print "error occures in search_keyword_auto_jbk"
235                         print type(inst)
236                         print inst
237                 else:
238                     try:
239                         recdb.add_auto_keyword(chtxtt, titlet, btimet, etimet)
240                     except Exception, inst:
241                         print "error occures in search_keyword"
242                         print type(inst)
243                         print inst
244 def type_reserve(typetxt,chtxt,title,bt,et,opt):
245     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
246     etime = et.strftime("%Y-%m-%d %H:%M:%S")
247     typetxtnow=typetxt
248     typetxtfinal=""
249     if typetxt==recdblist.REC_RESERVE:
250         typetxtfinal=recdblist.REC_FINAL_RESERVE
251     tnow = datetime.datetime.now()
252     dtt = bt-tnow
253     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
254     if (dt < 58 * 60 and dt > 30 * 60):
255         bctypet = chdb.chtxtsearch(chtxt)['bctype']
256         chdatat = rec10d.rec10db.select_by_bctype_epg_ch(bctypet)
257         dt1 = datetime.datetime.strptime(chdatat[0][5], "%Y-%m-%d %H:%M:%S")-datetime.datetime.now()
258         dt1 = dt1.days * 24 * 60 * 60 + dt1.seconds
259         if dt1 < 60 * 60:
260             recdata = epgdb.searchtime2(title, btime, "5", chtxt)
261             chtxtn = recdata[0]
262             titlen = recdata[1]
263             btimen = recdata[2]
264             etimen = recdata[3]
265             exp = recdata[4]
266             longexp = recdata[5]
267             category=recdata[6]
268             bt = datetime.datetime.strptime(btimen, "%Y-%m-%d %H:%M:%S")
269             et = datetime.datetime.strptime(etimen, "%Y-%m-%d %H:%M:%S")
270             btimen = bt.strftime("%Y-%m-%d %H:%M:%S")
271             etimen = et.strftime("%Y-%m-%d %H:%M:%S")
272             if chtxt != "":
273                 try:
274                     recdb.del_reckey(typetxtnow, title, chtxt, btime)
275                     recdb.rec_reckey(typetxtfinal, titlen, chtxtn, btimen, etimen, opt)
276                     recdb.rec_reclog(titlen, chtxtn, btimen, etimen, opt, exp, longexp, category)
277                     auto_rec.add_key(chtxt, titlen,exp+" "+longexp)
278                     auto_rec.add_key("ALL", titlen,exp+" "+longexp)
279                     recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen)
280                 except Exception, inst:
281                     print "Error happended in Oikake DB"
282                     print type(inst)
283                     print inst
284             else:
285                 recdblist.printutf8(u"追いかけ機能エラー:番組データが見付かりません。")
286         else:
287             if rec10d.rec10db.select_by_bctype_epg_ch(bctypet)[0][6] != "0":
288                 rec10d.rec10db.update_status_by_bctype_epg_ch(bctypet, "3")
289         sys.exit()
290     elif (dt <= 30 * 60 and dt > 20 * 60):
291         recdata = epgdb.searchtime2(title, btime, "5", chtxt)
292         chtxtn = recdata[0]
293         titlen = recdata[1]
294         btimen = recdata[2]
295         etimen = recdata[3]
296         exp = recdata[4]
297         longexp = recdata[5]
298         category=recdata[6]
299         bt = datetime.datetime.strptime(btimen, "%Y-%m-%d %H:%M:%S")
300         et = datetime.datetime.strptime(etimen, "%Y-%m-%d %H:%M:%S")
301         btimen = bt.strftime("%Y-%m-%d %H:%M:%S")
302         etimen = et.strftime("%Y-%m-%d %H:%M:%S")
303         if chtxt != "":
304             try:
305                 recdb.del_reckey(typetxtnow, title, chtxt, btime)
306                 recdb.rec_reckey(typetxtfinal, titlen, chtxtn, btimen, etimen, opt)
307                 recdb.rec_reclog(titlen, chtxtn, btimen, etimen, opt, exp, longexp, category)
308                 auto_rec.add_key(chtxt, titlen,exp+" "+longexp)
309                 auto_rec.add_key("ALL", titlen,exp+" "+longexp)
310                 recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen)
311             except Exception, inst:
312                 print "Error happended in Oikake DB"
313                 print type(inst)
314                 print inst
315     elif dt <= 20 * 60:
316         try:
317             recdb.del_reckey(typetxtnow, title, chtxt, btime)
318             recdb.rec_reckey(typetxtfinal, title, chtxt, btime, etime, opt)
319         except Exception, inst:
320             print type(inst)
321             print inst
322 def type_final(typetxt,chtxt,title,bt,et,opt):
323     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
324     etime = et.strftime("%Y-%m-%d %H:%M:%S")
325     typetxtnow=typetxt
326     typetxting=""
327     typetxtdecque=""
328     if typetxt==recdblist.REC_FINAL_RESERVE:
329         typetxting=recdblist.REC_TS_RECORDING
330         typetxtdecque=recdblist.REC_TS_DECODE_QUE
331     tnow = datetime.datetime.now()
332     dtt = bt-tnow
333     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
334     print dt
335     if dt < 6 * 60 and dt > 0:
336         newtitle=title
337         recdb.del_reckey(typetxtnow, title, chtxt, btime)
338         testpath=[os.path.join(recpath,title+".ts.b25")]
339         testpath.append(os.path.join(recpath,title+".ts"))
340         testpath.append(os.path.join(recpath,title+".avi"))
341         testpath.append(os.path.join(recpath,title+".mp4"))
342         testpath.append(os.path.join(recpath,title+".log"))
343         tcheck=0
344         for ti in testpath:
345             if os.path.exists(ti):
346                 tcheck=tcheck+1
347         if re.search("N", opt) or tcheck>0:
348             newtitle=newtitle+u"_"+bt.strftime("%Y%m%d%H%M")
349         recdb.rec_reckey(typetxting, newtitle, chtxt, btime, etime, opt)
350         recdblist.printutf8(u"録画開始 "+newtitle+" "+btime+" "+etime)
351         tv2avi.timetv2b25(recpath + "/" + newtitle + ".avi", chtxt, btime, etime, opt)
352         recdb.del_reckey(typetxting, newtitle, chtxt, btime)
353         if not re.search("R", opt):
354             tnow = datetime.datetime.now()
355             bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
356             et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
357             dt = tnow-bt
358             bt = tnow + datetime.timedelta(seconds=600)
359             et = et + dt + datetime.timedelta(seconds=600)
360             btime = bt.strftime("%Y-%m-%d %H:%M:%S")
361             etime = et.strftime("%Y-%m-%d %H:%M:%S")
362             recdb.rec_reckey(typetxtdecque, newtitle, chtxt, btime, etime, opt)
363         else:
364             try:
365                 shutil.copy(os.path.join(recpath,title+".ts.b25"), os.path.join(movepath,title+".ts.b25"))
366             except:
367                 ""
368             recdb.rec_reckey(recdblist.REC_MOVE_END, newtitle, chtxt, btime, etime, opt)
369         sys.exit()
370 def type_keyword(typetxt,chtxt,title,bt,et,opt,deltatime):
371     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
372     etime = et.strftime("%Y-%m-%d %H:%M:%S")
373     typetxtnow=typetxt
374     typetxtres=""
375     if typetxt==recdblist.REC_KEYWORD:
376         typetxtres=recdblist.REC_RESERVE
377     tnow = datetime.datetime.now()
378     dtt = bt-tnow
379     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
380     print dt
381     if dt < 90 * 60:
382         recdata = epgdb.searchtime2(title, btime, deltatime, chtxt)
383         if recdata[1] != "":
384             chtxtt = recdata[0]
385             titlet = recdata[1]
386             btimet = recdata[2]
387             etimet = recdata[3]
388             exp = recdata[4]
389             longexp = recdata[5]
390             category=recdata[6]
391             bt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S")
392             et = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S")
393             btimet = bt.strftime("%Y-%m-%d %H:%M:%S")
394             etimet = et.strftime("%Y-%m-%d %H:%M:%S")
395             #try:
396             recdb.del_reckey(typetxtnow, title, chtxt, btime)
397             recdb.rec_reckey(typetxtres, titlet, chtxtt, btimet, etimet, opt)
398             recdb.rec_reclog(titlet, chtxtt, btimet, etimet, opt, exp,longexp,category)
399             auto_rec.add_key(chtxt, titlet,exp+" "+longexp)
400             auto_rec.add_key("ALL", titlet,exp+" "+longexp)
401             recdblist.printutf8(u"key "+title+u" : "+titlet+u" "+btimet+u" "+etimet)
402             #except Exception, inst:
403             #    recdblist.printutf8("Error happened in REC_KEYWORD DB")
404             #    recdblist.printutf8(type(inst))
405             #    recdblist.printutf8(inst)
406         else:
407             recdblist.printutf8("nothing match")
408
409 def type_keyword_every_day(type,chtxt,title,bt,et,opt,deltatime,deltaday):
410     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
411     etime = et.strftime("%Y-%m-%d %H:%M:%S")
412     tnow = datetime.datetime.now()
413     dtt = bt-tnow
414     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
415     dd = datetime.timedelta(days=int(deltaday))
416     if dtt.days < 0:
417         recdb.del_reckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime)
418         bt = bt + dd
419         et = et + dd
420         btxt = bt.strftime("%Y-%m-%d %H:%M:%S")
421         etxt = et.strftime("%Y-%m-%d %H:%M:%S")
422         recdb.everyreserv(title, chtxt, btxt, etxt, deltatime, opt, deltaday)
423     elif dt < 120 * 60:
424         recdb.keyreserv(title, chtxt, btime, etime, deltatime, opt)
425         recdb.del_reckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime)
426         bt = bt + dd
427         et = et + dd
428         btxt = bt.strftime("%Y-%m-%d %H:%M:%S")
429         etxt = et.strftime("%Y-%m-%d %H:%M:%S")
430         recdb.everyreserv(title, chtxt, btxt, etxt, deltatime, opt, deltaday)
431
432
433 def type_decode_que(typetxt,chtxt,title,bt,et,opt):
434     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
435     etime = et.strftime("%Y-%m-%d %H:%M:%S")
436     tnow = datetime.datetime.now()
437     dtt = bt-tnow
438     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
439     typetxtnow=typetxt
440     typetxting=""
441     typetxtmiss=""
442     typetxtencque=""
443     if typetxt== recdblist.REC_TS_DECODE_QUE:
444         typetxting=recdblist.REC_TS_DECODING
445         typetxtmiss=recdblist.REC_MISS_DECODE
446         typetxtencque=recdblist.REC_ENCODE_QUE
447     tnow = datetime.datetime.now()
448     dtt = bt-tnow
449     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
450     if dt < 10 * 60:
451         if status.getB25Decoding() < 2:
452             pin = recpath + "/" + title
453             recdb.del_reckey(typetxtnow, title, chtxt, btime)
454             recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt)
455             tv2avi.b252ts(pin, chtxt, btime, etime, opt)
456             recdb.del_reckey(typetxting, title, chtxt, btime)
457             if not os.access(recpath + "/" + title + ".ts", os.F_OK):
458                 recdb.del_reckey(typetxting, title, chtxt, btime)
459                 recdb.rec_reckey(typetxtmiss, title, chtxt, btime, etime, opt)
460             bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
461             et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
462             dt = et-bt
463             if not re.search("D", opt):
464                 tnow = datetime.datetime.now()
465                 bt = tnow + datetime.timedelta(seconds=600)
466                 et = bt + dt
467                 btime = bt.strftime("%Y-%m-%d %H:%M:%S")
468                 etime = et.strftime("%Y-%m-%d %H:%M:%S")
469                 recdb.rec_reckey(typetxtencque, title, chtxt, btime, etime, opt)
470             else:
471                 try:
472                     shutil.copy(os.path.join(recpath,title+".ts"), os.path.join(movepath,title+".ts"))
473                 except:
474                     ""
475                 recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt)
476             if checker.checkB25Decode(recpath + "/" + title + ".ts.b25", recpath + "/" + title + ".ts") == 1:
477                 os.remove(recpath + "/" + title + ".ts.b25")
478         else:
479             recdb.del_reckey(typetxtnow, title, chtxt, btime)
480             bt = bt + datetime.timedelta(seconds=600)
481             et = et + datetime.timedelta(seconds=600)
482             btime = bt.strftime("%Y-%m-%d %H:%M:%S")
483             etime = et.strftime("%Y-%m-%d %H:%M:%S")
484             recdb.rec_reckey(typetxtnow, title, chtxt, btime, etime, opt)
485     sys.exit()
486
487 def type_encode_que(typetxt,chtxt,title,bt,et,opt):
488     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
489     etime = et.strftime("%Y-%m-%d %H:%M:%S")
490     tnow = datetime.datetime.now()
491     dtt = bt-tnow
492     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
493     typetxtnow=typetxt
494     typetxting=""
495     typetxtfin=""
496     if typetxt==recdblist.REC_ENCODE_QUE:
497         typetxting=recdblist.REC_ENCODE_LOCAL
498         typetxtfin=recdblist.REC_FIN_LOCAL
499     if dt < 10 * 60:
500         if status.getEncoding() < int(configreader.getenv("enc_max")):
501             recdblist.printutf8(opt)
502             pin = recpath + "/" + title + ".ts"
503             if re.search("d", opt):
504                 pin = recpath + "/" + title + ".m2v"
505                 if not os.path.exists(pin):
506                     tv2avi.dualaudio2sep(os.path.join(recpath, title+".ts"),"167")
507                 time.sleep(3)
508             if re.search("5", opt):
509                 pin = recpath + "/" + title + ".sa.avi"
510                 if not os.path.exists(pin):
511                     tv2avi.pentaaudiots2avi(os.path.join(recpath, title+".ts"), pin)
512                 time.sleep(3)
513             #pout = recpath + "/" + title + ".avi"
514             pout = recpath + "/" + title + ".mkv"
515             recdblist.printutf8(pin)
516             #recdblist.printutf8(pin+":"+pout+":"+opt)
517             recdb.del_reckey(typetxtnow, title, chtxt, btime)
518             recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt)
519             tv2mkv.ts2mkv(pin, pout, opt)
520             #tv2mp4.ts2mp4(pin, pout, opt)
521             #tv2avi.ts2avi(pin, pout, opt)
522             recdb.del_reckey(typetxting, title, chtxt, btime)
523             if re.search("E", opt):
524                 try:
525                     shutil.copy(os.path.join(recpath,title+".mp4"), os.path.join(movepath,title+".mp4"))
526                 except:
527                     ""
528                 recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt)
529             recdb.rec_reckey(typetxtfin, title, chtxt, btime, etime, opt)
530             sys.exit()
531         else:
532             recdb.del_reckey(typetxtnow, title, chtxt, btime)
533             bt = bt + datetime.timedelta(seconds=600)
534             et = et + datetime.timedelta(seconds=600)
535             btime = bt.strftime("%Y-%m-%d %H:%M:%S")
536             etime = et.strftime("%Y-%m-%d %H:%M:%S")
537             recdb.rec_reckey(typetxtnow, title, chtxt, btime, etime, opt)
538             sys.exit()