OSDN Git Service

add logo search.
authorgn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Fri, 18 Feb 2011 00:18:40 +0000 (00:18 +0000)
committergn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Fri, 18 Feb 2011 00:18:40 +0000 (00:18 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@839 4e526526-5e11-4fc0-8910-f8fd03428081

rec10/trunk/src/chdata.py
rec10/trunk/src/chdb.py
rec10/trunk/src/dbMySQL.py
rec10/trunk/src/epgdb.py
rec10/trunk/src/scan_ch.py
rec10/trunk/src/timerec.py
rec10/trunk/src/ts2epg.py

index 6f2ceb4..861719b 100644 (file)
@@ -6,13 +6,15 @@ import os.path
 import configreader\r
 import xml.dom.minidom\r
 import scan_ch\r
+import datetime\r
 \r
 import rec10d\r
 \r
 path = str(os.path.dirname(os.path.abspath(__file__))) + "/"\r
 \r
 def chAdd(bctype, chtxt, ch, csch):#すべて文字列\r
-    rec10d.rec10db.add_epg_ch(bctype,chtxt, ch, csch, u"2010-01-01 00:00:00")\r
+    tnow=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")\r
+    rec10d.rec10db.add_epg_ch(bctype,chtxt, ch, csch, u"2010-01-01 00:00:00",u"2010-01-01 00:00:00",tnow)\r
 def addCHlist(cl):\r
     if len(cl)>0:\r
         for c in cl:\r
index e542ff8..bfea9a4 100644 (file)
@@ -59,7 +59,6 @@ def update():
     CSupdate = 0
     CS2update = 0
     BSupdate = 0
-    HUupdate = 0
     rec10d.rec10db.set_new_status("8")
     for datum in rec10d.rec10db.select_get_update_epg_ch("6"):
         bctype = datum[0]
@@ -79,4 +78,15 @@ def update():
             ret.append(bctype)
     return ret
 def changeCHShow(chtxt,isshow):
-    rec10d.rec10db.change_visible_epg_ch(chtxt, isshow)
\ No newline at end of file
+    rec10d.rec10db.change_visible_epg_ch(chtxt, isshow)
+def updateLogo():
+    ret=[]
+    BSCSUpdate=0
+    for datum in rec10d.rec10db.select_get_updatelogo_epg_ch("720"):
+        bctype=datus[0]
+        if bctype == "cs1" or bctype == u"cs1":
+            ret.append(u"bs")
+            BSCSUpdate=1
+        else:
+            ret.append(bctype)
+    return ret
index 1dab3ea..de26606 100644 (file)
@@ -101,19 +101,22 @@ class DB_MySQL:
             logo2 BLOB,\
             logo3 BLOB,\
             logo4 BLOB,\
-            logo5 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.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, updatetime,logoupdate,scanupdate):
         db = self.connect_db()
         db[1].execute('\
-        INSERT INTO epg_ch (bctype,chtxt,ch,csch,chname,updatetime,status,visible)\
-        VALUES (%s,%s,%s,%s,"",%s,%s,%s)', \
-                      (bctype, chtxt, ch, csch, updatetime, "1","1"))
+        INSERT INTO epg_ch (bctype,chtxt,ch,csch,chname,updatetime,status,visible,logoupdate,scanupdate)\
+        VALUES (%s,%s,%s,%s,"",%s,%s,%s,%s,%s)', \
+                      (bctype, chtxt, ch, csch, updatetime, "1","1",logoupdate,scanupdate))
         self.close_db(db)
     def delete_all_epg_ch(self):
         db = self.connect_db()
@@ -123,7 +126,7 @@ class DB_MySQL:
     def select_by_chtxt_epg_ch(self, chtxt):
         db = self.connect_db()
         dbexe = db[1].execute("\
-        SELECT bctype,chtxt,ch,csch,updatetime,chname,status,visible \
+        SELECT bctype,chtxt,ch,csch,updatetime,chname,status,visible,logoupdate,scanupdate \
         FROM epg_ch \
         WHERE chtxt LIKE %s", \
                               (chtxt,))
@@ -135,12 +138,14 @@ class DB_MySQL:
         for dl in dls:
             r = list(dl)
             r[4] = r[4].strftime("%Y-%m-%d %H:%M:%S")
+            r[8] = r[8].strftime("%Y-%m-%d %H:%M:%S")
+            r[9] = r[9].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,chname,status,visible \
+        SELECT bctype,chtxt,ch,csch,updatetime,status,chname,status,visible,logoupdate,scanupdate \
         FROM epg_ch \
         WHERE bctype = %s", \
                               (bctype,))
