X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=rec10%2Ftrunk%2Fsrc%2Ftimerec.py;h=1bb2d559e906ab064e85d68bd1040f2cb69c6498;hb=7e28f9a40b5c06d9d9feb7633af380bde72559d3;hp=94b08085a576ac00c401ef99e0929eed51399ab3;hpb=1d39978d1583a2d4cca2cbe6eb36afb026b3f156;p=rec10%2Frec10-git.git diff --git a/rec10/trunk/src/timerec.py b/rec10/trunk/src/timerec.py index 94b0808..1bb2d55 100644 --- a/rec10/trunk/src/timerec.py +++ b/rec10/trunk/src/timerec.py @@ -2,336 +2,509 @@ # coding: UTF-8 # Rec10 TS Recording Tools # Copyright (C) 2009 Yukikaze +import datetime +import os +import os.path +import re import sys import time -import os -import datetime -import epgdb -import configreader +import shutil + +import auto_rec +import auto_process +import chdb import checker -import tv2avi +import configreader +import epgdb +import rec10d import recdb -import chdb import status -import re -import rec10d -recpath=configreader.getpath('recpath') -path=str(os.path.dirname(os.path.abspath(__file__)))+"/" +import tv2avi +import tv2mkv +import tv2mp4 +import install +import recdblist +recpath = configreader.getpath('recpath') +movepath = configreader.getpath('move_destpath') +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" def task(): """ 数分毎に実行されるタスク処理 予定によって子プロセスを生成し処理する。 """ - recdb.delete_old("6") - tasks=recdb.getnow("2") - #print tasks - inum=recdb.countRecNow_minutes("10") - #inum=recdb.countRecNow("1") - print "now-rectask" - print "inum:"+str(inum)+"bscsrec:"+str(status.getBSCSRecording())+"terec:"+str(status.getTERecording())+" epg:"+str(status.getEPGUpdating()) - - #if inum+status.getBSCSRecording()+status.getTERecording() < 2: - update=chdb.update() - print update - print "番組表更新処理" - if len(update)>0: - pid=os.fork() + try: + if rec10d.rec10db.select_installed_in_status()==0: + install.install() + except: + install.install() + recdb.delete_old("24") + recdb.delete_old_auto_bayes("1") + recdb.delete_old_auto_keyword("1") + tasks = recdb.getnow("2") + inum = recdb.countRecNow_minutes("10") + recdblist.printutf8(u"rec10処理開始"+ datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + recdblist.printutf8(u"直近録画予約件数:" + str(inum) + u"BS/CS録画中件数:" + str(status.getBSCSRecording()) + u"TE録画中件数:" + str(status.getTERecording()) ) + encodenum=0 + b25num=0 + dnow=datetime.datetime.now() + if dnow.minute%10<5: + pid = os.fork() + if pid != 0: + "" + else: + for k in recdb.get_key(): + search_keyword(k) + sys.exit() + else: + pid = os.fork() if pid!=0: - time.sleep(1) + "" else: - i=0 + time.sleep(10) + auto_process.auto_check(recpath) + sys.exit() + update = chdb.update() + if len(update) > 0: + pid = os.fork() + if pid != 0: + "" + else: + i = 0 for bctype in update: - recnum=0 - if bctype.find('te')!=-1: - recnum=status.getTERecording()+recdb.countRecNow_minutes_TE("10") - print bctype+"//ing:"+str(status.getTERecording())+":task:"+str(recdb.countRecNow_minutes_TE("10")) + recnum = 0 + if bctype.find('te') > -1: + recnum = status.getTERecording() + recdb.countRecNow_minutes_TE("10") + recdblist.printutf8(u"放送種別:"+bctype + u"||該当チューナー実行中件数:" + str(status.getTERecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_TE("10"))) + recnum = int(configreader.getenv("te_max")) -recnum else: - recnum=status.getBSCSRecording()+recdb.countRecNow_minutes_BSCS("10") - print bctype+"//ing:"+str(status.getBSCSRecording())+":task:"+str(recdb.countRecNow_minutes_BSCS("10")) - if recnum < 2: + recnum = status.getBSCSRecording() + recdb.countRecNow_minutes_BSCS("10") + recdblist.printutf8(u"放送種別:"+bctype + u"||該当チューナー実行中件数:" + str(status.getBSCSRecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_BSCS("10"))) + recnum = int(configreader.getenv("bscs_max")) -recnum + if recnum >0 : print update - rec10d.rec10db.update_status_by_bctype_chdata(bctype,"0") + rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "0") epgdb.updatebc(bctype) - update=chdb.update() - #rec10d.rec10db.update_by_bctype_chdata(bctype) - i=i+1 - if i>1: + update = chdb.update() + i = i + 1 + if i > 0: break sys.exit() - """if len(update)>0 and status.getEPGUpdating()==0: - #status.setEPGUpdating(1) - print "番組表を更新" - #print update - status.setEPGUpdating(1) - pid=os.fork() - if pid!=0:#親プロセスの場合 - "" - else:#子プロセスの場合 アップデートを行って終了 - i=0 - for bctype in update: - time.sleep(1) - print bctype - epgdb.updatebc(bctype) - update=chdb.update() - i=i+1 - print update - if i>10: - break - status.setEPGUpdating(0) - sys.exit()""" for task in tasks: - #print task + typetxt = task["type"] try: - chtxt=task['chtxt'] + chtxt = task['chtxt'] except: - chtxt="" + chtxt = "" try: - title=task['title'] + title = task['title'] except: - title="" + title = "" try: - btime=task['btime'] - bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S") + btime = task['btime'] + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") except: - btime="" - bt=datetime.datetime.strptime("2009-01-01 00:00:00","%Y-%m-%d %H:%M:%S") + btime = "" + bt = datetime.datetime.strptime("2009-01-01 00:00:00", "%Y-%m-%d %H:%M:%S") try: - etime=task['etime'] - et=datetime.datetime.strptime(etime,"%Y-%m-%d %H:%M:%S") + etime = task['etime'] + et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") except: - etime="" - et=datetime.datetime.strptime("2009-01-01 00:00:00","%Y-%m-%d %H:%M:%S") + etime = "" + et = datetime.datetime.strptime("2009-01-01 00:00:00", "%Y-%m-%d %H:%M:%S") try: - opt=task['opt'] + opt = task['opt'] except: - opt="" - tnow=datetime.datetime.now() - dtt=bt-tnow - dt=dtt.days*24*60*60+dtt.seconds - - if task["type"]==recdb.REC_RESERVE:#"res,"+chtxt+","+title+","+btime+","+etime+","+opt - print dt - if (dt<58*60 and dt>20*60): - pid=os.fork() - if pid!=0:#親プロセスの場合 + opt = "" + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + if task["type"] == recdblist.REC_RESERVE:#"res,"+chtxt+","+title+","+btime+","+etime+","+opt + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + type_reserve(task["type"],chtxt,title,bt,et,opt) + sys.exit() + elif task["type"] == recdblist.REC_KEYWORD:#"key,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt + deltatime = task['deltatime'] + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + type_keyword(task["type"],chtxt,title, bt, et, opt, deltatime) + sys.exit() + elif task["type"] == recdblist.REC_KEYWORD_EVERY_SOME_DAYS:#"keyevery,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt+","+deltaday + deltatime = task['deltatime'] + deltaday = task['deltaday'] + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + type_keyword_every_day(task["type"],chtxt, title, bt, et, opt, deltatime, deltaday) + sys.exit() + elif task["type"] == recdblist.REC_FINAL_RESERVE:#"rec,"+chtxt+","+title+","+btime+","+etime+","+opt + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + type_final(task["type"],chtxt, title, bt, et, opt) + sys.exit() + elif task["type"] == recdblist.REC_TS_DECODE_QUE: + b25num=b25num+1 + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + time.sleep(5*b25num) + type_decode_que(task["type"],chtxt, title, bt, et, opt) + sys.exit() + elif task["type"] == recdblist.REC_ENCODE_QUE: + encodenum=encodenum+1 + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + time.sleep(5*encodenum) + type_encode_que(task["type"],chtxt, title, bt, et, opt) + sys.exit() + elif task["type"] == recdblist.REC_AVI_TO_MKV: + if dt < 10 * 60: + pid = os.fork() + if pid > 0:#親プロセスの場合 "" - else:#子プロセスの場合 アップデートを行って終了 - bctypet=chdb.chtxtsearch(chtxt)['bctype'] - chdatat=rec10d.rec10db.select_by_bctype_chdata(bctypet) - dt1=datetime.datetime.now()-datetime.datetime.strptime(chdatat[0][5],"%Y-%m-%d %H:%M:%S") - dt1=dt1.days*24*60*60+dt1.seconds - if dt1<60*60: - recdata=epgdb.searchtime2(title.decode('utf-8'),btime,"5",chtxt) - chtxtn=recdata[0] - titlen=recdata[1] - btimen=recdata[2] - etimen=recdata[3] - bt=datetime.datetime.strptime(btimen,"%Y-%m-%d %H:%M:%S") - et=datetime.datetime.strptime(etimen,"%Y-%m-%d %H:%M:%S") - btimen=bt.strftime("%Y-%m-%d %H:%M:%S") - etimen=et.strftime("%Y-%m-%d %H:%M:%S") - if chtxt!="": - try: - recdb.del_reckey(recdb.REC_RESERVE, title, chtxt, btime) - recdb.rec_reckey(recdb.REC_FINAL_RESERVE, titlen, chtxtn, btimen, etimen, opt) - except Exception,inst: - print type(inst) - print inst - else: - print "nothing match" - else: - print rec10d.rec10db.select_by_bctype_chdata(bctypet) - if rec10d.rec10db.select_by_bctype_chdata(bctypet)[0][6]!="0": - rec10d.rec10db.update_status_by_bctype_chdata(bctypet,"3") - sys.exit() - """cht=chdb.chtxtsearch(chtxt)['bctype'] - if cht.find('te')!=-1: - cht='te' - else: - cht='bscs' - bctypetemp=chdb.chtxtsearch(chtxt)['bctype'] - if cht=='bscs': - gettaskbscs=recdb.countRecNow_minutes_BSCS("10") - getnowbscs=status.getBSCSRecording() - bscs=getnowbscs+gettaskbscs - if bscs <2 and status.getEPGUpdating()!=1: - print "now(bscs):"+str(getnowbscs)+" task(bscs):"+str(gettaskbscs) - status.setEPGUpdating(1) - rec10d.rec10db.update_status_by_bctype_chdata(bctype,"0") - epgdb.updatebc(bctypetemp) - time.sleep(10) - isUpdate=1 - status.setEPGUpdating(0) - else: - isUpdate=0 - if cht=="te": - gettaskte=recdb.countRecNow_minutes_TE("10") - getnowte=status.getTERecording() - te=getnowte+gettaskte - if te <2 and status.getEPGUpdating()!=1: - print "now(te):"+str(getnowte)+" task(te):"+str(gettaskte) - status.setEPGUpdating(1) - epgdb.updatebc(bctypetemp) - time.sleep(10) - status.setEPGUpdating(0) - isUpdate=1 - else: - isUpdate=0 - if isUpdate: - recdata=epgdb.searchtime2(title.decode('utf-8'),btime,"5",chtxt) - chtxtn=recdata[0] - titlen=recdata[1] - btimen=recdata[2] - etimen=recdata[3] - bt=datetime.datetime.strptime(btimen,"%Y-%m-%d %H:%M:%S") - et=datetime.datetime.strptime(etimen,"%Y-%m-%d %H:%M:%S") - btimen=bt.strftime("%Y-%m-%d %H:%M:%S") - etimen=et.strftime("%Y-%m-%d %H:%M:%S") - if chtxt!="": - try: - recdb.del_reckey(recdb.REC_RESERVE, title, chtxt, btime) - recdb.rec_reckey(recdb.REC_FINAL_RESERVE, titlen, chtxtn, btimen, etimen, opt) - except Exception,inst: - print type(inst) - print inst - else: - print "nothing match" - else: - "" - sys.exit()""" - - elif dt<=10*60: - try: - recdb.del_reckey(recdb.REC_RESERVE, title, chtxt, btime) - recdb.rec_reckey(recdb.REC_FINAL_RESERVE, title, chtxt, btime, etime, opt) - except Exception,inst: - print type(inst) - print inst - elif task["type"]==recdb.REC_KEYWORD:#"key,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt - deltatime=task['deltatime'] - if dt<90*60: - recdata=epgdb.searchtime2(title.decode('utf-8'),btime,deltatime,chtxt) - if recdata[1]!="": - chtxtt=recdata[0] - titlet=recdata[1] - btimet=recdata[2] - etimet=recdata[3] - bt=datetime.datetime.strptime(btimet,"%Y-%m-%d %H:%M:%S") - et=datetime.datetime.strptime(etimet,"%Y-%m-%d %H:%M:%S") - btimet=bt.strftime("%Y-%m-%d %H:%M:%S") - etimet=et.strftime("%Y-%m-%d %H:%M:%S") - try: - recdb.del_reckey(recdb.REC_KEYWORD, title, chtxt, btime) - recdb.rec_reckey(recdb.REC_RESERVE, titlet, chtxtt, btimet, etimet, opt) - except Exception,inst: - print type(inst) - print inst else: - print "nothing match" - elif task["type"]==recdb.REC_KEYWORD_EVERY_SOME_DAYS:#"keyevery,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt+","+deltaday - deltatime=task['deltatime'] - deltaday=task['deltaday'] - dd=datetime.timedelta(days=int(deltaday)) - if dtt.days<0: - recdb.del_reckey(recdb.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime) - bt=bt+dd - et=et+dd - btxt=bt.strftime("%Y-%m-%d %H:%M:%S") - etxt=et.strftime("%Y-%m-%d %H:%M:%S") - recdb.everyreserv(title,chtxt,btxt,etxt,deltatime,opt,deltaday) - elif dt<120*60: - recdb.keyreserv(title,chtxt,btime,etime,deltatime,opt) - recdb.del_reckey(recdb.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime) - bt=bt+dd - et=et+dd - btxt=bt.strftime("%Y-%m-%d %H:%M:%S") - etxt=et.strftime("%Y-%m-%d %H:%M:%S") - recdb.everyreserv(title,chtxt,btxt,etxt,deltatime,opt,deltaday) - - elif task["type"]==recdb.REC_FINAL_RESERVE:#"rec,"+chtxt+","+title+","+btime+","+etime+","+opt - print dt - if dt<6*60 and dt>0: - recdb.del_reckey(recdb.REC_FINAL_RESERVE, title, chtxt, btime) - recdb.rec_reckey(recdb.REC_TS_RECORDING, title, chtxt, btime, etime, opt) - print "録画開始" - pid=os.fork() - if pid!=0:#親プロセスの場合 + recdb.del_reckey(recdblist.REC_AVI_TO_MKV, title, chtxt, btime) + recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt) + #tv2mp4.avi2mp4(os.path.join(recpath,title+".avi"),os.path.join(recpath,title+".mkv"),opt) + tv2mkv.avi2mkv(os.path.join(recpath,title+".avi"),os.path.join(recpath,title+".mkv"),opt) + recdb.del_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime) + sys.exit() + elif task["type"] == recdblist.REC_AVI_TO_MP4: + if dt < 10 * 60: + pid = os.fork() + if pid > 0:#親プロセスの場合 "" else: - #print title - tv2avi.timetv2b25(recpath+"/"+title+".avi", chtxt, btime, etime, opt) - recdb.del_reckey(recdb.REC_TS_RECORDING, title, chtxt, btime) - tnow=datetime.datetime.now() - bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S") - et=datetime.datetime.strptime(etime,"%Y-%m-%d %H:%M:%S") - dt=tnow-bt - bt=tnow+datetime.timedelta(seconds=600) - et=et+dt+datetime.timedelta(seconds=600) - btime=bt.strftime("%Y-%m-%d %H:%M:%S") - etime=et.strftime("%Y-%m-%d %H:%M:%S") - recdb.rec_reckey(recdb.REC_TS_DECODE_QUE,title,chtxt,btime,etime,opt) + recdb.del_reckey(recdblist.REC_AVI_TO_MP4, title, chtxt, btime) + recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt) + tv2mp4.avi2mp4(os.path.join(recpath,title+".avi"),os.path.join(recpath,title+".mp4"),opt) + recdb.del_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime) sys.exit() - elif task["type"]==recdb.REC_TS_DECODE_QUE: - if dt<10*60: - if status.getB25Decoding()<2: - pid=os.fork() - if pid!=0:#親プロセスの場合 - "" - else: - pin=recpath+"/"+title - recdb.del_reckey(recdb.REC_TS_DECODE_QUE,title,chtxt,btime) - recdb.rec_reckey(recdb.REC_TS_DECODING, title, chtxt, btime, etime, opt) - tv2avi.b252ts(pin, chtxt, btime, etime, opt) - recdb.del_reckey(recdb.REC_TS_DECODING,title,chtxt,btime) - if not os.access(recpath+"/"+title+".ts", os.F_OK): - recdb.del_reckey(recdb.REC_TS_DECODING, title, chtxt, btime) - recdb.rec_reckey(recdb.REC_MISS_DECODE, title, chtxt, btime, etime, opt) - tnow=datetime.datetime.now() - bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S") - et=datetime.datetime.strptime(etime,"%Y-%m-%d %H:%M:%S") - dt=tnow-bt - bt=tnow+datetime.timedelta(seconds=600) - et=et+dt+datetime.timedelta(seconds=600) - btime=bt.strftime("%Y-%m-%d %H:%M:%S") - etime=et.strftime("%Y-%m-%d %H:%M:%S") - recdb.rec_reckey(recdb.REC_ENCODE_QUE, title, chtxt, btime, etime, opt) - print "b25check "+recpath+"/"+title+".ts.b25 "+recpath+"/"+title+".ts" - print checker.checkB25Decode(recpath+"/"+title+".ts.b25",recpath+"/"+title+".ts") - if checker.checkB25Decode(recpath+"/"+title+".ts.b25",recpath+"/"+title+".ts")==1: - os.remove(recpath+"/"+title+".ts.b25") - sys.exit() + elif task["type"] == recdblist.REC_MKV_TO_MP4: + if dt < 10 * 60: + pid = os.fork() + if pid > 0:#親プロセスの場合 + "" else: - recdb.del_reckey(recdb.REC_TS_DECODE_QUE,title,chtxt,btime) - bt=bt+datetime.timedelta(seconds=600) - et=et+datetime.timedelta(seconds=600) - btime=bt.strftime("%Y-%m-%d %H:%M:%S") - etime=et.strftime("%Y-%m-%d %H:%M:%S") - recdb.rec_reckey(recdb.REC_TS_DECODE_QUE,title,chtxt,btime,etime,opt) - elif task["type"]==recdb.REC_ENCODE_QUE: - if dt<10*60: - if status.getEncoding()0:#親プロセスの場合 - "" - else: - pin=recpath+"/"+title+".ts" - if re.search("d",opt): - pin=recpath+"/"+title+"sa.avi" - if re.search("5",opt): - pin=recpath+"/"+title+"sa.avi" - pout=recpath+"/"+title+".avi" - print [pin,pout,opt] - #print pin+":"+pout+":"+opt - recdb.del_reckey(recdb.REC_ENCODE_QUE,title,chtxt,btime) - recdb.rec_reckey(recdb.REC_ENCODE_LOCAL, title, chtxt, btime, etime, opt) - tv2avi.ts2avi(pin, pout, opt) - recdb.del_reckey(recdb.REC_ENCODE_LOCAL,title,chtxt,btime) - recdb.rec_reckey(recdb.REC_FIN_LOCAL, title, chtxt, btime, etime, opt) - sys.exit() + recdb.del_reckey(recdblist.REC_MKV_TO_MP4, title, chtxt, btime) + recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt) + tv2mp4.mkv2mp4(os.path.join(recpath,title+".mkv"),os.path.join(recpath,title+".mp4")) + recdb.del_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime) + sys.exit() + sys.exit() +def search_keyword(key): + tnow = datetime.datetime.now() + nows =tnow.strftime("%Y-%m-%d %H:%M:%S") + for k in key: + recdatum = epgdb.searchtime_auto(k,nows, "144") + for recdata in recdatum: + if recdata[1] != "": + chtxtt = recdata[0] + titlet = recdata[1] + btimet = recdata[2] + etimet = recdata[3] + btt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S") + ett = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S") + btimet = btt.strftime("%Y-%m-%d %H:%M:%S") + etimet = ett.strftime("%Y-%m-%d %H:%M:%S") + try: + recdb.add_auto_keyword(chtxtt, titlet, btimet, etimet) + except Exception, inst: + print "error occures in search_keyword" + print type(inst) + print inst +def type_reserve(typetxt,chtxt,title,bt,et,opt): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + typetxtnow=typetxt + typetxtfinal="" + if typetxt==recdblist.REC_RESERVE: + typetxtfinal=recdblist.REC_FINAL_RESERVE + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + if (dt < 58 * 60 and dt > 30 * 60): + bctypet = chdb.chtxtsearch(chtxt)['bctype'] + chdatat = rec10d.rec10db.select_by_bctype_epg_ch(bctypet) + dt1 = datetime.datetime.strptime(chdatat[0][5], "%Y-%m-%d %H:%M:%S")-datetime.datetime.now() + dt1 = dt1.days * 24 * 60 * 60 + dt1.seconds + if dt1 < 60 * 60: + recdata = epgdb.searchtime2(title, btime, "5", chtxt) + chtxtn = recdata[0] + titlen = recdata[1] + btimen = recdata[2] + etimen = recdata[3] + exp = recdata[4] + longexp = recdata[5] + category=recdata[6] + bt = datetime.datetime.strptime(btimen, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etimen, "%Y-%m-%d %H:%M:%S") + btimen = bt.strftime("%Y-%m-%d %H:%M:%S") + etimen = et.strftime("%Y-%m-%d %H:%M:%S") + if chtxt != "": + try: + recdb.del_reckey(typetxtnow, title, chtxt, btime) + recdb.rec_reckey(typetxtfinal, titlen, chtxtn, btimen, etimen, opt) + recdb.rec_reclog(titlen, chtxtn, btimen, etimen, opt, exp, longexp, category) + auto_rec.add_key(chtxt, titlen,exp+" "+longexp) + auto_rec.add_key("ALL", titlen,exp+" "+longexp) + recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen) + except Exception, inst: + print "Error happended in Oikake DB" + print type(inst) + print inst + else: + recdblist.printutf8(u"追いかけ機能エラー:番組データが見付かりません。") + else: + if rec10d.rec10db.select_by_bctype_epg_ch(bctypet)[0][6] != "0": + rec10d.rec10db.update_status_by_bctype_epg_ch(bctypet, "3") + sys.exit() + elif (dt <= 30 * 60 and dt > 20 * 60): + recdata = epgdb.searchtime2(title, btime, "5", chtxt) + chtxtn = recdata[0] + titlen = recdata[1] + btimen = recdata[2] + etimen = recdata[3] + exp = recdata[4] + longexp = recdata[5] + category=recdata[6] + bt = datetime.datetime.strptime(btimen, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etimen, "%Y-%m-%d %H:%M:%S") + btimen = bt.strftime("%Y-%m-%d %H:%M:%S") + etimen = et.strftime("%Y-%m-%d %H:%M:%S") + if chtxt != "": + try: + recdb.del_reckey(typetxtnow, title, chtxt, btime) + recdb.rec_reckey(typetxtfinal, titlen, chtxtn, btimen, etimen, opt) + recdb.rec_reclog(titlen, chtxtn, btimen, etimen, opt, exp, longexp, category) + auto_rec.add_key(chtxt, titlen,exp+" "+longexp) + auto_rec.add_key("ALL", titlen,exp+" "+longexp) + recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen) + except Exception, inst: + print "Error happended in Oikake DB" + print type(inst) + print inst + elif dt <= 20 * 60: + try: + recdb.del_reckey(typetxtnow, title, chtxt, btime) + recdb.rec_reckey(typetxtfinal, title, chtxt, btime, etime, opt) + except Exception, inst: + print type(inst) + print inst +def type_final(typetxt,chtxt,title,bt,et,opt): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + typetxtnow=typetxt + typetxting="" + typetxtdecque="" + if typetxt==recdblist.REC_FINAL_RESERVE: + typetxting=recdblist.REC_TS_RECORDING + typetxtdecque=recdblist.REC_TS_DECODE_QUE + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + print dt + if dt < 6 * 60 and dt > 0: + newtitle=title + recdb.del_reckey(typetxtnow, title, chtxt, btime) + testpath=[os.path.join(recpath,title+".ts.b25")] + testpath.append(os.path.join(recpath,title+".ts")) + testpath.append(os.path.join(recpath,title+".avi")) + testpath.append(os.path.join(recpath,title+".mp4")) + testpath.append(os.path.join(recpath,title+".log")) + tcheck=0 + for ti in testpath: + if os.path.exists(ti): + tcheck=tcheck+1 + if re.search("N", opt) or tcheck>0: + newtitle=newtitle+u"_"+bt.strftime("%Y%m%d%H%M") + recdb.rec_reckey(typetxting, newtitle, chtxt, btime, etime, opt) + recdblist.printutf8(u"録画開始 "+newtitle+" "+btime+" "+etime) + tv2avi.timetv2b25(recpath + "/" + newtitle + ".avi", chtxt, btime, etime, opt) + recdb.del_reckey(typetxting, newtitle, chtxt, btime) + if not re.search("R", opt): + tnow = datetime.datetime.now() + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + dt = tnow-bt + bt = tnow + datetime.timedelta(seconds=600) + et = et + dt + datetime.timedelta(seconds=600) + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.rec_reckey(typetxtdecque, newtitle, chtxt, btime, etime, opt) + else: + shutil.copy(os.path.join(recpath,title+".ts.b25"), os.path.join(movepath,title+".ts.b25")) + recdb.rec_reckey(recdblist.REC_MOVE_END, newtitle, chtxt, btime, etime, opt) + sys.exit() +def type_keyword(typetxt,chtxt,title,bt,et,opt,deltatime): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + typetxtnow=typetxt + typetxtres="" + if typetxt==recdblist.REC_KEYWORD: + typetxtres=recdblist.REC_RESERVE + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + print dt + if dt < 90 * 60: + recdata = epgdb.searchtime2(title, btime, deltatime, chtxt) + if recdata[1] != "": + chtxtt = recdata[0] + titlet = recdata[1] + btimet = recdata[2] + etimet = recdata[3] + exp = recdata[4] + longexp = recdata[5] + category=recdata[6] + bt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S") + btimet = bt.strftime("%Y-%m-%d %H:%M:%S") + etimet = et.strftime("%Y-%m-%d %H:%M:%S") + #try: + recdb.del_reckey(typetxtnow, title, chtxt, btime) + recdb.rec_reckey(typetxtres, titlet, chtxtt, btimet, etimet, opt) + recdb.rec_reclog(titlet, chtxtt, btimet, etimet, opt, exp,longexp,category) + auto_rec.add_key(chtxt, titlet,exp+" "+longexp) + auto_rec.add_key("ALL", titlet,exp+" "+longexp) + recdblist.printutf8(u"key "+title+u" : "+titlet+u" "+btimet+u" "+etimet) + #except Exception, inst: + # recdblist.printutf8("Error happened in REC_KEYWORD DB") + # recdblist.printutf8(type(inst)) + # recdblist.printutf8(inst) + else: + recdblist.printutf8("nothing match") + +def type_keyword_every_day(type,chtxt,title,bt,et,opt,deltatime,deltaday): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + dd = datetime.timedelta(days=int(deltaday)) + if dtt.days < 0: + recdb.del_reckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime) + bt = bt + dd + et = et + dd + btxt = bt.strftime("%Y-%m-%d %H:%M:%S") + etxt = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.everyreserv(title, chtxt, btxt, etxt, deltatime, opt, deltaday) + elif dt < 120 * 60: + recdb.keyreserv(title, chtxt, btime, etime, deltatime, opt) + recdb.del_reckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime) + bt = bt + dd + et = et + dd + btxt = bt.strftime("%Y-%m-%d %H:%M:%S") + etxt = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.everyreserv(title, chtxt, btxt, etxt, deltatime, opt, deltaday) + + +def type_decode_que(typetxt,chtxt,title,bt,et,opt): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + typetxtnow=typetxt + typetxting="" + typetxtmiss="" + typetxtencque="" + if typetxt== recdblist.REC_TS_DECODE_QUE: + typetxting=recdblist.REC_TS_DECODING + typetxtmiss=recdblist.REC_MISS_DECODE + typetxtencque=recdblist.REC_ENCODE_QUE + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + if dt < 10 * 60: + if status.getB25Decoding() < 2: + pin = recpath + "/" + title + recdb.del_reckey(typetxtnow, title, chtxt, btime) + recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt) + tv2avi.b252ts(pin, chtxt, btime, etime, opt) + recdb.del_reckey(typetxting, title, chtxt, btime) + if not os.access(recpath + "/" + title + ".ts", os.F_OK): + recdb.del_reckey(typetxting, title, chtxt, btime) + recdb.rec_reckey(typetxtmiss, title, chtxt, btime, etime, opt) + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + dt = et-bt + if not re.search("D", opt): + tnow = datetime.datetime.now() + bt = tnow + datetime.timedelta(seconds=600) + et = bt + dt + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.rec_reckey(typetxtencque, title, chtxt, btime, etime, opt) + else: + if opt.rfind("d")>=0: + shutil.copy(os.path.join(recpath,title+".sa.avi"),os.path.join(movepath,title+".sa.avi")) + elif opt.rfind("5")>=0: + shutil.copy(os.path.join(recpath,title+".sa.avi"),os.path.join(movepath,title+".sa.avi")) else: - recdb.del_reckey(recdb.REC_ENCODE_QUE,title,chtxt,btime) - bt=bt+datetime.timedelta(seconds=600) - et=et+datetime.timedelta(seconds=600) - btime=bt.strftime("%Y-%m-%d %H:%M:%S") - etime=et.strftime("%Y-%m-%d %H:%M:%S") - recdb.rec_reckey(recdb.REC_ENCODE_QUE,title,chtxt,btime,etime,opt) + shutil.copy(os.path.join(recpath,title+".ts"), os.path.join(movepath,title+".ts")) + recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt) + if checker.checkB25Decode(recpath + "/" + title + ".ts.b25", recpath + "/" + title + ".ts") == 1: + os.remove(recpath + "/" + title + ".ts.b25") + else: + recdb.del_reckey(typetxtnow, title, chtxt, btime) + bt = bt + datetime.timedelta(seconds=600) + et = et + datetime.timedelta(seconds=600) + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.rec_reckey(typetxtnow, title, chtxt, btime, etime, opt) + sys.exit() + +def type_encode_que(typetxt,chtxt,title,bt,et,opt): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + typetxtnow=typetxt + typetxting="" + typetxtfin="" + if typetxt==recdblist.REC_ENCODE_QUE: + typetxting=recdblist.REC_ENCODE_LOCAL + typetxtfin=recdblist.REC_FIN_LOCAL + if dt < 10 * 60: + if status.getEncoding() < int(configreader.getenv("enc_max")): + recdblist.printutf8(opt) + pin = recpath + "/" + title + ".ts" + if re.search("d", opt): + pin = recpath + "/" + title + ".sa.avi" + if re.search("5", opt): + pin = recpath + "/" + title + ".sa.avi" + #pout = recpath + "/" + title + ".avi" + pout = recpath + "/" + title + ".mkv" + recdblist.printutf8(pin) + #recdblist.printutf8(pin+":"+pout+":"+opt) + recdb.del_reckey(typetxtnow, title, chtxt, btime) + recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt) + tv2mkv.ts2mkv(pin, pout, opt) + #tv2mp4.ts2mp4(pin, pout, opt) + #tv2avi.ts2avi(pin, pout, opt) + recdb.del_reckey(typetxting, title, chtxt, btime) + if re.search("E", opt): + shutil.copy(os.path.join(recpath,title+".mp4"), os.path.join(movepath,title+".mp4")) + recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt) + recdb.rec_reckey(typetxtfin, title, chtxt, btime, etime, opt) + sys.exit() + else: + recdb.del_reckey(typetxtnow, title, chtxt, btime) + bt = bt + datetime.timedelta(seconds=600) + et = et + datetime.timedelta(seconds=600) + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.rec_reckey(typetxtnow, title, chtxt, btime, etime, opt) + sys.exit() \ No newline at end of file