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