#!/usr/bin/python
# coding: UTF-8
# Rec10 TS Recording Tools
-# Copyright (C) 2009 Yukikaze
+# Copyright (C) 2009-2010 Yukikaze
import datetime
import os
import os.path
import tv2avi
import tv2mkv
import tv2mp4
+import install
import recdblist
recpath = configreader.getpath('recpath')
movepath = configreader.getpath('move_destpath')
数分毎に実行されるタスク処理
予定によって子プロセスを生成し処理する。
"""
+ 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")
encodenum=0
b25num=0
dnow=datetime.datetime.now()
- if dnow.hour==12 and dnow.minute<5 :
+ if dnow.minute%10<5:
pid = os.fork()
if pid != 0:
- time.sleep(1)
+ ""
else:
for k in recdb.get_key():
search_keyword(k)
else:
pid = os.fork()
if pid!=0:
- time.sleep(1)
+ ""
else:
+ time.sleep(10)
auto_process.auto_check(recpath)
sys.exit()
update = chdb.update()
if len(update) > 0:
pid = os.fork()
if pid != 0:
- time.sleep(1)
+ ""
else:
i = 0
for bctype in update:
else:
recdb.del_reckey(recdblist.REC_AVI_TO_MKV, title, chtxt, btime)
recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt)
- tv2mkv.avi2mkv(os.path.join(recpath,title+".avi"),os.path.join(recpath,title+".mkv"))
+ #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:
else:
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"))
+ 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"] == recdblist.REC_MKV_TO_MP4:
if pid > 0:#親プロセスの場合
""
else:
- recdb.del_reckey(recdblist.REC_AVI_TO_MP4, title, chtxt, btime)
+ 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()
- elif task["type"] == recdblist.REC_AUTO_KEYWORD:#"key,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt
- deltatime = "24"
- if dt < 90 * 60:
- recdatum = epgdb.searchtime_auto(title, btime, deltatime, chtxt)
- for recdata in recdatum:
- if recdata[1] != "":
- chtxtt = recdata[0]
- titlet = recdata[1]
- btimet = recdata[2]
- etimet = recdata[3]
- exp = recdata[4]
- longexp = recdata[5]
- category=recdata[6]
- 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.rec_reckey(recdblist.REC_AUTO_SUGGEST_REC, titlet, chtxtt, btimet, etimet, opt)
- except Exception, inst:
- print "Error occures in REC_AUTO_KEYWORD(1)"
- print type(inst)
- print inst
- dd = datetime.timedelta(days=1)
- bt = bt + dd
- et = et + dd
- btxt = bt.strftime("%Y-%m-%d %H:%M:%S")
- etxt = et.strftime("%Y-%m-%d %H:%M:%S")
- try:
- recdb.del_reckey(recdblist.REC_AUTO_KEYWORD, title, chtxt, btime)
- recdb.auto_keyreserv(title, chtxt, btxt, etxt, "24", opt)
- except Exception, inst:
- print "Error occures in REC_AUTO_KEYWORD(1)"
- print type(inst)
- print inst
sys.exit()
def search_keyword(key):
tnow = datetime.datetime.now()
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
+ if status.getSettings_auto_jbk()==1:
+ topt=status.getSettings_auto_opt()
+ try:
+ maxnum=0
+ if len(ch['ch'])>2:
+ maxnum=epgdb.count_schedule_timeline(btimet, etimet)[1]
+ maxnum=int(configreader.getenv("bscs_max"))-maxnum
+ else:
+ maxnum=epgdb.count_schedule_timeline(btimet, etimet)[0]
+ maxnum=int(configreader.getenv("te_max"))-maxnum
+ if maxnum>0:
+ topt=status.getSettings_auto_opt()
+ recdb.recreserv(titlet,chtxtt, btimet, etimet,topt)
+ except Exception, inst:
+ print "error occures in search_keyword_auto_jbk"
+ print type(inst)
+ print inst
+ else:
+ 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")
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("Oikake "+title+" : "+titlen+" "+btimen+" "+etimen)
+ recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen)
except Exception, inst:
- print "Error happended in Oikake DB"
+ print "Error happened in Oikake DB"
print type(inst)
print inst
else:
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 "Error happened in Oikake DB"
print type(inst)
print inst
elif dt <= 20 * 60:
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)
- recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt)
- recdblist.printutf8(u"録画開始 "+title+" "+btime+" "+etime)
- ttitle=title
- #recdblist.printutf8(title)
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+".mkv"))
+ 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 tcheck>0:
- ttitle=title+"_"+datetime.datetime.now().strftime("%Y%m%d%H%M")
- tv2avi.timetv2b25(recpath + "/" + ttitle + ".avi", chtxt, btime, etime, opt)
- recdb.del_reckey(typetxting, title, chtxt, btime)
+ if re.search("N", opt) or tcheck>0:
+ iff=""
+ try:
+ iff=u"("+configreader.getenv("iff")+u")_"
+ except:
+ iff=""
+ newtitle=newtitle+u"_"+iff+bt.strftime("%Y-%m-%dT%H:%M:%S")
+ 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 = 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, ttitle, chtxt, btime, etime, opt)
+ 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, ttitle, chtxt, btime, etime, opt)
+ try:
+ shutil.copy(os.path.join(recpath,title+".ts.b25"), os.path.join(movepath,title+".ts.b25"))
+ except:
+ ""
+ 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")
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:
+ try:
shutil.copy(os.path.join(recpath,title+".ts"), os.path.join(movepath,title+".ts"))
+ except Exception, inst:
+ errtxt="Error happened in type_decode_que in timerec.\n"
+ errtxt=errtxt+"move ts error.\n"
+ errtxt=errtxt+type(inst)+"\n"
+ errtxt=errtxt+inst
+ recdblist.addlog(os.path.join(recpath,title+".ts"), errtxt, "timerec-move(Decode) error")
recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt)
- #recdblist.printutf8(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")
else:
typetxtfin=recdblist.REC_FIN_LOCAL
if dt < 10 * 60:
if status.getEncoding() < int(configreader.getenv("enc_max")):
+ recdb.del_reckey(typetxtnow, title, chtxt, btime)
+ recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt)
recdblist.printutf8(opt)
pin = recpath + "/" + title + ".ts"
if re.search("d", opt):
- pin = recpath + "/" + title + ".sa.avi"
+ pin = recpath + "/" + title + ".m2v"
+ if not os.path.exists(pin):
+ tv2avi.dualaudio2sep(os.path.join(recpath, title+".ts"),"167")
+ time.sleep(3)
if re.search("5", opt):
pin = recpath + "/" + title + ".sa.avi"
- #pout = recpath + "/" + title + ".avi"
- pout = recpath + "/" + title + ".mp4"
+ if not os.path.exists(pin):
+ tv2avi.pentaaudiots2avi(os.path.join(recpath, title+".ts"), pin)
+ time.sleep(3)
+ 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)
+ tv2mkv.ts2mkv(pin, pout, opt)
recdb.del_reckey(typetxting, title, chtxt, btime)
- if re.search("R", opt):
- shutil.copy(os.path.join(recpath,title+".mp4"), os.path.join(movepath,title+".mp4"))
+ if re.search("E", opt):
+ try:
+ if os.path.exists(os.path.join(recpath,title+".mp4")):
+ shutil.copy(os.path.join(recpath,title+".mp4"), os.path.join(movepath,title+".mp4"))
+ elif os.path.exists(os.path.join(recpath,title+".mkv")):
+ shutil.copy(os.path.join(recpath,title+".mkv"), os.path.join(movepath,title+".mkv"))
+ except Exception, inst:
+ errtxt="Error happened in type_encode_que in timerec.\n"
+ errtxt=errtxt+"move mkv/mp4 error.\n"
+ errtxt=errtxt+type(inst)+"\n"
+ errtxt=errtxt+inst
+ recdblist.addlog(os.path.join(recpath,title+".ts"), errtxt, "timerec-move(Encode) error")
recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt)
recdb.rec_reckey(typetxtfin, title, chtxt, btime, etime, opt)
sys.exit()