import datetime
import ts2epg
import xml2db
-#import japanesenkf
-#japanesenkf.overrideEncodings()
path=str(os.path.dirname(os.path.abspath(__file__)))+"/"
tmppath=path
def update(chtxt):
lastup=datetime.datetime.strptime("2009-04-01 00:00:00","%Y-%m-%d %H:%M:%S")
dt=tnow-lastup
dt=dt.days*24*60+dt.seconds
- #print dt
if dt>2*60*60:
ts2epg.write(tmppath+"epgdate.xml",chdb.chtxtsearch(chtxt)['ch'])
xml2db.xml2db(tmppath+"epgdate.xml",path+"ch.db",chdb.chtxtsearch(chtxt)['bctype'])
- #os.remove(path+"epgdate.xml")
def updatebc(bctype):
- #print bctype
- #tnow=datetime.datetime.now()
bctypel=chdb.bctypesearch(bctype)
print bctypel
ts2epg.write(tmppath+"epgdate.xml",chdb.bctypesearch(bctype)['ch'])
xml2db.xml2db(tmppath+"epgdate.xml",path+"ch.db",bctype)
- #os.remove(path+"epgdate.xml")
def updateall():
update("hisch")
update("nhk-k")
chtxt="Unknown"
#print ch
ret.append(chtxt+","+title.encode('utf-8')+","+btime+","+etime)
-
- #r=db.execute("SELECT * FROM tv")
- #for row in r:
- # print unicode(row)
- #row=r.fetchone()
- #print r
db.close()
return ret
def searchtime(titletxt,time,deltatime):#時間以内のものだけを表示 deltatimeはhours
dt=abs(dt)
if dt<deltatime*60*60:
ret.append(chtxt+","+title.encode('utf-8')+","+btime+","+etime)
-
- #r=db.execute("SELECT * FROM tv")
- #for row in r:
- # print unicode(row)
- #row=r.fetchone()
- #print r
db.close()
return ret
import configreader
import glob
import time
+import sqlite3
+dbpath=str(os.path.dirname(os.path.abspath(__file__)))+"/"+"ch.db"
if __name__ == "__main__":
- print "Hello World";
+ print "Hello Rec10 Recording Que Search.";
def search_b25(path):
+ """
+ 録画フォルダを検索し、各QUEの実行状況を表示する
+ """
+ b25list=glob.glob(path+"/*.b25")
+ tslist=glob.glob(path+"/*.ts")
+ avilist=glob.glob(path+"/*.avi")
+ for b25f in b25list:
+ ##b25f is title.ts.b25 avi is title.avi
+ dir=os.path.split(b25f)[0]
+ title=os.path.split(b25f)[1]
+ title=title.replace(".ts.b25","")
+ avipath=os.path.join(dir,title+".avi")
+ tspath=os.path.join(dir,title+".ts")
+ b25f=b25f.replace(".ts.b25",".avi")
+ mode="ts"
+ if os.path.isfile(tspath):##tsファイルが存在している
+ dtime=time.time()-os.path.getmtime(tspath)
+ dtime=int(dtime)
+ if dtime > 120 :
+ if os.path.getsize(tspath)>1*1000*1000:##最終更新から22分以上経過かつ1MB以上
+ mode="avi"
+ else:
+ mode="tsmiss"
+ else :
+ mode="ts"
+ if os.path.isfile(avipath):##tsファイルが存在している
+ dtime=time.time()-os.path.getmtime(avipath)
+ dtime=int(dtime)
+ if dtime > 120 :
+ if os.path.getsize(avipath)>1*1000*1000:##最終更新から22分以上経過かつ1MB以上
+ mode="fin"
+ else:
+ mode="avimiss"
+ else :
+ mode="avi"
+ print title+":"+mode
+def search_b25_DB(path):
+ """
+ 検索結果をDBに書き込む。
+ """
+ db = sqlite3.connect(dbpath)
+ try:
+ db.execute('drop table que')
+ db.commit()
+ except:
+ test = ""
+
+ try:
+ db.execute('create table que (title TEXT,que TEXT,status TEXT)')
+ except:
+ ""
+ db.commit()
+
b25list=glob.glob(path+"/*.b25")
tslist=glob.glob(path+"/*.ts")
avilist=glob.glob(path+"/*.avi")
import datetime
import epgdb
import configreader
-#import japanesenkf
import ts2x264
import tv2avi
import recdb
import chdb
import status
import re
-#japanesenkf.overrideEncodings()
recpath=configreader.getpath('recpath')
path=str(os.path.dirname(os.path.abspath(__file__)))+"/"
def task():
tnow=datetime.datetime.now()
dtt=bt-tnow#
dt=dtt.days*24*60*60+dtt.seconds
- #value=line.split(",")
+
if task["type"]==recdb.REC_RESERVE:#"res,"+chtxt+","+title+","+btime+","+etime+","+opt
if dt<58*60:
recdb.del_reckey(recdb.REC_RESERVE, title, chtxt, btime)
- #recdb.delrec(title,chtxt,btime)
recdb.rec_reckey(recdb.REC_FINAL_RESERVE, title, chtxt, btime, etime, opt)
- #recdb.lastrecreserv(title,chtxt,btime,etime,opt)
- """if dt >30*60:
- pid=os.fork()
- if pid>0:#親プロセスの場合
- ""
- else:#子プロセスの場合 アップデートを行って終了
- epgdb.update(chtxt)
- sys.exit(0)
- """
-
+
elif task["type"]==recdb.REC_KEYWORD:#"key,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt
deltatime=task['deltatime']
-
if dt<30*60:
recdatum=epgdb.searchtime(title,btime,deltatime)
if len(recdatum)>0:
- #recdb.delkey(title,chtxt,btime,deltatime)
recdb.del_reckey(recdb.REC_KEYWORD, title, chtxt, btime)
for recdata in recdatum:
- #recdata=recdata[0]
- #print recdata
recds=recdata.split(",")
chtxt=recds[0]
title=recds[1]
recdb.rec_reckey(recdb.REC_FINAL_RESERVE, title, chtxt, btime, etime, opt)
else :
print "nothing match"
+
elif task["type"]==recdb.REC_KEYWORD_EVERY_SOME_DAYS:#"keyevery,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt+","+deltaday
deltatime=task['deltatime']
deltaday=task['deltaday']
elif dt<30*60*60:
recdb.keyreserv(title,chtxt,btime,etime,deltatime,opt)
recdb.del_reckey(recdb.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime)
- #recdb.delevery(keyword,chtxt,btime,deltatime,deltaday)
bt=bt+dd
et=et+dd
btxt=bt.strftime("%Y-%m-%d %H:%M:%S")
etxt=et.strftime("%Y-%m-%d %H:%M:%S")
recdb.everyreserv(title,chtxt,btxt,etxt,deltatime,opt,deltaday)
+
elif task["type"]==recdb.REC_FINAL_RESERVE:#"rec,"+chtxt+","+title+","+btime+","+etime+","+opt
print dt
if dt<6*60:
- #recdb.dellastrec(title,chtxt,btime)
recdb.del_reckey(recdb.REC_FINAL_RESERVE, title, chtxt, btime)
- #recdb.recend(title,chtxt,btime,etime,opt)
recdb.rec_reckey(recdb.REC_TS_DECODING, title, chtxt, btime, etime, opt)
print "録画開始"
pid=os.fork()
#print title
tv2avi.timetv2avi(recpath+"/"+title+".avi",chtxt,btime,etime,opt)
if not os.access(recpath+"/"+title+".ts", os.F_OK):
- #recdb.del_reckey("tsfin", title, chtxt, btime)
recdb.del_reckey(recdb.REC_TS_DECODING, title, chtxt, btime)
recdb.rec_reckey(recdb.REC_MISS_DECODE, title, chtxt, btime, etime, opt)
else:
recdb.rec_reckey(recdb.REC_ENCODE_QUE,title,chtxt,btime,etime,opt)
recdb.rec_reckey(recdb.REC_FIN_DECODE,title,chtxt,btime,etime,opt)
sys.exit(0)
+
elif task["type"]==recdb.REC_ENCODE_QUE:
if dt<10*60:
if status.getEncoding()<2:
if pid>0:#親プロセスの場合
""
else:
- #print title
- #tv2avi.b252avi(recpath+"/"+title+".avi", chtxt,opt)
pin=recpath+"/"+title+".ts"
if re.search("d",opt):
pin=recpath+"/"+title+"sa.avi"
pout=recpath+"/"+title+".avi"
print pin+":"+pout+":"+opt
recdb.del_reckey(recdb.REC_ENCODE_QUE,title,chtxt,btime)
- recdb.rec_reckey("local", title, chtxt, btime, etime, opt)
+ recdb.rec_reckey(recdb.REC_ENCODE_LOCAL, title, chtxt, btime, etime, opt)
ts2x264.ts2x264(pin, pout, opt)
-
- #tv2avi.timetv2avi(recpath+"/"+title+".avi",chtxt,btime,etime,opt)
sys.exit(0)
else:
recdb.del_reckey(recdb.REC_ENCODE_QUE,title,chtxt,btime)