OSDN Git Service

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