OSDN Git Service

implement ch scan system.(alpha)
[rec10/rec10-git.git] / rec10 / trunk / src / scan_ch.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
5 import os
6 import os.path
7 import time
8 import commands
9 import traceback
10
11 import rec10d
12 import configreader
13 import recdblist
14 import tv2ts
15 tmppath = configreader.getpath("tmp")+"/"
16 tssplitterp = configreader.getpath("tssplitter")
17 def searchCh():
18     #地上デジタル
19     for i in xrange(12,99):
20         recdblist.printuft8ex(u"チャンネルスキャン:地上デジタル CH "+str(i), 200, 200)
21         if checkTs(str(i))>0:
22             addCh(str(i),u"te"+str(i),str(i))
23     #BSデジタル
24     recdblist.printuft8ex(u"チャンネルスキャン:BSデジタル "+str(i), 200, 200)
25     for i in xrange(100,240):
26         recdblist.printuft8ex(u"チャンネルスキャン:BSデジタル CH "+str(i), 200, 200)
27         if checkTs(str(i))>0:
28             addCh(str(i),u"bs","BS")
29     #スカパーe2!
30     #http://www5e.biglobe.ne.jp/~kazu_f/digital-sat/trapon-nsat110.html
31     #
32     #CS1ネットワーク
33     if checkTs("CS2")>0:
34         addCh("CS2","cs1","CS")
35     if checkTs("CS8")>0:
36         addCh("CS8","cs1","CS")
37     if checkTs("CS10")>0:
38         addCh("CS10","cs1","CS")
39     #CS2ネットワーク
40     if checkTs("CS4")>0:
41         addCh("CS4","cs2","CS")
42     if checkTs("CS6")>0:
43         addCh("CS6","cs2","CS")
44     if checkTs("CS12")>0:
45         addCh("CS12","cs2","CS")
46     if checkTs("CS14")>0:
47         addCh("CS14","cs2","CS")
48     if checkTs("CS16")>0:
49         addCh("CS16","cs2","CS")
50     if checkTs("CS18")>0:
51         addCh("CS18","cs2","CS")
52     if checkTs("CS20")>0:
53         addCh("CS20","cs2","CS")
54     if checkTs("CS22")>0:
55         addCh("CS22","cs2","CS")
56     if checkTs("CS24")>0:
57         addCh("CS24","cs2","CS")
58 def checkTs(ch):
59     tv2ts.tv2b25ts(os.path.join(tmppath,"ch_"+str(ch)+".ts"), ch, "1")
60     if os.path.exists(os.path.join(tmppath,"ch_"+str(ch)+".ts")):
61         os.remove(os.path.join(tmppath,"ch_"+str(ch)+".ts"))
62         return 1
63     else:
64         return 0
65 def addCh(ch,bctype,chtxthead):
66     prglist=getChProgNum(ch)
67     for lstr in prglist:
68         #print [bctype,chtxthead+"_"+lstr, ch, lstr]
69         try:
70             if ch.find("bs")>-1:
71                 if int(lstr)<300:
72                     rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr, u"2010-01-01 00:00:00")
73             else:
74                 rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr, u"2010-01-01 00:00:00")
75         except Exception, inst:
76             recdblist.Commonlogex("Warning", "addCh (scan_ch.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
77 def getChProgNum(ch):
78     pout=os.path.join(tmppath,"ch_"+str(ch)+".ts")
79     tv2ts.tv2tsmix(pout, ch, "10")
80     retl=getTsProgNum(pout)
81     os.remove(pout)
82     return retl
83 def getTsProgNum(tspath):
84     pin=tspath
85     pout=os.path.join(tmppath,"chscan.txt")
86     doexe = tssplitterp + " -ch \""+ pin + "\" \""+ pout + "\""
87     doexe = "nice -n 18 " + doexe
88     os.environ['LANG']="ja_JP.UTF-8"
89     txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8','ignore')
90     f=open(pout)
91     lines=f.readlines()
92     f.close()
93     ret=[]
94     for l in lines:
95         try:
96             l=l.replace(" ","")
97             l=l.replace("\n","")
98             ret.append(str(int(l)))
99         except:
100             ""
101     recdblist.addlog(pin, doexe, u"TsSplitログ-コマンド")
102     recdblist.addlog(pin, txt, u"TsSplitログ-詳細")
103     time.sleep(1)
104     try:
105         ""
106         #os.remove(pout)
107     except:
108         ""
109     return ret