OSDN Git Service

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