OSDN Git Service

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