@@ -153,6 +158,8 @@ class DB_MySQL:
             #recdblist.printutf8(dl)
             r = list(dl)
             r[4] = r[4].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")
             r[5] = str(r[5])
             ret.append(r)
         return ret
@@ -160,7 +167,7 @@ class DB_MySQL:
         db = self.connect_db()
         dbexe = db[1].execute("\
         SELECT \
-        bctype,chtxt,ch,csch,updatetime,chname,status,visible \
+        bctype,chtxt,ch,csch,updatetime,chname,status,visible,logoupdate,scanupdate \
         FROM epg_ch \
         WHERE ch = %s", \
                               (ch,))
@@ -172,13 +179,15 @@ class DB_MySQL:
         for dl in dls:
             r = list(dl)
             r[4] = r[4].strftime("%Y-%m-%d %H:%M:%S")
+            r[8] = r[8].strftime("%Y-%m-%d %H:%M:%S")
+            r[9] = r[9].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,updatetime,chname,status,visible \
+        bctype,chtxt,ch,csch,updatetime,chname,status,visible,logoupdate,scanupdate \
         FROM epg_ch \
         WHERE csch = %s", \
                               (csch,))
@@ -190,12 +199,14 @@ class DB_MySQL:
         for dl in dls:
             r = list(dl)
             r[4] = r[4].strftime("%Y-%m-%d %H:%M:%S")
+            r[8] = r[8].strftime("%Y-%m-%d %H:%M:%S")
+            r[9] = r[9].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,chname,status,visible \
+        SELECT bctype,chtxt,ch,csch,updatetime,chname,status,visible,logoupdate,scanupdate \
         FROM epg_ch \
         ")
         ret = []
@@ -206,6 +217,8 @@ class DB_MySQL:
         for dl in dls:
             r = list(dl)
             r[4] = r[4].strftime("%Y-%m-%d %H:%M:%S")
+            r[8] = r[8].strftime("%Y-%m-%d %H:%M:%S")
+            r[9] = r[9].strftime("%Y-%m-%d %H:%M:%S")
             ret.append(r)
         return ret
     def change_visible_epg_ch(self,chtxt,visible):
@@ -247,6 +260,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("\
@@ -256,6 +287,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("\
@@ -276,14 +308,26 @@ class DB_MySQL:
                       (status, bctype)\
                       )
         self.close_db(db)
-    def update_chname_by_chtxt_epg_ch(self,chtxt,chname):
+    def update_status_by_bctype_epg_ch(self, bctype, status):
         db = self.connect_db()
         db[1].execute("\
         UPDATE epg_ch \
         SET \
-        chname=%s \
-        WHERE chtxt = %s", \
-                      (chname, chtxt)\
+        status=%s , \
+        updatetime=now() \
+        WHERE bctype = %s", \
+                      (status, bctype)\
+                      )
+        self.close_db(db)
+    def update_logostatus_by_bctype_epg_ch(self,bctype,logostatus):
+        db = self.connect_db()
+        db[1].execute("\
+        UPDATE epg_ch \
+        SET \
+        logostatus=%s , \
+        logoupdate=now() \
+        WHERE bctype = %s", \
+                      (logostatus, bctype)\
                       )
         self.close_db(db)
     def add_auto_proc_tmp(self,type,title,chtxt):
index 7269ef9..34f1865 100644 (file)
@@ -45,6 +45,19 @@ def updatebc(bctype):
         recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200)\r
         xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype)\r
         rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "2")\r
+def updateLogo_bc(bctype):\r
+    bctypel = chdb.searchCHFromBctype(bctype)\r
+    #print bctype\r
+    try:\r
+        ts2epg.writeLogoEpgXML(tmppath + bctype + "logo.xml", chdb.searchCHFromBctype(bctype)['ch'])\r
+        xml2db_dom.xml2db_dom_logo(tmppath + bctype + "logo.xml", bctype)\r
+        shutil.copyfile(tmppath + bctype + "logo.xml", tmppath + bctype + "logo.bak.xml")\r
+        time.sleep(5)\r
+        rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"1")\r
+    except Exception, inst:\r
+        recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200)\r
+        xml2db_dom.xml2db_dom(tmppath + bctype + "logo.bak.xml", bctype)\r
+        rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"2")\r
 def searchTime(titletxt, timet, deltatime, chtxt):\r
     time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")\r
     ret = []\r
