OSDN Git Service

implement update(to 0.9.10)
[rec10/rec10-git.git] / rec10 / trunk / src / recdblist.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
5
6 """
7 task names
8 """
9 import datetime
10 import os
11 import os.path
12 import traceback
13
14 import configreader
15
16 global REC_RESERVE
17 global REC_FINAL_RESERVE
18 global REC_ENCODE_GRID
19 global REC_ENCODE_LOCAL
20 global REC_ENCODE_QUE
21 global REC_MISS_ENCODE
22 global REC_KEYWORD
23 global REC_KEYWORD_EVERY_SOME_DAYS
24 global REC_FIN_LOCAL
25 global REC_MISS_DECODE
26 global REC_TS_DECODE_QUE
27 global REC_TS_DECODING
28 global REC_TS_RECORDING
29 global REC_AVI_TO_MKV
30 global REC_AVI_TO_MP4
31 global REC_MKV_TO_MP4
32 global REC_CHANGING_CANTAINER
33
34 #ここから処理のちに移動
35
36 global REC_MOVE_END
37
38 #ここから自動で提起される処理。
39 global REC_AUTO_SUGGEST_REC
40 global REC_AUTO_SUGGEST_DECODE
41 global REC_AUTO_SUGGEST_ENCODE
42 global REC_AUTO_SUGGEST_AVI2MP4
43 global REC_AUTO_SUGGEST_MKV2MP4
44 global REC_AUTO_SUGGEST_AVI2FP
45 global REC_AUTO_SUGGEST_AP2FP
46 global REC_BAYES_SUGGEST
47 global REC_AUTO_KEYWORD
48 REC_RESERVE = "reserve_flexible"
49 REC_FINAL_RESERVE = "reserve_fixed"
50 REC_ENCODE_GRID = "convert_ts_mp4_network"
51 REC_ENCODE_LOCAL = "convert_ts_mp4_running"
52 REC_ENCODE_QUE = "convert_ts_mp4"
53 REC_MISS_ENCODE = "convert_avi_mp4_miss"
54 REC_KEYWORD = "search_today"
55 REC_KEYWORD_EVERY_SOME_DAYS = "search_everyday"
56 REC_FIN_LOCAL = "convert_ts_mp4_finished"
57 REC_MISS_DECODE = "convert_b25_ts_miss"
58 REC_TS_DECODE_QUE = "convert_b25_ts"
59 REC_TS_DECODING = "convert_b25_ts_running"
60 REC_TS_RECORDING = "reserve_running"
61 REC_CHANGING_CANTAINER = "convert_mkv_mp4_runnings"
62 REC_AVI_TO_MKV = "convert_avi_mkv"
63 REC_AVI_TO_MP4 = "convert_avi_mp4"
64 REC_MKV_TO_MP4 = "convert_mkv_mp4"
65
66 REC_MOVE_END = "move_end"
67
68 REC_AUTO_SUGGEST_REC = "auto_suggest_rec"
69 REC_AUTO_SUGGEST_DECODE = "auto_suggest_dec"
70 REC_AUTO_SUGGEST_ENCODE = "auto_suggest_enc"
71 REC_AUTO_SUGGEST_AVI2FP = "auto_suggest_avi2fp"
72 REC_AUTO_SUGGEST_AP2FP = "auto_suggest_ap2fp"
73 REC_AUTO_KEYWORD = "auto_keyword"
74 REC_BAYES_SUGGEST ="bayes_suggest"
75
76 global BONTSDEMUX_DELAY
77 BONTSDEMUX_DELAY="0"
78
79 version = 100
80 version_str="0.9.10"
81
82 global verbose_level_now
83 global log_level_now
84
85 try:
86     log_level_now=int(configreader.getlog("log_level"))
87     verbose_level_now=int(configreader.getlog("verbose_level"))
88 except:
89     log_level_now=900
90     verbose_level_now=400
91 def printutf8(unicode,verbose_level=500):
92     if verbose_level_now > verbose_level:
93         try:
94             str=unicode.encode('utf-8')
95             print str
96         except Exception, inst:
97             recdblist.Commonlogex("Error", "printutf8(recdblist.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)
98 def printuft8ex(unicode,verbose_level=500,log_level=500):
99     str=unicode.encode('utf-8')
100     if verbose_level_now > verbose_level:
101         print str
102     logfname="/var/log/rec10"
103     mode="a"
104     if log_level_now > log_level:
105         if os.path.exists(logfname):
106             f=open(logfname,mode)
107             f.write(str+"\n")
108             f.close()
109 def Commonlogex(type,place,inst,txt,verbose_level=500,log_level=500):
110     lt=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+u":"
111     if txt=="":
112         lt=lt+u"["+type+u"] "+place+u" "+inst
113     else:
114         lt=lt+u"["+type+u"] "+place+u" "+inst+u"\n"+txt
115     lt=lt.encode('utf-8')
116     logfname="/var/log/rec10"
117     mode="a"
118     if verbose_level_now > verbose_level:
119         print lt
120     if log_level_now > log_level:
121         if os.path.exists(logfname):
122             f=open(logfname,mode)
123             f.write(lt+"\n")
124             f.close()
125 def addCommandLog(tspath,log_title,cmd,cmd_log=""):
126     addlog(tspath,cmd,log_title+u"ログ-コマンド")
127     addlog(tspath,cmd_log,log_title+u"ログ-詳細")
128 def addlog(tspath,txt,log_title):
129     logo=tspath
130     logo=logo.replace("_1.wav",".ts")
131     logo=logo.replace("_2.wav",".ts")
132     logo=logo.replace("_1.aac",".ts")
133     logo=logo.replace("_2.aac",".ts")
134     logo=logo.replace("_1.mp3",".ts")
135     logo=logo.replace("_2.mp3",".ts")
136     logo=logo.replace(".ts.tsmix",".ts")
137     logo=logo.replace(".ts.b25",".ts")
138     logo=logo.replace(".sa.avi",".ts")
139     logo=logo.replace(".m2v",".ts")
140     logo=logo.replace(".avi",".ts")
141     logo=logo.replace(".mkv",".ts")
142     logo=logo.replace(".wav",".ts")
143     logo=logo.replace(".mp4",".ts")
144     logo=logo.replace(".mp3",".ts")
145     logo=logo.replace(".aac",".ts")
146     logo=logo.replace(".srt",".ts")
147     logo=logo.replace(".ts",".log")
148     f=open(logo,'a')
149     s=len(txt)
150     stxt=""
151     if s>3000:
152         stxt=txt[0:1500]+"\n\n(ry..)\n"
153         st=txt[s-1500:].find("\n")
154         if st>0:
155             stxt=stxt+txt[s-1500+st:]
156     else:
157         stxt=txt
158     txtw= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
159     txtw=txtw+"\n####"+log_title+"####\n"+stxt
160     f.write(txtw.encode('utf-8'))
161     f.close()