OSDN Git Service

add tsid channel information for complete BS support.
[rec10/rec10-git.git] / rec10 / trunk / src / dbMySQL.py
index 48d240e..cce2e86 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # coding: UTF-8
 # Rec10 TS Recording Tools
-# Copyright (C) 2009-2010 Yukikaze
+# Copyright (C) 2009-2012 Yukikaze
 import MySQLdb
 import recdblist
 import warnings
@@ -24,12 +24,12 @@ class DB_MySQL:
         try:
             con = MySQLdb.connect(user=user, passwd=passwd)
             cur = con.cursor()
-            cur.execute('CREATE DATABASE ' + dbname + " DEFAULT CHARACTER SET utf8")
+            cur.execute('CREATE DATABASE ' + dbname + " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;")
             cur.close()
             con.close()
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "init (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "init (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
         db = self.connect_db()
         try:
             db[1].execute('\
@@ -50,12 +50,13 @@ class DB_MySQL:
             epgduplicate TINYINT DEFAULT 0,\
             epgchange TINYINT DEFAULT 0,\
             epgexp VARCHAR(200),\
+            epgcategory VARCHAR(100),\
             counter TINYINT DEFAULT -1,\
             UNIQUE uni (type,chtxt,title,btime,deltaday)\
             )')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "init (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "init (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
         self.close_db(db)
         self.new_epg_timeline("")
         self.new_in_timeline_log()
@@ -71,6 +72,10 @@ class DB_MySQL:
         """
         con = MySQLdb.connect(db=self.dbname, host=self.dbhost, port=self.dbport, user=self.dbusr, passwd=self.dbpasswd, charset="utf8")
         cur = con.cursor()
+        try:
+            con.autocommit(1)
+        except:
+            ""
         cur.execute('set names utf8;')
         return [con, cur]
     def close_db(self, db):
@@ -82,7 +87,7 @@ class DB_MySQL:
             db[1].execute('drop table epg_ch')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and (inst[0]==1050 or inst[0]==1051))):
-                recdblist.Commonlogex("Error", "new_epg_ch drop (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_epg_ch drop (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
 
         try:
             db[1].execute('\
@@ -92,27 +97,42 @@ class DB_MySQL:
             chtxt VARCHAR(20) PRIMARY KEY,\
             ch VARCHAR(20),\
             csch VARCHAR(20),\
+            tsid VARCHAR(20),\
             chname VARCHAR(100),\
             updatetime DATETIME,\
             status TINYINT,\
-            isshow TINYINT\
+            visible TINYINT DEFAULT 1,\
+            logo0 BLOB,\
+            logo1 BLOB,\
+            logo2 BLOB,\
+            logo3 BLOB,\
+            logo4 BLOB,\
+            logo5 BLOB,\
+            logoupdate DATETIME,\
+            logostatus TINYINT DEFAULT 2,\
+            scanupdate DATETIME\
             )')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "new_epg_ch (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_epg_ch (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
 
         self.close_db(db)
-    def add_epg_ch(self, bctype, chtxt, ch, csch, updatetime):
+    def add_epg_ch(self, bctype, chtxt, ch, csch,tsid,updatetime,logoupdate,scanupdate):
         db = self.connect_db()
         db[1].execute('\
-        INSERT INTO epg_ch \
-        VALUES (%s,%s,%s,%s,"",%s,%s,%s)', \
-                      (bctype, chtxt, ch, csch, updatetime, "1","1"))
+        INSERT INTO epg_ch (bctype,chtxt,ch,csch,tsid,chname,updatetime,status,visible,logoupdate,scanupdate)\
+        VALUES (%s,%s,%s,%s,%s,"",%s,%s,%s,%s,%s)', \
+                      (bctype, chtxt, ch, csch,tsid,updatetime, "1","1",logoupdate,scanupdate))
+        self.close_db(db)
+    def delete_all_epg_ch(self):
+        db = self.connect_db()
+        db[1].execute('\
+        DROP TABLE epg_ch ')
         self.close_db(db)
     def select_by_chtxt_epg_ch(self, chtxt):
         db = self.connect_db()
         dbexe = db[1].execute("\
-        SELECT bctype,chtxt,ch,csch,updatetime \
+        SELECT bctype,chtxt,ch,csch,tsid,updatetime,chname,status,visible,logoupdate,scanupdate \
         FROM epg_ch \
         WHERE chtxt LIKE %s", \
                               (chtxt,))
@@ -123,13 +143,18 @@ class DB_MySQL:
         self.close_db(db)
         for dl in dls:
             r = list(dl)
-            r[4] = r[4].strftime("%Y-%m-%d %H:%M:%S")
+            r[5] = r[5].strftime("%Y-%m-%d %H:%M:%S")
+            if r[9]!=None:
+                r[9] = r[9].strftime("%Y-%m-%d %H:%M:%S")
+            else:
+                r[9]="2012-04-01 00:00:00"
+            r[10] = r[10].strftime("%Y-%m-%d %H:%M:%S")
             ret.append(r)
         return ret
     def select_by_bctype_epg_ch(self, bctype):
         db = self.connect_db()
         dbexe = db[1].execute("\
-        SELECT bctype,chtxt,ch,csch,updatetime,status \
+        SELECT bctype,chtxt,ch,csch,tsid,updatetime,status,chname,status,visible,logoupdate,scanupdate \
         FROM epg_ch \
         WHERE bctype = %s", \
                               (bctype,))
@@ -141,15 +166,22 @@ class DB_MySQL:
         for dl in dls:
             #recdblist.printutf8(dl)
             r = list(dl)
-            r[4] = r[4].strftime("%Y-%m-%d %H:%M:%S")
-            r[5] = str(r[5])
+            r[5] = r[5].strftime("%Y-%m-%d %H:%M:%S")
+            if r[10]!=None:
+                r[10] = r[10].strftime("%Y-%m-%d %H:%M:%S")
+            else:
+                r[10]="2011-04-01 00:00:00"
+            r[11] = r[11].strftime("%Y-%m-%d %H:%M:%S")
+            r[6] = str(r[6])
             ret.append(r)
+        import random
+        ret.insert(0,ret[random.randint(0,len(ret)-1)])
         return ret
     def select_by_ch_epg_ch(self, ch):
         db = self.connect_db()
         dbexe = db[1].execute("\
         SELECT \
-        bctype,chtxt,ch,csch,updatetime \
+        bctype,chtxt,ch,csch,tsid,updatetime,chname,status,visible,logoupdate,scanupdate \
         FROM epg_ch \
         WHERE ch = %s", \
                               (ch,))
@@ -160,13 +192,35 @@ class DB_MySQL:
         self.close_db(db)
         for dl in dls:
             r = list(dl)
-            r[4] = r[4].strftime("%Y-%m-%d %H:%M:%S")
+            r[5] = r[5].strftime("%Y-%m-%d %H:%M:%S")
+            r[9] = r[9].strftime("%Y-%m-%d %H:%M:%S")
+            r[10] = r[10].strftime("%Y-%m-%d %H:%M:%S")
+            ret.append(r)
+        return ret
+    def select_by_csch_epg_ch(self, csch):
+        db = self.connect_db()
+        dbexe = db[1].execute("\
+        SELECT \
+        bctype,chtxt,ch,csch,tsid,updatetime,chname,status,visible,logoupdate,scanupdate \
+        FROM epg_ch \
+        WHERE csch = %s", \
+                              (csch,))
+        ret = []
+        dls = []
+        if dbexe > 0:
+            dls = db[1].fetchall()
+        self.close_db(db)
+        for dl in dls:
+            r = list(dl)
+            r[5] = r[5].strftime("%Y-%m-%d %H:%M:%S")
+            r[9] = r[9].strftime("%Y-%m-%d %H:%M:%S")
+            r[10] = r[10].strftime("%Y-%m-%d %H:%M:%S")
             ret.append(r)
         return ret
     def select_all_epg_ch(self):
         db = self.connect_db()
         dbexe = db[1].execute("\
-        SELECT bctype,chtxt,ch,csch,updatetime \
+        SELECT bctype,chtxt,ch,csch,tsid,updatetime,chname,status,visible,logoupdate,scanupdate \
         FROM epg_ch \
         ")
         ret = []
@@ -176,9 +230,21 @@ class DB_MySQL:
         self.close_db(db)
         for dl in dls:
             r = list(dl)
-            r[4] = r[4].strftime("%Y-%m-%d %H:%M:%S")
+            r[5] = r[5].strftime("%Y-%m-%d %H:%M:%S")
+            r[9] = r[9].strftime("%Y-%m-%d %H:%M:%S")
+            r[10] = r[10].strftime("%Y-%m-%d %H:%M:%S")
             ret.append(r)
         return ret
+    def change_visible_epg_ch(self,chtxt,visible):
+        db = self.connect_db()
+        db[1].execute("\
+        UPDATE epg_ch SET visible=%s WHERE chtxt=%s",(visible,chtxt))
+        self.close_db(db)
+    def change_logodata_epg_ch(self,chtxt,logonum,logodata):
+        db = self.connect_db()
+        db[1].execute("\
+        UPDATE epg_ch SET logo"+str(logonum)+"=%s WHERE chtxt=%s",(logodata,chtxt))
+        self.close_db(db)
     def set_new_status(self,dhour):
         db = self.connect_db()
         dbexe = db[1].execute("UPDATE epg_ch \
@@ -208,6 +274,24 @@ class DB_MySQL:
             ret = db[1].fetchall()
         self.close_db(db)
         return ret
+    def select_get_updatelogo_epg_ch(self, dhour):
+        db = self.connect_db()
+        dbexe = db[1].execute("SELECT bctype,chtxt,logostatus FROM epg_ch \
+        WHERE (\
+        ( \
+        updatetime < DATE_SUB(now(),INTERVAL " + dhour + " HOUR) \
+        AND \
+        logostatus = 1 \
+        ) \
+        OR \
+        logostatus > 1 )\
+        ORDER BY status DESC")
+        ret = []
+        #recdblist.printutf8(dbexe)
+        if dbexe > 0:
+            ret = db[1].fetchall()
+        self.close_db(db)
+        return ret
     def update_by_bctype_epg_ch(self, bctype):
         db = self.connect_db()
         db[1].execute("\
@@ -217,6 +301,7 @@ class DB_MySQL:
         status = 1 \
         WHERE bctype = %s", (bctype,))
         self.close_db(db)
+
     def update_by_bctype_and_chtxt_epg_ch(self, bctype, chtxt):
         db = self.connect_db()
         db[1].execute("\
@@ -226,6 +311,14 @@ class DB_MySQL:
         status = 1\
         WHERE bctype = %s AND chtxt = %s", (bctype, chtxt))
         self.close_db(db)
+    def update_chname_by_chtxt_epg_ch(self,chtxt,chname):
+        db = self.connect_db()
+        db[1].execute("\
+        UPDATE epg_ch \
+        SET \
+        chname = %s \
+        WHERE chtxt = %s", (chname,chtxt))
+        self.close_db(db)
     def update_status_by_bctype_epg_ch(self, bctype, status):
         db = self.connect_db()
         db[1].execute("\
@@ -237,14 +330,15 @@ class DB_MySQL:
                       (status, bctype)\
                       )
         self.close_db(db)
-    def update_chname_by_chtxt_epg_ch(self,chtxt,chname):
+    def update_logostatus_by_bctype_epg_ch(self,bctype,logostatus):
         db = self.connect_db()
         db[1].execute("\
         UPDATE epg_ch \
         SET \
-        chname=%s \
-        WHERE chtxt = %s", \
-                      (chname, chtxt)\
+        logostatus=%s , \
+        logoupdate=now() \
+        WHERE bctype = %s", \
+                      (logostatus, bctype)\
                       )
         self.close_db(db)
     def add_auto_proc_tmp(self,type,title,chtxt):
@@ -261,7 +355,7 @@ class DB_MySQL:
             db[1].execute('drop table auto_proc_tmp')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and (inst[0]==1050 or inst[0]==1051))):
-                recdblist.Commonlogex("Error", "new_auto_proc_tmp drop (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_auto_proc_tmp drop (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
 
         try:
             db[1].execute('\
@@ -274,7 +368,7 @@ class DB_MySQL:
             )')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "new_auto_proc_tmp (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_auto_proc_tmp (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
 
         self.close_db(db)
     def update_auto_proc(self):
@@ -283,7 +377,7 @@ class DB_MySQL:
             db[1].execute('INSERT INTO auto_proc SELECT * FROM auto_proc_tmp')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "update_auto_proc (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "update_auto_proc (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
 
         self.close_db(db)
     def new_auto_proc(self):
@@ -292,7 +386,7 @@ class DB_MySQL:
             db[1].execute('drop table auto_proc')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and (inst[0]==1050 or inst[0]==1051))):
-                recdblist.Commonlogex("Error", "new_auto_proc drop (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_auto_proc drop (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
 
         try:
             db[1].execute('\
@@ -305,7 +399,7 @@ class DB_MySQL:
             )')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "new_auto_proc (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_auto_proc (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
 
         self.close_db(db)
     def add_auto_proc(self,type,title,chtxt):
@@ -322,7 +416,7 @@ class DB_MySQL:
             db[1].execute('drop table in_settings')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and (inst[0]==1050 or inst[0]==1051))):
-                recdblist.Commonlogex("Error", "drop_in_settings (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "drop_in_settings (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
         self.close_db(db)
     def new_in_settings(self):
         db = self.connect_db()
@@ -338,7 +432,7 @@ class DB_MySQL:
             db[1].execute("INSERT IGNORE into in_settings VALUE (0,0,\"H\",1)")
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "new_in_settings (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_in_settings (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
 
         self.close_db(db)
     def select_all_in_settings(self):
@@ -399,7 +493,7 @@ class DB_MySQL:
             )')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "new_in_timeline_log (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_in_timeline_log (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
 
         self.close_db(db)
     def select_chtxt_by_title_timeline_log(self,title):
@@ -426,13 +520,13 @@ class DB_MySQL:
                       (type, chtxt, title, btime, etime, deltatime, deltaday, opt ,counter))
         ##db.commit()
         self.close_db(db)
-    def update_epg_timeline(self,type,chtxt,title,btime,epgbtime,epgetime,epgtitle,epgexp):
+    def update_epg_timeline(self,type,chtxt,title,btime,epgbtime,epgetime,epgtitle,epgexp,epgcategory):
         db = self.connect_db()
         db[1].execute('\
         UPDATE timeline \
-        SET epgbtime=%s,epgetime=%s,epgtitle=%s,epgexp=%s \
+        SET epgbtime=%s,epgetime=%s,epgtitle=%s,epgexp=%s,epgcategory=%s \
         WHERE type=%s AND chtxt=%s AND title=%s AND btime=%s ', \
-                      (epgbtime,epgetime,epgtitle,epgexp,type, chtxt, title, btime))
+                      (epgbtime,epgetime,epgtitle,epgexp,epgcategory,type, chtxt, title, btime))
         ##db.commit()
         self.close_db(db)
     def update_status_change_timeline(self,type,chtxt,title,btime,epgchange):
@@ -512,8 +606,8 @@ class DB_MySQL:
         dbr = db[1].execute("SELECT \
         type, chtxt, title, btime, etime, deltatime ,deltaday ,opt ,epgbtime ,epgetime ,epgtitle ,epgduplicate ,epgchange ,counter\
         FROM timeline \
-        WHERE btime > %s AND \
-        etime < %s",(btime,etime))
+        WHERE btime >= %s AND \
+        etime <= %s",(btime,etime))
         dbl = db[1].fetchall()
         self.close_db(db)
         #recdblist.printutf8(dbl)
@@ -700,7 +794,7 @@ class DB_MySQL:
             )")
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "new_in_auto_jbk_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_in_auto_jbk_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
         self.close_db(db)
     def add_in_auto_jbk_key(self,key):
         db = self.connect_db()
@@ -716,7 +810,7 @@ class DB_MySQL:
         dbexe = db[1].execute("\
         SELECT keyword,auto,opt \
         FROM in_auto_jbk_key \
-        ")
+vim         ")
         ret = []
         if dbexe > 0:
             ret = db[1].fetchall()
@@ -728,7 +822,7 @@ class DB_MySQL:
             db[1].execute('drop table in_status')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and (inst[0]==1050 or inst[0]==1051))):
-                recdblist.Commonlogex("Error", "drop_in_status (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "drop_in_status (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
         self.close_db(db)
     def new_in_status(self):
         db = self.connect_db()
@@ -746,7 +840,7 @@ class DB_MySQL:
             db[1].execute("INSERT IGNORE into in_status VALUE (0,0,0,0,0,0)")
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "new_in_status (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_in_status (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
         self.close_db(db)
     def select_all_in_status(self):
         db = self.connect_db()
@@ -783,7 +877,7 @@ class DB_MySQL:
                 version=int(str(r[0]))
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "select_version_in_status (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "select_version_in_status (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
         return version
     def change_version_in_status(self,version):
         db = self.connect_db()
@@ -841,21 +935,21 @@ class DB_MySQL:
             r = list(dl)
             ret=r[4]
         return ret
-    def change_installed_in_status(self):
+    def change_chscaned_in_status(self):
         """
         installedを設定する
         """
         db = self.connect_db()
         db[1].execute("\
-        UPDATE in_status SET installed=1")
+        UPDATE in_status SET installed=2")
         self.close_db(db)
-    def change_chscaned_in_status(self):
+    def change_installed_in_status(self,num=1):
         """
         installedを設定する
         """
         db = self.connect_db()
         db[1].execute("\
-        UPDATE in_status SET installed=2")
+        UPDATE in_status SET installed=%s",(num,))
         self.close_db(db)
     def new_epg_timeline(self, bctype):
         db = self.connect_db()
@@ -866,7 +960,7 @@ class DB_MySQL:
                           (bctype,))
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and (inst[0]==1007 or inst[0]==1146))or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "new_epg_timeline delete (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_epg_timeline delete (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
         try:
             db[1].execute("\
             CREATE TABLE epg_timeline \
@@ -883,7 +977,7 @@ class DB_MySQL:
             )")
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "new_epg_timeline (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_epg_timeline (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
         #db.commit()
         self.close_db(db)
     def add_epg_timeline(self, bctype, channel, start, stop, title, desc,longdesc, category):
@@ -909,17 +1003,13 @@ class DB_MySQL:
         db = self.connect_db()
         dbexe = "\
         SELECT \
-        epg_ch.chtxt,title,start,stop,exp,longexp,category \
+        channel,title,start,stop,exp,longexp,category \
         FROM epg_timeline \
-        INNER JOIN epg_ch \
-        WHERE epg_ch.chtxt LIKE epg_timeline.channel \
-        AND \
-        start >= %s \
+        WHERE start >= %s \
         AND \
         start <= %s \
         AND \
-        epg_ch.chtxt LIKE %s"
-        print dbexe
+        channel LIKE %s"
         dbcmd = db[1].execute(dbexe, (btime, etime, chtxt))
         retall = []
         if dbcmd > 0:
@@ -935,6 +1025,8 @@ class DB_MySQL:
         INNER JOIN epg_ch \
         WHERE epg_ch.chtxt=epg_timeline.channel \
         AND \
+        epg_ch.visible=1 \
+        AND \
         start >= %s \
         AND \
         stop <= %s \
@@ -966,7 +1058,7 @@ class DB_MySQL:
             db[1].execute('CREATE INDEX keycharindex ON in_auto_bayes_key(keychar)')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "new_in_auto_bayes_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_in_auto_bayes_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
         self.close_db(db)
 
     def add_in_auto_bayes_key(self,key,chtxt,ratio_rec,ratio_all):
@@ -1028,7 +1120,7 @@ class DB_MySQL:
                 ratio_all=CONVERT((ratio_all*%s+%s)/%s,DECIMAL(32,14))",retl)
             except Exception, inst:
                 if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                    recdblist.Commonlogex("Error", "change_multi_ratio_all_in_auto_bayes_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                    recdblist.addCommonlogEX("Error", "change_multi_ratio_all_in_auto_bayes_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
         self.close_db(db)
     def change_ratio_rec_reduce_in_auto_bayes_key(self,chtxt,beforenum,newnum):
         beforenum=str(beforenum)
@@ -1060,7 +1152,7 @@ class DB_MySQL:
                 ratio_rec=CONVERT((ratio_rec*%s+%s)/%s,DECIMAL(32,14))",retl)
             except Exception, inst:
                 if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                    recdblist.Commonlogex("Error", "change_multi_ratio_rec_in_auto_bayes_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                    recdblist.addCommonlogEX("Error", "change_multi_ratio_rec_in_auto_bayes_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
         self.close_db(db)
     def select_by_key_in_auto_bayes_key(self,key,chtxt):
         db = self.connect_db()
@@ -1092,7 +1184,7 @@ class DB_MySQL:
             )')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "new_auto_timeline_keyword (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_auto_timeline_keyword (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
     def add_auto_timeline_keyword(self,chtxt="", title="", btime="", etime=""):
         db = self.connect_db()
         db[1].execute('\
@@ -1125,7 +1217,7 @@ class DB_MySQL:
             )')
         except Exception, inst:
             if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
-                recdblist.Commonlogex("Error", "new_auto_timeline_bayes (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+                recdblist.addCommonlogEX("Error", "new_auto_timeline_bayes (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
     def add_auto_timeline_bayes(self,chtxt="", title="", btime="", etime="",point=""):
         db = self.connect_db()
         db[1].execute('\
@@ -1185,17 +1277,63 @@ class DB_MySQL:
         self.change_version_in_status("98")
     def update_db_98to100(self):
         ###ここで前のepg_chをバックアップしてchtxtの変換をする必要がある。
-        db = self.connect_db()
         self.drop_in_settings()
         self.new_in_settings()
+        db = self.connect_db()
         db[1].execute("\
-        UPDATE timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt SET timeline.chtxt=CONCAT(CONCAT(epg_ch.ch,'_'),epg_ch.csch)")
+        UPDATE timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt SET timeline.chtxt=CONCAT(CONCAT(epg_ch.ch,'_'),epg_ch.csch) WHERE NOT (substring(epg_ch.bctype,1,2) = 'bs' OR substring(epg_ch.bctype,1,2) = 'cs')")
         db[1].execute("\
-        ALTER TABLE epg_ch DROP ontv")
+        UPDATE timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt SET timeline.chtxt=CONCAT('BS_',epg_ch.ch) WHERE substring(epg_ch.bctype,1,2) = 'bs'")
+        db[1].execute("\
+        UPDATE timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt SET timeline.chtxt=CONCAT('CS_',epg_ch.csch) WHERE substring(epg_ch.bctype,1,2) = 'cs'")
+        try:
+            db[1].execute("\
+            ALTER TABLE epg_ch DROP ontv")
+        except:
+            ""
+        db[1].execute("\
+        ALTER TABLE epg_ch ADD logo0 BLOB,\
+        ADD logo1 BLOB,\
+        ADD logo2 BLOB,\
+        ADD logo3 BLOB,\
+        ADD logo4 BLOB,\
+        ADD logo5 BLOB\
+        ")
         db[1].execute("\
         ALTER TABLE in_auto_jbk_key ADD auto TINYINT DEFAULT 0")
         db[1].execute("\
         ALTER TABLE in_auto_jbk_key ADD opt VARCHAR(20) DEFAULT \"\"")
         self.close_db(db)
-        self.change_installed_in_status()#チャンネルスキャンをさせる
-        self.change_version_in_status("100")
\ No newline at end of file
+        self.change_installed_in_status(1)#チャンネルスキャンをさせる
+        self.change_version_in_status("100")
+    def update_db_100to101(self):
+        self.drop_in_settings()
+        self.new_in_settings()
+        self.new_epg_ch()
+        db = self.connect_db()
+        try:
+            db[1].execute("\
+            ALTER TABLE timeline ADD epgcategory VARCHAR(100)\
+            ")
+        except:
+            ""
+        self.close_db(db)
+        self.change_installed_in_status(1)
+        self.change_version_in_status("101")
+        #self.change_installed_in_status()#チャンネルスキャンをさせる
+    def update_db_101to102(sekf):
+        self.drop_in_settings()
+        self.new_in_settings()
+        self.new_epg_ch()
+        db = self.connect_db()
+        try:
+            db[1].execute("\
+            ALTER TABLE epg_ch ADD tsid VARCHAR(20)\
+            ")
+        except:
+            ""
+        self.close_db(db)
+        self.change_installed_in_status(1)
+        self.change_version_in_status("102")
+        #self.change_installed_in_status()#チャンネルスキャンをさせる
+