index 9f0be2e..1a6e751 100644 (file)
@@ -7,6 +7,7 @@ import os.path
 import time
 import commands
 import traceback
+import datetime
 
 import chdb
 import rec10d
@@ -84,9 +85,11 @@ def addCh(ch,bctype,chtxthead):
         try:
             if ch.find("bs")>-1:
                 if int(lstr)<300:
-                    rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr, u"2010-01-01 00:00:00")
+                    tnow=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+                    rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr, u"2010-01-01 00:00:00", u"2010-01-01 00:00:00",tnow)
             else:
-                rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr, u"2010-01-01 00:00:00")
+                tnow=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+                rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr, u"2010-01-01 00:00:00", u"2010-01-01 00:00:00",tnow)
         except Exception, inst:
             recdblist.addCommonlogEX("Warning", "addCh (scan_ch.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
     checkB25Purchased(ch, prglist[1])
index 3b95962..a821e60 100644 (file)
@@ -74,6 +74,7 @@ def task():
             auto_process.killDeadEncode(recpath)
             sys.exit()
     update = chdb.update()
+    updatelogo = chdb.updateLogo()
     if len(update) > 0:
         pid = os.fork()
         if pid != 0:
@@ -101,6 +102,32 @@ def task():
             time.sleep(5)
             auto_process.update_all_timeline_epg()
             sys.exit()
+    elif len(updatelogo)>0:
+        pid = os.fork()
+        if pid != 0:
+            ""
+        else:
+            i = 0
+            for bctype in updatelogo:
+                recnum = 0
+                if bctype.find('te') > -1:
+                    recnum = status.getTERecording() + recdb.countRecNow_minutes_TE("1200")
+                    recdblist.printutf8(u"ロゴ取得 : 放送種別-"+bctype + u"||該当チューナー実行中件数:" + str(status.getTERecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_TE("10")),verbose_level=800)
+                    recnum = int(configreader.getConfEnv("te_max")) -recnum
+                else:
+                    recnum = status.getBSCSRecording() + recdb.countRecNow_minutes_BSCS("1200")
+                    recdblist.printutf8(u"ロゴ取得 : 放送種別-"+bctype + u"||該当チューナー実行中件数:" + str(status.getBSCSRecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_BSCS("10")),verbose_level=800)
+                    recnum = int(configreader.getConfEnv("bscs_max")) -recnum
+                if recnum >0 :
+                    recdblist.printutf8(str(updatelogo),verbose_level=750)
+                    rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"0")
+                    epgdb.updateLogo_bc(bctype)
+                    updatelogo = chdb.updateLogo()
+                    i = i + 1
+                if i > 0:
+                    break
+            time.sleep(5)
+            sys.exit()
     else:
         pid = os.fork()
         if pid != 0:
index 65e7f1e..5f6a73d 100644 (file)
@@ -23,7 +23,13 @@ def writeEpgXML(pout, ch):
     elif len(ch)>2:\r
         timet = "240"\r
     writeEpgXMLTime(pout, ch ,timet)\r
-def writeEpgXMLTime(pout, ch ,times):\r
+def writeLogoEpgXML(pout, ch):\r
+    """\r
+    tsを取得してepgの入ったxmlとして書き出す\r
+    """\r
+    timet = "1200"\r
+    writeEpgXMLTime(pout, ch ,timet,islogo=1)\r
+def writeEpgXMLTime(pout, ch ,times,islogo=0):\r
     """\r
     指定された時間分tsを取得してepgの入ったxmlとして書き出す\r
     """\r
@@ -39,8 +45,11 @@ def writeEpgXMLTime(pout, ch ,times):
     if os.access(pout + ".ts", os.F_OK):\r
         os.remove(pout + ".ts")\r
     time.sleep(10)\r
-    tv2ts.tv2tsmix(pout + ".ts", ch, timet)\r
-    exe = "export LANG=ja_JP.UTF-8 && nice -n 15 " + epgdump + " " + mode + " " + pout + ".ts " + pout\r
+    tv2ts.tv2b25ts(pout+ ".ts", ch, time)\r
+    logoopt=""\r
+    if islogo==1:\r
+        logoopt="/LOGO "\r
+    exe = "export LANG=ja_JP.UTF-8 && nice -n 15 " + epgdump + " " +logoopt+ mode + " " + pout + ".ts " + pout\r
     recdblist.printutf8(exe)\r
     recdblist.addCommonlogEX(u"通常", "write_time(ts2epg.py)", exe,"",log_level=500)\r
     unicode(commands.getoutput(exe),'utf-8','ignore')\r