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