OSDN Git Service

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