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)
33 ts2epg.write(tmppath+"epgdate.xml",chdb.bctypesearch(bctype)['ch'])
34 xml2db.xml2db(tmppath+"epgdate.xml",path+"ch.db",bctype)
51 db=sqlite3.connect(dbpath)
54 for ch, title, start, stop in db.execute("SELECT channel,title,start,stop FROM tv WHERE title LIKE \"%"+titletxt+"%\""):
55 btime=start.replace(" +0900","")
56 btime=btime[0:4]+"-"+btime[4:6]+"-"+btime[6:8]+" "+btime[8:10]+":"+btime[10:12]+":00"
57 etime=stop.replace(" +0900","")
58 etime=etime[0:4]+"-"+etime[4:6]+"-"+etime[6:8]+" "+etime[8:10]+":"+etime[10:12]+":00"
60 chtxt=chdb.ontvsearch(ch)['chtxt']
64 ret.append(chtxt+","+title.encode('utf-8')+","+btime+","+etime)
67 def searchtime(titletxt,time,deltatime):#時間以内のものだけを表示 deltatimeはhours
69 db=sqlite3.connect(dbpath)
72 deltatime=int(deltatime)
73 for ch, title, start, stop in db.execute("SELECT channel,title,start,stop FROM tv WHERE title LIKE \"%"+titletxt+"%\""):
74 btime=start.replace(" +0900","")
75 btime=btime[0:4]+"-"+btime[4:6]+"-"+btime[6:8]+" "+btime[8:10]+":"+btime[10:12]+":00"
76 etime=stop.replace(" +0900","")
77 etime=etime[0:4]+"-"+etime[4:6]+"-"+etime[6:8]+" "+etime[8:10]+":"+etime[10:12]+":00"
78 bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S")
79 t=datetime.datetime.strptime(time,"%Y-%m-%d %H:%M:%S")
81 chtxt=chdb.ontvsearch(ch)['chtxt']
86 dt=dt.days*24*60*60+dt.seconds
88 if dt<deltatime*60*60:
89 ret.append(chtxt+","+title.encode('utf-8')+","+btime+","+etime)
93 def searchtime2(titletxt,timet,deltatime,chtxt):
94 time=datetime.datetime.strptime(timet,"%Y-%m-%d %H:%M:%S")
96 db=sqlite3.connect(dbpath)
99 deltatime=int(deltatime)
100 beforetime=time.strftime("%Y%m%d%H%M%S")
101 aftertime=time+datetime.timedelta(hours=deltatime)
102 aftertime=aftertime.strftime("%Y%m%d%H%M%S")
103 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+"\""
107 for chtxtt, title, start, stop in db.execute(dbexe):
109 p=n_gram.bigram(titletxt,title)
111 btime=btime[0:4]+"-"+btime[4:6]+"-"+btime[6:8]+" "+btime[8:10]+":"+btime[10:12]+":00"
113 etime=etime[0:4]+"-"+etime[4:6]+"-"+etime[6:8]+" "+etime[8:10]+":"+etime[10:12]+":00"
114 bt=datetime.datetime.strptime(btime,"%Y-%m-%d %H:%M:%S")
115 et=datetime.datetime.strptime(etime,"%Y-%m-%d %H:%M:%S")
117 dt=24*60*60*dt.days+dt.seconds+1
119 dt=1000-1000*dt/(7*24*60*60)
124 one=chtxtt+","+title.encode('utf-8')+","+btime+","+etime
127 print title+":"+str(p)+"点"