OSDN Git Service

42ae8279a170e77aebacff3ec1c457ccf19d4c03
[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             time.sleep(1)
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         recdb.del_reckey(typetxtnow, title, chtxt, btime)
346         recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt)
347         recdblist.printutf8(u"録画開始 "+title+" "+btime+" "+etime)
348         ttitle=title
349         #recdblist.printutf8(title)
350         testpath=[os.path.join(recpath,title+".ts.b25")]
351         testpath.append(os.path.join(recpath,title+".ts"))
352         testpath.append(os.path.join(recpath,title+".avi"))
353         testpath.append(os.path.join(recpath,title+".mkv"))
354         testpath.append(os.path.join(recpath,title+".log"))
355         tcheck=0
356         for ti in testpath:
357             if os.path.exists(ti):
358                 tcheck=tcheck+1
359         if tcheck>0:
360             ttitle=title+"_"+datetime.datetime.now().strftime("%Y%m%d%H%M")
361         tv2avi.timetv2b25(recpath + "/" + ttitle + ".avi", chtxt, btime, etime, opt)
362         recdb.del_reckey(typetxting, title, chtxt, btime)
363         if not re.search("R", opt):
364             tnow = datetime.datetime.now()
365             bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
366             et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
367             dt = tnow-bt
368             bt = tnow + datetime.timedelta(seconds=600)
369             et = et + dt + datetime.timedelta(seconds=600)
370             btime = bt.strftime("%Y-%m-%d %H:%M:%S")
371             etime = et.strftime("%Y-%m-%d %H:%M:%S")
372             recdb.rec_reckey(typetxtdecque, ttitle, chtxt, btime, etime, opt)
373         else:
374             shutil.copy(os.path.join(recpath,title+".ts.b25"), os.path.join(movepath,title+".ts.b25"))
375             recdb.rec_reckey(recdblist.REC_MOVE_END, ttitle, chtxt, btime, etime, opt)
376         sys.exit()
377 def type_keyword(typetxt,chtxt,title,bt,et,opt,deltatime):
378     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
379     etime = et.strftime("%Y-%m-%d %H:%M:%S")
380     typetxtnow=typetxt
381     typetxtres=""
382     if typetxt==recdblist.REC_KEYWORD:
383         typetxtres=recdblist.REC_RESERVE
384     tnow = datetime.datetime.now()
385     dtt = bt-tnow
386     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
387     print dt
388     if dt < 90 * 60:
389         recdata = epgdb.searchtime2(title, btime, deltatime, chtxt)
390         if recdata[1] != "":
391             chtxtt = recdata[0]
392             titlet = recdata[1]
393             btimet = recdata[2]
394             etimet = recdata[3]
395             exp = recdata[4]
396             longexp = recdata[5]
397             category=recdata[6]
398             bt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S")
399             et = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S")
400             btimet = bt.strftime("%Y-%m-%d %H:%M:%S")
401             etimet = et.strftime("%Y-%m-%d %H:%M:%S")
402             #try:
403             recdb.del_reckey(typetxtnow, title, chtxt, btime)
404             recdb.rec_reckey(typetxtres, titlet, chtxtt, btimet, etimet, opt)
405             recdb.rec_reclog(titlet, chtxtt, btimet, etimet, opt, exp,longexp,category)
406             auto_rec.add_key(chtxt, titlet,exp+" "+longexp)
407             auto_rec.add_key("ALL", titlet,exp+" "+longexp)
408             recdblist.printutf8(u"key "+title+u" : "+titlet+u" "+btimet+u" "+etimet)
409             #except Exception, inst:
410             #    recdblist.printutf8("Error happened in REC_KEYWORD DB")
411             #    recdblist.printutf8(type(inst))
412             #    recdblist.printutf8(inst)
413         else:
414             recdblist.printutf8("nothing match")
415
416 def type_keyword_every_day(type,chtxt,title,bt,et,opt,deltatime,deltaday):
417     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
418     etime = et.strftime("%Y-%m-%d %H:%M:%S")
419     tnow = datetime.datetime.now()
420     dtt = bt-tnow
421     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
422     dd = datetime.timedelta(days=int(deltaday))
423     if dtt.days < 0:
424         recdb.del_reckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime)
425         bt = bt + dd
426         et = et + dd
427         btxt = bt.strftime("%Y-%m-%d %H:%M:%S")
428         etxt = et.strftime("%Y-%m-%d %H:%M:%S")
429         recdb.everyreserv(title, chtxt, btxt, etxt, deltatime, opt, deltaday)
430     elif dt < 120 * 60:
431         recdb.keyreserv(title, chtxt, btime, etime, deltatime, opt)
432         recdb.del_reckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime)
433         bt = bt + dd
434         et = et + dd
435         btxt = bt.strftime("%Y-%m-%d %H:%M:%S")
436         etxt = et.strftime("%Y-%m-%d %H:%M:%S")
437         recdb.everyreserv(title, chtxt, btxt, etxt, deltatime, opt, deltaday)
438
439
440 def type_decode_que(typetxt,chtxt,title,bt,et,opt):
441     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
442     etime = et.strftime("%Y-%m-%d %H:%M:%S")
443     tnow = datetime.datetime.now()
444     dtt = bt-tnow
445     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
446     typetxtnow=typetxt
447     typetxting=""
448     typetxtmiss=""
449     typetxtencque=""
450     if typetxt== recdblist.REC_TS_DECODE_QUE:
451         typetxting=recdblist.REC_TS_DECODING
452         typetxtmiss=recdblist.REC_MISS_DECODE
453         typetxtencque=recdblist.REC_ENCODE_QUE
454     tnow = datetime.datetime.now()
455     dtt = bt-tnow
456     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
457     if dt < 10 * 60:
458         if status.getB25Decoding() < 2:
459             pin = recpath + "/" + title
460             recdb.del_reckey(typetxtnow, title, chtxt, btime)
461             recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt)
462             tv2avi.b252ts(pin, chtxt, btime, etime, opt)
463             recdb.del_reckey(typetxting, title, chtxt, btime)
464             if not os.access(recpath + "/" + title + ".ts", os.F_OK):
465                 recdb.del_reckey(typetxting, title, chtxt, btime)
466                 recdb.rec_reckey(typetxtmiss, title, chtxt, btime, etime, opt)
467             bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
468             et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
469             dt = et-bt
470             if not re.search("D", opt):
471                 tnow = datetime.datetime.now()
472                 bt = tnow + datetime.timedelta(seconds=600)
473                 et = bt + dt
474                 btime = bt.strftime("%Y-%m-%d %H:%M:%S")
475                 etime = et.strftime("%Y-%m-%d %H:%M:%S")
476                 recdb.rec_reckey(typetxtencque, title, chtxt, btime, etime, opt)
477             else:
478                 if opt.rfind("d")>=0:
479                     shutil.copy(os.path.join(recpath,title+".sa.avi"),os.path.join(movepath,title+".sa.avi"))
480                 elif opt.rfind("5")>=0:
481                     shutil.copy(os.path.join(recpath,title+".sa.avi"),os.path.join(movepath,title+".sa.avi"))
482                 else:
483                     shutil.copy(os.path.join(recpath,title+".ts"), os.path.join(movepath,title+".ts"))
484                 recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt)
485             #recdblist.printutf8(checker.checkB25Decode(recpath + "/" + title + ".ts.b25", recpath + "/" + title + ".ts"))
486             if checker.checkB25Decode(recpath + "/" + title + ".ts.b25", recpath + "/" + title + ".ts") == 1:
487                 os.remove(recpath + "/" + title + ".ts.b25")
488         else:
489             recdb.del_reckey(typetxtnow, title, chtxt, btime)
490             bt = bt + datetime.timedelta(seconds=600)
491             et = et + datetime.timedelta(seconds=600)
492             btime = bt.strftime("%Y-%m-%d %H:%M:%S")
493             etime = et.strftime("%Y-%m-%d %H:%M:%S")
494             recdb.rec_reckey(typetxtnow, title, chtxt, btime, etime, opt)
495     sys.exit()
496
497 def type_encode_que(typetxt,chtxt,title,bt,et,opt):
498     btime = bt.strftime("%Y-%m-%d %H:%M:%S")
499     etime = et.strftime("%Y-%m-%d %H:%M:%S")
500     tnow = datetime.datetime.now()
501     dtt = bt-tnow
502     dt = dtt.days * 24 * 60 * 60 + dtt.seconds
503     typetxtnow=typetxt
504     typetxting=""
505     typetxtfin=""
506     if typetxt==recdblist.REC_ENCODE_QUE:
507         typetxting=recdblist.REC_ENCODE_LOCAL
508         typetxtfin=recdblist.REC_FIN_LOCAL
509     if dt < 10 * 60:
510         if status.getEncoding() < int(configreader.getenv("enc_max")):
511             recdblist.printutf8(opt)
512             pin = recpath + "/" + title + ".ts"
513             if re.search("d", opt):
514                 pin = recpath + "/" + title + ".sa.avi"
515             if re.search("5", opt):
516                 pin = recpath + "/" + title + ".sa.avi"
517             #pout = recpath + "/" + title + ".avi"
518             pout = recpath + "/" + title + ".mp4"
519             recdblist.printutf8(pin)
520             #recdblist.printutf8(pin+":"+pout+":"+opt)
521             recdb.del_reckey(typetxtnow, title, chtxt, btime)
522             recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt)
523             #tv2mkv.ts2mkv(pin, pout, opt)
524             tv2mp4.ts2mp4(pin, pout, opt)
525             #tv2avi.ts2avi(pin, pout, opt)
526             recdb.del_reckey(typetxting, title, chtxt, btime)
527             if re.search("R", opt):
528                 shutil.copy(os.path.join(recpath,title+".mp4"), os.path.join(movepath,title+".mp4"))
529                 recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt)
530             recdb.rec_reckey(typetxtfin, title, chtxt, btime, etime, opt)
531             sys.exit()
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()