3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
7 path = str(os.path.dirname(os.path.abspath(__file__))) + "/"
8 dbpath = path + "ch.db"
11 def __init__(self, dbpath):
13 def connect_db(self, tout=10):
20 return sqlite3.connect(self.dbpath, timeout=tout)
21 def close_db(self, db):
23 def select_by_ontv_ch(self, ontv):
24 db = self.connect_db(120)
25 ret = db.execute("SELECT bctype,channel,display FROM ch WHERE channel= ? ", (ontv, ))
29 def select_all_rectime(self):
30 db = self.connect_db(120)
32 for id, typet, chtxt, title, btime, etime, deltatime, deltaday, opt in db.execute("SELECT id,type,chtxt,title,btime,etime,deltatime,deltaday,opt FROM rectime"):
37 ret['title'] = title.encode('utf-8')
48 ret['deltatime'] = deltatime
49 elif typet == 'keyevery':
50 ret['deltatime'] = deltatime
51 ret['deltaday'] = deltaday
55 def select_by_chtxt_rectime(self, chtxt):
56 db = self.connect_db(120)
58 for typet, chtxt, title, btime, etime, deltatime, deltaday, opt in db.execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime WHERE chtxt = ? ", (chtxt, )):
62 ret['title'] = title.encode('utf-8')
71 ret['deltatime'] = deltatime
72 elif typet == 'keyevery':
73 ret['deltatime'] = deltatime
74 ret['deltaday'] = deltaday
78 def select_by_id_rectime(self, id):
79 db = self.connect_db(120)
81 for typet, chtxt, title, btime, etime, deltatime, deltaday, opt in db.execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime WHERE id = ? ", (id, )):
85 ret['title'] = title.encode('utf-8')
94 ret['deltatime'] = deltatime
95 elif typet == 'keyevery':
96 ret['deltatime'] = deltatime
97 ret['deltaday'] = deltaday
101 def select_all_chdata(self):
102 db = self.connect_db(120)
103 ret = db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata")
107 def select_by_chtxt_chdata(self, chtxt):
108 db = self.connect_db(120)
109 ret = db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE chtxt=?", (chtxt, ))
113 def select_by_station_chdata(self, station):
114 db = self.connect_db(120)
115 ret = db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE station=?", (station, ))
119 def select_by_station_name_chdata(self, station_name):
120 db = self.connect_db(120)
121 ret = db.execute("SELECT bctype,ontv,chtxt,ch,csch,updatetime FROM chdata WHERE station_name=?", (station_name, ))
125 def add_rectime(self, type="", chtxt="", title="", btime="", etime="", deltatime="", deltaday="", opt=""):
126 db = self.connect_db(480)
127 db.execute('INSERT OR IGNORE INTO rectime (type,chtxt,title,btime,etime,deltatime,deltaday,opt) values (?,?,?,datetime(?),datetime(?),?,?,?)', (type, chtxt, title, btime, etime, deltatime, deltaday, opt))
130 def schedule_rectime(self, btime, etime):
131 db = self.connect_db(120)
132 dbexe = "SELECT type,chdata.bctype,rectime.chtxt,rectime.title,rectime.btime,rectime.etime FROM rectime INNER JOIN chdata ON rectime.chtxt=chdata.chtxt"
133 dbexe = dbexe + " WHERE NOT( ( rectime.etime <= ? ) OR ( rectime.btime >= ? ) )"
135 for typet, bctypet, chtxtt, titlet, btimet, etimet in db.execute(dbexe, (btime, etime)):
136 ret = [typet, bctypet, chtxtt, titlet, btimet, etimet]
140 def count_schedule_rectime(self, btime, etime):
143 return [te num,bs/cs num]
145 db = self.connect_db(120)
146 dbexe = "SELECT type,chdata.bctype,rectime.chtxt,rectime.title FROM rectime INNER JOIN chdata ON rectime.chtxt=chdata.chtxt"
147 dbexe = dbexe + " WHERE NOT( ( rectime.etime <= ? ) OR ( rectime.btime >= ? ) )"
150 for typet, bctypet, chtxtt, titlet in db.execute(dbexe, (btime, etime)):
151 if (typet == "rec") or (typet == "res") or (typet == "key") or (typet == "keyevery"):
152 if bctypet.find("cs") > -1:
154 elif bctypet.find("bs") > -1:
156 elif bctypet.find("te") > -1:
160 def del_by_id_rectime(self, id):
161 db = self.connect_db(120)
162 db.execute('DELETE FROM rectime WHERE id=' + id)