OSDN Git Service

52a2c008ef8da1caf02e27fbb80ba25bb18b6b24
[rec10/rec10-git.git] / rec10 / trunk / src / tv2ts.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2011 Yukikaze
5 #import sys # モジュール属性 argv を取得するため
6 import commands
7 import os
8 import os.path
9 import time
10 import traceback
11
12 import configreader
13 import status
14 import recdblist
15 import recording_earth_pt1
16 mypath = str(os.path.dirname(os.path.abspath(__file__))) + "/"
17 def tv2tsmix(pout, ch, time,getlog=0):
18     tv2b25ts(pout + ".b25", ch, time)
19     txt=b252tsmix(pout + ".b25", pout)
20     return txt
21     #if os.access(pout, os.F_OK):
22     #    try:
23     #        os.remove(pout + ".b25")
24     #    except:
25     #        ""
26 def tv2ts(pout, ch, csch, time):
27     if ch.replace(" ","").replace("CS","").isdigit():
28         if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
29             status.changeBSCSRecording(1)
30         else:
31             status.changeTERecording(1)
32         try:
33             tv2b25ts(pout + ".b25", ch, time)
34         except Exception, inst:
35             recdblist.addCommonlogEX(u"Error",u"tv2ts(tv2ts.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
36         if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
37             status.changeBSCSRecording(-1)
38         else:
39             status.changeTERecording(-1)
40     else:
41          ch="0"
42          csch="0"
43     b252tsmix(pout + ".b25", pout + ".tsmix")
44     tch="0"
45     if csch!=u"0":
46         tch=csch
47     elif ch==u"101":
48         tch="101"
49     elif ch==u"102":
50         tch="102"
51     #else:
52     #    tch=ch
53     tsmix2ts(pout + ".tsmix", pout, tch)
54     if os.access(pout, os.F_OK):
55         try:
56             #os.remove(path + "/" + t + ext)
57             ""
58         except:
59             ""
60 def b252ts(pout, ch, csch):
61     b252tsmix(pout + ".b25", pout + ".tsmix")
62     tch=u"0"
63     if ch.replace(" ","").replace("CS","").isdigit():
64         if csch!=u"0":
65             tch=csch
66         elif ch==u"101":
67             tch=u"101"
68         elif ch==u"102":
69             tch=u"102"
70     else:
71         tch="0"
72     tsmix2ts(pout + ".tsmix", pout, tch)
73 def tv2b25ts(pout, ch, time):
74     if recording_earth_pt1.useDVB()==0:
75         exe = configreader.getConfPath('recpt1')
76         if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
77             status.changeBSCSRecording(1)
78         else:
79             status.changeTERecording(1)
80         try:
81             doexe = exe + ' ' + ch + ' ' + time + ' \'' + pout + '\''
82             recdblist.printutf8(doexe)
83             recdblist.addLog(pout, doexe, u"recpt1ログ-コマンド")
84             recdblist.addLog(pout, unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8'), u"recpt1ログ-詳細")
85         except Exception, inst:
86             recdblist.addCommonlogEX(u"Error",u"tv2b25ts(tv2ts.py)", str(type(inst)),str(inst))
87         if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
88             status.changeBSCSRecording(-1)
89         else:
90             status.changeTERecording(-1)
91     elif recording_earth_pt1.useDVB()==1:
92         if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
93             status.changeBSCSRecording(1)
94         else:
95             status.changeTERecording(1)
96         try:
97             recording_earth_pt1.record(ch,"0",pout,time,0)
98         except Exception, inst:
99             recdblist.addCommonlogEX(u"Error",u"tv2b25ts(tv2ts.py)", str(type(inst)),str(inst))
100         if len(ch) > 2:#BS/CSは100とかCS??とかなので3文字以上
101             status.changeBSCSRecording(-1)
102         else:
103             status.changeTERecording(-1)
104 def b252tsmix(pin, pout):
105     if not (os.path.exists(pout) and os.path.getsize(pin)>os.path.getsize(pout)*0.95 and os.path.getsize(pin)<os.path.getsize(pout)*1.05):
106         exe=""
107         if configreader.getConfPath('b25_remote')=="1":
108             try:
109                 exe = configreader.getConfPath('b25_env')+" && "
110             except:
111                 inst=u"b25_remoteがオンになっていますが、b25_envが設定されていないかコメントアウトされています。"
112                 recdblist.addCommonlogEX(u"Error",u"b252tsmix(tv2ts.py)", "",inst)
113         exe = exe + "nice -n 17 " + configreader.getConfPath('b25')
114         doexe = exe + u' \"' + pin + u'\" \"' + pout + u'\"'
115         recdblist.printutf8(doexe)
116         recdblist.addCommandSelfLog(pin,doexe)
117         txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
118         recdblist.addLog(pin, doexe, u"b25ログ-コマンド")
119         recdblist.addLog(pin, txt, u"b25ログ-詳細")
120         recdblist.addCommandLogZip(pin, "b25", "b25", doexe, txt)
121         return txt
122 def tsmix2ts(pin, pout, csch):#csch=0ならcsの処理をしない
123     tssplitterex=configreader.getConfPath("java")+" -jar "+configreader.getConfPath("jTsSplitter")
124     doexe =tssplitterex + " \""+ pin + "\" \""+ pout + "\" " + str(csch)
125     doexe = "nice -n 18 " + doexe
126     os.environ['LANG']="ja_JP.UTF-8"
127     txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
128     recdblist.addLog(pin, doexe, u"TsSplitログ-コマンド")
129     recdblist.addLog(pin, txt, u"TsSplitログ-詳細")
130     time.sleep(1)
131     if os.access(pout, os.F_OK) and os.path.getsize(pout)>10*1000*1000:
132         os.remove(pin)
133