# Rec10 TS Recording Tools
# Copyright (C) 2009 Yukikaze
import os
+import time
import sqlite3
import chdb
import datetime
import ts2epg
import xml2db
+import n_gram
path=str(os.path.dirname(os.path.abspath(__file__)))+"/"
tmppath=path
def update(chtxt):
dt=abs(dt)
if dt<deltatime*60*60:
ret.append(chtxt+","+title.encode('utf-8')+","+btime+","+etime)
+ print title
db.close()
return ret
+def searchtime2(titletxt,timet,deltatime,chtxt):
+ time=datetime.datetime.strptime(timet,"%Y-%m-%d %H:%M:%S")
+ dbpath=path+"ch.db"
+ db=sqlite3.connect(dbpath)
+ #print dbpath
+ ret=[]
+ deltatime=int(deltatime)
+ beforetime=time.strftime("%Y%m%d%H%M%S")
+ aftertime=time+datetime.timedelta(hours=deltatime)
+ aftertime=aftertime.strftime("%Y%m%d%H%M%S")
+ dbexe="SELECT chdata.chtxt,title,start,stop FROM tv INNER JOIN chdata WHERE chdata.ontv=tv.channel AND start >= \""+beforetime+"\" AND start <= \""+aftertime+"\" AND chdata.chtxt=\""+chtxt+"\""
+ #print dbexe
+ one={}
+ tempt=0
+ for chtxtt, title, start, stop in db.execute(dbexe):
+ """btime=start.replace(" +0900","")
+ btime=btime[0:4]+"-"+btime[4:6]+"-"+btime[6:8]+" "+btime[8:10]+":"+btime[10:12]+":00"
+ etime=stop.replace(" +0900","")
+ etime=etime[0:4]+"-"+etime[4:6]+"-"+etime[6:8]+" "+etime[8:10]+":"+etime[10:12]+":00"
+ bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S")
+ t=datetime.datetime.strptime(time,"%Y-%m-%d %H:%M:%S")
+ try:
+ chtxt=chdb.ontvsearch(ch)['chtxt']
+ except:
+ chtxt="Unknown"
+ #print ch
+ dt=bt-t
+ dt=dt.days*24*60*60+dt.seconds
+ dt=abs(dt)
+ if dt<deltatime*60*60:
+ ret.append(chtxt+","+title.encode('utf-8')+","+btime+","+etime)
+ """
+ ret=[]
+ p=n_gram.bigram(titletxt,title)
+ btime=start
+ btime=btime[0:4]+"-"+btime[4:6]+"-"+btime[6:8]+" "+btime[8:10]+":"+btime[10:12]+":00"
+ etime=stop
+ etime=etime[0:4]+"-"+etime[4:6]+"-"+etime[6:8]+" "+etime[8:10]+":"+etime[10:12]+":00"
+ bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S")
+ et=datetime.datetime.strptime(etime,"%Y-%m-%d %H:%M:%S")
+ dt=bt-time
+ dt=24*60*60*dt.days+dt.seconds+1
+ p=p*90
+ dt=1000-1000*dt/(7*24*60*60)
+ if p>0:
+ p=p+dt
+ print dt
+ if p>tempt:
+ one=chtxtt+","+title.encode('utf-8')+","+btime+","+etime
+ tempt=p
+ if p>0:
+ print title+":"+str(p)+"点"
+ db.close()
+ ret.append(one)
+ print ret
+ return ret
"""
recdb.delete_old("6")
tasks=recdb.getnow("1")
- if len(tasks)==0:
+ inum=recdb.countRecNow("1")
+ print "now-rectask"
+ print inum
+ if inum==0:
update=chdb.update()
#print "番組表更新処理"
print update
elif task["type"]==recdb.REC_KEYWORD:#"key,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt
deltatime=task['deltatime']
- if dt<30*60:
- recdatum=epgdb.searchtime(title,btime,deltatime)
+ if dt<90*60:
+ recdatum=epgdb.searchtime2(title.decode('utf-8'),btime,deltatime,chtxt)
if len(recdatum)>0:
recdb.del_reckey(recdb.REC_KEYWORD, title, chtxt, btime)
for recdata in recdatum:
print "ts2epg処理"
bctype=chdb.chsearch(ch)['bctype']
print ch+":"+bctype
- timet="120"
+ timet="180"
if re.search(u'cs',bctype):
mode="/CS"
- timet="300"
+ timet="240"
elif re.search(u'bs',bctype):
mode="/BS"
- timet="300"
+ timet="180"
else :
mode=chdb.bctypesearch(u'te'+ch)['ontv']
tsepg2xml=configreader.getpath("tsepg2xml")
epgdump=configreader.getpath("epgdump")
if os.access(pout+".ts", os.F_OK):
- os.removedirs(pout+".ts")
- time.sleep(5)
+ os.remove(pout+".ts")
+ time.sleep(10)
print type(ch)
print ch
- tv2ts.tv2tsmix(pout+".ts",ch,"180")
+ tv2ts.tv2tsmix(pout+".ts",ch,timet)
t=0
while not os.access(pout+".ts", os.F_OK):
time.sleep(10)
- tv2ts.tv2tsmix(pout+".ts",ch,"180")
+ tv2ts.tv2tsmix(pout+".ts",ch,timet)
t=t+1
if t>10:
break
#exe="export LANG=ja_JP.UTF-8 && /usr/bin/nice -n 19 "+epgdump+" "+mode+" "+pout+".ts "+pout
print exe
os.system(exe)
- time.sleep(5)
+ time.sleep(10)