3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2011 Yukikaze
19 path = str(os.path.dirname(os.path.abspath(__file__))) + "/"
20 tmppath = configreader.getConfPath("tmp")+"/"
23 if not os.path.exists(tmppath):
26 recdblist.printutf8(chtxt)
27 tnow = datetime.datetime.now()
29 lastup = datetime.datetime.strptime(chdb.searchCHFromChtxt(chtxt)[0]['update'], "%Y-%m-%d %H:%M:%S")
31 lastup = datetime.datetime.strptime("2009-04-01 00:00:00", "%Y-%m-%d %H:%M:%S")
33 dt = dt.days * 24 * 60 + dt.seconds
35 ts2epg.writeEpgXML(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.searchCHFromChtxt(chtxt)['ch'])
36 xml2db_dom.xml2db_dom(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.searchCHFromChtxt(chtxt)['bctype'])
38 bctypel = chdb.searchCHFromBctype(bctype)
41 ts2epg.writeEpgXML(tmppath + bctype + "epgdata.xml", chdb.searchCHFromBctype(bctype)['ch'])
42 xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.xml", bctype)
43 shutil.copyfile(tmppath + bctype + "epgdata.xml", tmppath + bctype + "epgdata.bak.xml")
45 rec10d.rec10db.update_by_bctype_epg_ch(bctype)
46 except Exception, inst:
47 recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200)
48 xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype)
49 rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "2")
50 def updateLogo_bc(bctype):
51 bctypel = chdb.searchCHFromBctype(bctype)
54 ts2epg.writeLogoEpgXML(tmppath + bctype + "logo.xml", chdb.searchCHFromBctype(bctype)['ch'])
55 xml2db_dom.xml2db_dom_logo(tmppath + bctype + "logo.xml", bctype)
56 shutil.copyfile(tmppath + bctype + "logo.xml", tmppath + bctype + "logo.bak.xml")
58 rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"1")
59 except Exception, inst:
60 recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200)
61 xml2db_dom.xml2db_dom(tmppath + bctype + "logo.bak.xml", bctype)
62 rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"2")
63 def searchTime(titletxt, timet, deltatime, chtxt):
64 time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
66 deltatime = int(deltatime)
67 beforetime = time.strftime("%Y%m%d%H%M%S")
68 beforetime = time - datetime.timedelta(hours=deltatime)
69 aftertime = time + datetime.timedelta(hours=deltatime)
70 beforetime = beforetime.strftime("%Y%m%d%H%M%S")
71 aftertime = aftertime.strftime("%Y%m%d%H%M%S")
72 one = ["", "", "", "","","",""]
74 chtxtt=chtxt.replace("_0","_%")
75 d = rec10d.rec10db.select_by_time_ngram_epg_timeline(beforetime, aftertime, chtxtt)
76 for chtxtt, title, start, stop ,exp,longexp,category in d:
77 #recdblist.printutf8(chtxtt+":"+title+":"+start+":"+stop)
78 p = n_gram.bigram(titletxt, title)
80 btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"
82 etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"
83 bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
86 dt = 24 * 60 * 60 * dt.days + dt.seconds + 1
88 dt = 1000-1000 * dt / (7 * 24 * 60 * 60)
92 one = [chtxtt, title, btime, etime,exp,longexp,category]
95 #recdblist.printutf8(title + ":" + str(p) + u"点")
100 def searchTimeAuto(keytxt, timet, deltatime):
101 time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")
103 deltatime = int(deltatime)
104 beforetime = time.strftime("%Y%m%d%H%M%S")
105 aftertime = time + datetime.timedelta(hours=deltatime)
106 aftertime = aftertime.strftime("%Y%m%d%H%M%S")
107 d = rec10d.rec10db.select_by_time_keyword_auto_suggest_epg_timeline(keytxt,beforetime, aftertime)
108 for chtxtt, title, start, stop ,exp,longexp,category in d:
110 btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"
112 etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"
113 ret.append([chtxtt, title, btime, etime,exp,longexp,category])
115 def countSchedule(btime,etime):
117 return rec num (int return[0]:TE /int return[1]:BS/CS)
128 dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime)
130 btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
131 etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
133 dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S")
134 dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S")
141 times = list(set(times))
145 for i in xrange(0, len(times)-2, 1):
148 btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
149 etime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
150 ret1 = rec10d.rec10db.count_schedule_timeline(btime1, etime1)
151 if retcount[0] < ret1[0]:
152 retcount[0] = ret1[0]
153 if retcount[1] < ret1[1]:
154 retcount[1] = ret1[1]
157 def searchSchedule(btime,etime):
159 return rec num (int return[0]:TE /int return[1]:BS/CS)
170 dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime)
172 btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
173 etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
175 dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S")
176 dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S")
183 times = list(set(times))
187 for i in xrange(0, len(times)-2, 1):
190 btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
191 etime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
192 ret1 = rec10d.rec10db.search_schedule_timeline(btime1, etime1)
197 def countEpgSchedule(epgbtime,epgetime):
199 return rec num (int return[0]:TE /int return[1]:BS/CS)
210 dls = rec10d.rec10db.select_byepgtime_over_timeline(epgbtime, epgetime)
213 btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S")
214 etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S")
216 dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S")
217 dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S")
224 times = list(set(times))
228 for i in xrange(0, len(times)-1, 1):
231 epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
232 epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
233 ret1 = rec10d.rec10db.count_epgschedule_timeline(epgbtime1, epgetime1)
234 if retcount[0] < ret1[0]:
235 retcount[0] = ret1[0]
236 if retcount[1] < ret1[1]:
237 retcount[1] = ret1[1]
239 def searchEpgSchedule(epgbtime,epgetime):
241 return rec num (int return[0]:TE /int return[1]:BS/CS)
252 dls = rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime)
254 btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S")
255 etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S")
257 dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S")
258 dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S")
265 times = list(set(times))
269 for i in xrange(0, len(times)-2, 1):
272 epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")
273 epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S")
274 ret1 = rec10d.rec10db.search_epgschedule_timeline(epgbtime1, epgetime1)