OSDN Git Service

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