OSDN Git Service

add ch scan and installer.
authorgn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Wed, 9 Dec 2009 02:10:46 +0000 (02:10 +0000)
committergn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Wed, 9 Dec 2009 02:10:46 +0000 (02:10 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@307 4e526526-5e11-4fc0-8910-f8fd03428081

rec10/trunk/src/chdata.py
rec10/trunk/src/dbMySQL.py
rec10/trunk/src/install.py
rec10/trunk/src/rec10.conf
rec10/trunk/src/scan_ch.py [new file with mode: 0644]
rec10/trunk/src/timerec.py
rec10/trunk/src/ts2epg.py
rec10/trunk/src/xml2db_dom.py

index 46526e2..ca02a8f 100644 (file)
@@ -16,9 +16,44 @@ def chadd(bctype, ontv, chtxt, ch, csch):#すべて文字列
     チャンネルの数字を足したものにする
     """
     rec10d.rec10db.add_epg_ch(bctype, ontv, chtxt, ch, csch, u"2009-04-01 00:00:00")
-
-def new_chdata():
+def new_chdata(bs,cs):
     rec10d.rec10db.new_epg_ch()
+    if bs==1:
+        #bs放送の設定 全国共通のはず
+        chadd('bs', u'3001.ontvjapan.com', u'bs-nhk-1', u'101', u'0')
+        chadd('bs', u'3002.ontvjapan.com', u'bs-nhk-2', u'102', u'0')
+        chadd('bs', u'3003.ontvjapan.com', u'bs-nhk-hi', u'103', u'0')
+        chadd('bs', u'3004.ontvjapan.com', u'bs-nittere', u'141', u'0')
+        chadd('bs', u'3005.ontvjapan.com', u'bs-asahi', u'151', u'0')
+        chadd('bs', u'3006.ontvjapan.com', u'bs-tbs', u'161', u'0')
+        chadd('bs', u'3007.ontvjapan.com', u'bs-japan', u'171', u'0')
+        chadd('bs', u'3008.ontvjapan.com', u'bs-fuji', u'181', u'0')
+        chadd('bs', u'3013.ontvjapan.com', u'bs-11', u'211', u'0')
+    if cs==1:
+        #CS放送(スカパーe2)主に基本パックには言ってるものを中心に
+        chadd(u'cs1', u'1204.ontvjapan.com', u'natiogeo', u'CS6', u'343')
+        chadd(u'cs1', u'1070.ontvjapan.com', u'bbc', u'CS12', u'353')
+        chadd(u'cs1', u'1069.ontvjapan.com', u'cnn', u'CS12', u'354')
+        chadd(u'cs1', u'1045.ontvjapan.com', u'kids', u'CS22', u'330')
+        chadd(u'cs1', u'1007.ontvjapan.com', u'movieplus', u'CS18', u'240')
+        chadd(u'cs1', u'1016.ontvjapan.com', u'fox', u'CS4', u'312')
+        chadd(u'cs1', u'1014.ontvjapan.com', u'axn', u'CS6', u'311')
+        chadd(u'cs1', u'1201.ontvjapan.com', u'atx', u'CS16', u'333')
+        chadd(u'cs1', u'1050.ontvjapan.com', u'hisch', u'CS16', u'342')
+        chadd(u'cs1', u'1047.ontvjapan.com', u'animax', u'CS20', u'332')
+        chadd(u'cs1', u'1062.ontvjapan.com', u'disch', u'CS20', u'340')
+        chadd(u'cs1', u'1193.ontvjapan.com', u'anipla', u'CS20', u'341')
+        chadd(u'cs1', u'1008.ontvjapan.com', u'neco', u'CS6', u'223')
+        chadd(u'cs1', u'1015.ontvjapan.com', u'family', u'CS22', u'293')
+        chadd(u'cs1', u'1213.ontvjapan.com', u'disney', u'CS4', u'334')
+        chadd(u'cs1', u'1092.ontvjapan.com', u'teroasa', u'CS12', u'303')
+        chadd(u'cs1', u'1073.ontvjapan.com', u'fuji-one', u'CS20', u'307')
+        chadd(u'cs1', u'1072.ontvjapan.com', u'fuji-two', u'CS20', u'308')
+        chadd(u'cs1', u'1009.ontvjapan.com', u'yo-ga', u'CS6', u'224')
+        chadd(u'cs2', u'1217.ontvjapan.com', u'thecinema', u'CS10', u'228')
+        chadd(u'cs2', u'1086.ontvjapan.com', u'nihoneiga', u'CS2', u'239')
+def new_chdata():
+    new_chdata(1,1)
     #チャンネルの設定
     #chadd(u'放送種別',u'ontvコード(ontvのサイトなどで調べられる)',u'略称(何でもよい)',u'チャンネル(物理チャンネル)',u'CS放送の場合の内訳')
 
@@ -49,38 +84,8 @@ def new_chdata():
 
 
 
-    #CS放送(スカパーe2)主に基本パックには言ってるものを中心に
-    chadd(u'cs1', u'1204.ontvjapan.com', u'natiogeo', u'CS6', u'343')
-    chadd(u'cs1', u'1070.ontvjapan.com', u'bbc', u'CS12', u'353')
-    chadd(u'cs1', u'1069.ontvjapan.com', u'cnn', u'CS12', u'354')
-    chadd(u'cs1', u'1045.ontvjapan.com', u'kids', u'CS22', u'330')
-    chadd(u'cs1', u'1007.ontvjapan.com', u'movieplus', u'CS18', u'240')
-    chadd(u'cs1', u'1016.ontvjapan.com', u'fox', u'CS4', u'312')
-    chadd(u'cs1', u'1014.ontvjapan.com', u'axn', u'CS6', u'311')
-    chadd(u'cs1', u'1201.ontvjapan.com', u'atx', u'CS16', u'333')
-    chadd(u'cs1', u'1050.ontvjapan.com', u'hisch', u'CS16', u'342')
-    chadd(u'cs1', u'1047.ontvjapan.com', u'animax', u'CS20', u'332')
-    chadd(u'cs1', u'1062.ontvjapan.com', u'disch', u'CS20', u'340')
-    chadd(u'cs1', u'1193.ontvjapan.com', u'anipla', u'CS20', u'341')
-    chadd(u'cs1', u'1008.ontvjapan.com', u'neco', u'CS6', u'223')
-    chadd(u'cs1', u'1015.ontvjapan.com', u'family', u'CS22', u'293')
-    chadd(u'cs1', u'1213.ontvjapan.com', u'disney', u'CS4', u'334')
-    chadd(u'cs1', u'1092.ontvjapan.com', u'teroasa', u'CS12', u'303')
-    chadd(u'cs1', u'1073.ontvjapan.com', u'fuji-one', u'CS20', u'307')
-    chadd(u'cs1', u'1072.ontvjapan.com', u'fuji-two', u'CS20', u'308')
-    chadd(u'cs1', u'1009.ontvjapan.com', u'yo-ga', u'CS6', u'224')
-    chadd(u'cs2', u'1217.ontvjapan.com', u'thecinema', u'CS10', u'228')
-    chadd(u'cs2', u'1086.ontvjapan.com', u'nihoneiga', u'CS2', u'239')
+    
 
-    #bs放送の設定 全国共通のはず
-    chadd('bs', u'3001.ontvjapan.com', u'bs-nhk-1', u'101', u'0')
-    chadd('bs', u'3002.ontvjapan.com', u'bs-nhk-2', u'102', u'0')
-    chadd('bs', u'3003.ontvjapan.com', u'bs-nhk-hi', u'103', u'0')
-    chadd('bs', u'3004.ontvjapan.com', u'bs-nittere', u'141', u'0')
-    chadd('bs', u'3005.ontvjapan.com', u'bs-asahi', u'151', u'0')
-    chadd('bs', u'3006.ontvjapan.com', u'bs-tbs', u'161', u'0')
-    chadd('bs', u'3007.ontvjapan.com', u'bs-japan', u'171', u'0')
-    chadd('bs', u'3008.ontvjapan.com', u'bs-fuji', u'181', u'0')
-    chadd('bs', u'3013.ontvjapan.com', u'bs-11', u'211', u'0')
+    
 if __name__ == "__main__":
     new_chdata()
\ No newline at end of file
index 5f6b4b8..ae4e2e6 100644 (file)
@@ -81,6 +81,7 @@ class DB_MySQL:
             chname VARCHAR(100),\
             updatetime DATETIME,\
             status TINYINT\
+            show TINYINT\
             )')
         except:
             ""
@@ -89,8 +90,8 @@ class DB_MySQL:
         db = self.connect_db()
         db[1].execute('\
         INSERT INTO epg_ch \
-        VALUES (%s,%s,%s,%s,%s,"",%s,%s)', \
-                      (bctype, ontv, chtxt, ch, csch, updatetime, "1"))
+        VALUES (%s,%s,%s,%s,%s,"",%s,%s,%s)', \
+                      (bctype, ontv, chtxt, ch, csch, updatetime, "1","1"))
         self.close_db(db)
     def select_by_ontv_epg_ch(self, ontv):
         db = self.connect_db()
@@ -465,8 +466,9 @@ class DB_MySQL:
             terec TINYINT DEFAULT 0,\
             bscsrec TINYINT DEFAULT 0,\
             b252ts TINYINT DEFAULT 0\
+            installed TINYINT DEFAULT 0\
             )")
-            db[1].execute("INSERT IGNORE into in_status VALUE (0,0,0,0)")
+            db[1].execute("INSERT IGNORE into in_status VALUE (0,0,0,0,0)")
         except:
             ""
         self.close_db(db)
@@ -526,6 +528,29 @@ class DB_MySQL:
         db[1].execute("\
         UPDATE in_status SET b252ts=b252ts+%s",i)
         self.close_db(db)
+    def select_installed_in_status(self):
+        db = self.connect_db()
+        dbexe = db[1].execute("\
+        SELECT ts2avi,terec,bscsrec,b252ts,installed \
+        FROM in_status \
+        ")
+        ret = 0
+        dls = []
+        if dbexe > 0:
+            dls = db[1].fetchall()
+        self.close_db(db)
+        for dl in dls:
+            r = list(dl)
+            ret=r[4]
+        return ret
+    def change_installed_in_status(self):
+        """
+        installedを設定する
+        """
+        db = self.connect_db()
+        db[1].execute("\
+        UPDATE in_status SET installed=1")
+        self.close_db(db)
     def new_epg_timeline(self, bctype):
         db = self.connect_db()
         try:
@@ -618,37 +643,6 @@ class DB_MySQL:
             retall = db[1].fetchall()
         self.close_db(db)
         return retall
-    #def new_epg_ch(self, bctype):
-    #    db = self.connect_db()
-    #    try:
-    #        db[1].execute("DELETE FROM ch WHERE bctype = %s", (bctype,))
-    #    except:
-    #        ""
-    #    try:
-    #        db[1].execute('\
-    #        CREATE TABLE epg_ch \
-    #        (\
-    #        bctype VARCHAR(20),\
-    #        channel VARCHAR(20) NOT NULL,\
-    #        display VARCHAR(100),\
-    #        UNIQUE unich(bctype,channel)\
-    #        )')
-    #    except:
-    #        ""
-        #db.commit()
-    #    self.close_db(db)
-    #def add_epg_ch(self, bctype, channel, display):
-    #    db = self.connect_db()
-    ##    db[1].execute('INSERT IGNORE INTO epg_ch VALUES (%s,%s,%s)', (bctype, channel, display))
-        #db.commit()
-    #    self.close_db(db)
-    #def add_multi_ch(self, chlists):
-    #    """
-    #    chlists is (bctype,channel,display) lists
-    ##    """
-    #    db = self.connect_db()
-    #    db[1].executemany('INSERT IGNORE INTO ch VALUES (%s,%s,%s)', chlists)
-    #    self.close_db(db)
     def new_in_auto_bayes_key(self):
         db = self.connect_db()
         try:
index afd983f..6a9a97a 100644 (file)
@@ -2,7 +2,64 @@
 # coding: UTF-8
 # Rec10 TS Recording Tools
 # Copyright (C) 2009 Yukikaze
+import time
+import os.path
+
 import chdata
-import timerec
-chdata.new_chdata()
-timerec.task()
\ No newline at end of file
+import recdblist
+def install():
+    recdblist.printutf8(u"rec10のインストールを開始します。")
+    time.sleep(1)
+    recdblist.printutf8(u"インストール処理中・・・")
+    path = str(os.path.dirname(os.path.abspath(__file__)))
+    confp = ConfigParser.SafeConfigParser()
+    Conf = 'rec10.conf'
+    confpath=""
+    if os.path.exists(os.path.join(path,Conf)):
+        confpath=os.path.join(path,Conf)
+    elif os.path.exists(os.path.join("/etc","rec10.conf")):
+        confpath=os.path.join("/etc","rec10.conf")
+    elif os.path.exists(os.path.join("/etc/rec10","rec10.conf")):
+        confpath=os.path.join("/etc/rec10","rec10.conf")
+    if confpath!="":
+        confp.read(confpath)
+    else:
+        recdblist.printutf8(u"rec10.confが見つかりません。")
+        recdblist.printutf8(u"このinstall.pyと同じフォルダに置くか、/etc/rec10.confもしくは/etc/rec10/rec10.confにおいてください。")
+        sys.exit(1)
+    recdblist.printutf8(u"設定ファイルの読み込みを確認//設定ファイルのパスは"+confpath)
+    if confp.get('path',"recpath")=="/path of /recording":
+        recdblist.printutf8(u"録画先のフォルダを設定してください(recpath=)")
+        sys.exit(1)
+    recdblist.printutf8(u"DB処理に入ります")
+    if os.path.exists(os.path.join(path,"rec10d.py")):
+        try:
+            import rec10d
+        except Exception, inst:
+            recdblist.printutf8(u"DB処理中にエラーが出ました。configファイルのDB設定を見直してください。")
+            print type(inst)
+            print inst
+    recdblist.printutf8(u"チャンネル設定に入ります")
+    recdblist.printutf8(u"BS放送は受信可能ですか?")
+    bsok=raw_input("y/N")
+    if bsok=="Y" or bsok == "y" :
+        bsok=1
+    else:
+        bsok=0
+    recdblist.printutf8(u"CS放送は受信可能ですか?")
+    csok=raw_input("y/N")
+    if csok=="Y" or csok == "y" :
+        csok=1
+    else:
+        csok=0
+    chdata.new_chdata(bsok,csok)
+    recdblist.printutf8(u"チャンネルスキャンの開始(現在放送停止中のものはうまくとれません)")
+    import scan_ch
+    scan_ch.scan_ch()
+    recdblist.printutf8(u"チャンネルスキャン完了")
+    recdblist.printutf8(u"おめでとうございます 初期設定は完了しました。")
+    recdblist.printutf8(u"rec10を実行するユーザーのcrontabに"+os.path.join(path,"rec10")+"を追加してください(5分周期が目安)")
+    rec10d.rec10db.change_installed_in_status()
+    timerec.task()
+if __name__ == "__main__":
+    install()
index de0ff74..48e7bb7 100644 (file)
@@ -6,10 +6,10 @@ xvfb-run = /usr/bin/xvfb-run
 rec10 = /etc/rec10/
 
 #recpathは録画先のフォルダを指定
-recpath = /path of /recording
+recpath = "/path of /recording"
 
 #録画終了後に動画を置いておくフォルダを指定するとrectool.plでリスト化できます。
-recorded = /path of /recordedpath
+recorded = "/path of /recordedpath"
 
 #複数のrec10で役割を分担するときに用いる移動先
 move_destpath =
diff --git a/rec10/trunk/src/scan_ch.py b/rec10/trunk/src/scan_ch.py
new file mode 100644 (file)
index 0000000..9cf2a20
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+# coding: UTF-8
+# Rec10 TS Recording Tools
+# Copyright (C) 2009 Yukikaze
+import os
+
+import chdata
+import configreader
+import recdblist
+import ts2epg
+import xml2db_dom
+def check_tech(ch):
+    recdblist.printutf8(u"チャンネル"+str(ch)+u"を受信中")
+    tmppath = configreader.getpath("tmp")+"/"
+    if tmppath=="/":
+        tmppath=path
+    ts2epg.write_time(tmppath+"chscan.xml", str(ch),"3")
+
+    if os.path.exists(tmppath+"chscan.xml"):
+        chl=xml2db_dom.getChdata(tmppath+"chscan.xml")
+        chdata.chadd(u"te"+str(ch), chl[0],u"te"+str(ch),str(ch),"0")
+        recdblist.printutf8(u"番組受信成功 チャンネル名:"+chl[1])
+    else:
+        recdblist.printutf8(u"失敗")
+def scan_ch(beginch,endch):
+    recdblist.printutf8(u"チャンネルスキャンを開始します")
+    for i in xrange(beginch,endch):
+        check_tech(i)
+def scan_ch():
+    scan_ch(0,30)
\ No newline at end of file
index 42d8ae0..39dbcd5 100644 (file)
@@ -22,6 +22,7 @@ import status
 import tv2avi
 import tv2mkv
 import tv2mp4
+import install
 import recdblist
 recpath = configreader.getpath('recpath')
 movepath = configreader.getpath('move_destpath')
@@ -31,6 +32,8 @@ def task():
     数分毎に実行されるタスク処理
     予定によって子プロセスを生成し処理する。
     """
+    if rec10d.rec10db.select_installed_in_status()==0:
+        install.install()
     recdb.delete_old("24")
     recdb.delete_old_auto_bayes("1")
     recdb.delete_old_auto_keyword("1")
index 52c111e..22d9bf8 100644 (file)
@@ -16,16 +16,24 @@ def write(pout, ch):
     """
     tsを取得してepgの入ったxmlとして書き出す
     """
+    timet = "90"
+    if re.search(u'cs', bctype):
+        timet = "180"
+    elif re.search(u'bs', bctype):
+        timet = "240"
+    write_time(pout, ch ,timet)
+def write_time(pout, ch ,time):
+    """
+    指定された時間分tsを取得してepgの入ったxmlとして書き出す
+    """
     recdblist.printutf8(u"Ts-EPG XML書き出し処理開始")
     bctype = chdb.chsearch(ch)['bctype']
     recdblist.printutf8(ch + ":" + bctype)
-    timet = "90"
+    timet = time
     if re.search(u'cs', bctype):
         mode = "/CS"
-        timet = "180"
     elif re.search(u'bs', bctype):
         mode = "/BS"
-        timet = "240"
     else:
         mode = chdb.bctypesearch(u'te' + ch)['ontv']
     epgdump = configreader.getpath("epgdump")
@@ -37,5 +45,4 @@ def write(pout, ch):
     recdblist.printutf8(exe)
     os.system(exe)
     time.sleep(10)
-        
 
index 92d35ca..5059c06 100644 (file)
@@ -71,4 +71,15 @@ def xml2db_dom(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSが
     dtb=datetime.datetime.now()-dtb
     recdblist.printutf8(bctype + u" epg取り出し終了")
     recdblist.printutf8(str(dtb.days * 24 * 60 * 60 + dtb.seconds)+u"seconds taken for updating bayes-auto DB .")
-        
+def getChdata(xmlpath):
+    dom=xml.dom.minidom.parse(file(xmlpath))
+    chlist=[]
+    for ch in dom.getElementsByTagName('channel'):
+        ontv=ch.getAttribute("id")
+        chname=ch.getElementsByTagName("display-name").item(0).childNodes[0].data
+        chlist.append([ontv,chname])
+    dom.unlink()
+    if len(chlist)>0:
+        return chlist[0]
+    else:
+        return ["",""]
\ No newline at end of file