3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
13 path=str(os.path.dirname(os.path.abspath(__file__)))+"/"
17 tnow=datetime.datetime.now()
19 lastup=datetime.datetime.strptime(chdb.chtxtsearch(chtxt)[0]['update'],"%Y-%m-%d %H:%M:%S")
21 lastup=datetime.datetime.strptime("2009-04-01 00:00:00","%Y-%m-%d %H:%M:%S")
23 dt=dt.days*24*60+dt.seconds
25 ts2epg.write(tmppath+"epgdate.xml",chdb.chtxtsearch(chtxt)['ch'])
26 xml2db.xml2db(tmppath+"epgdate.xml",path+"ch.db",chdb.chtxtsearch(chtxt)['bctype'])
28 bctypel=chdb.bctypesearch(bctype)
30 ts2epg.write(tmppath+"epgdate.xml",chdb.bctypesearch(bctype)['ch'])
31 xml2db.xml2db(tmppath+"epgdate.xml",path+"ch.db",bctype)
45 db=sqlite3.connect(dbpath)
48 for ch, title, start, stop in db.execute("SELECT channel,title,start,stop FROM tv WHERE title LIKE \"%"+titletxt+"%\""):
49 btime=start.replace(" +0900","")
50 btime=btime[0:4]+"-"+btime[4:6]+"-"+btime[6:8]+" "+btime[8:10]+":"+btime[10:12]+":00"
51 etime=stop.replace(" +0900","")
52 etime=etime[0:4]+"-"+etime[4:6]+"-"+etime[6:8]+" "+etime[8:10]+":"+etime[10:12]+":00"
54 chtxt=chdb.ontvsearch(ch)['chtxt']
58 ret.append(chtxt+","+title.encode('utf-8')+","+btime+","+etime)
61 def searchtime(titletxt,time,deltatime):#時間以内のものだけを表示 deltatimeはhours
63 db=sqlite3.connect(dbpath)
66 deltatime=int(deltatime)
67 for ch, title, start, stop in db.execute("SELECT channel,title,start,stop FROM tv WHERE title LIKE \"%"+titletxt+"%\""):
68 btime=start.replace(" +0900","")
69 btime=btime[0:4]+"-"+btime[4:6]+"-"+btime[6:8]+" "+btime[8:10]+":"+btime[10:12]+":00"
70 etime=stop.replace(" +0900","")
71 etime=etime[0:4]+"-"+etime[4:6]+"-"+etime[6:8]+" "+etime[8:10]+":"+etime[10:12]+":00"
72 bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S")
73 t=datetime.datetime.strptime(time,"%Y-%m-%d %H:%M:%S")
75 chtxt=chdb.ontvsearch(ch)['chtxt']
80 dt=dt.days*24*60*60+dt.seconds
82 if dt<deltatime*60*60:
83 ret.append(chtxt+","+title.encode('utf-8')+","+btime+","+etime)
87 def searchtime2(titletxt,timet,deltatime,chtxt):
88 time=datetime.datetime.strptime(timet,"%Y-%m-%d %H:%M:%S")
90 db=sqlite3.connect(dbpath)
93 deltatime=int(deltatime)
94 beforetime=time.strftime("%Y%m%d%H%M%S")
95 aftertime=time+datetime.timedelta(hours=deltatime)
96 aftertime=aftertime.strftime("%Y%m%d%H%M%S")
97 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+"\""
101 for chtxtt, title, start, stop in db.execute(dbexe):
102 """btime=start.replace(" +0900","")
103 btime=btime[0:4]+"-"+btime[4:6]+"-"+btime[6:8]+" "+btime[8:10]+":"+btime[10:12]+":00"
104 etime=stop.replace(" +0900","")
105 etime=etime[0:4]+"-"+etime[4:6]+"-"+etime[6:8]+" "+etime[8:10]+":"+etime[10:12]+":00"
106 bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S")
107 t=datetime.datetime.strptime(time,"%Y-%m-%d %H:%M:%S")
109 chtxt=chdb.ontvsearch(ch)['chtxt']
114 dt=dt.days*24*60*60+dt.seconds
116 if dt<deltatime*60*60:
117 ret.append(chtxt+","+title.encode('utf-8')+","+btime+","+etime)
121 p=n_gram.bigram(titletxt,title)
123 btime=btime[0:4]+"-"+btime[4:6]+"-"+btime[6:8]+" "+btime[8:10]+":"+btime[10:12]+":00"
125 etime=etime[0:4]+"-"+etime[4:6]+"-"+etime[6:8]+" "+etime[8:10]+":"+etime[10:12]+":00"
126 bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S")
127 et=datetime.datetime.strptime(etime,"%Y-%m-%d %H:%M:%S")
129 dt=24*60*60*dt.days+dt.seconds+1
131 dt=1000-1000*dt/(7*24*60*60)
136 one=chtxtt+","+title.encode('utf-8')+","+btime+","+etime
139 print title+":"+str(p)+"点"