def auto_check(path):
avilist = glob.glob(path + "/*.avi")
mkvlist = glob.glob(path+"/*.mkv")
+ mp4list = glob.glob(path+"/*.mp4")
tslist = glob.glob(path+"/*.ts")
b25list = glob.glob(path+"/*.ts.b25")
- filelist=avilist+mkvlist+tslist+b25list
+ filelist=avilist+mkvlist+tslist+b25list+mp4list
add=[]
for fn in filelist:
- if fn.rfind("sa.avi")==-1:
+ if fn.rfind("sa.avi")==-1 and fn.rfind(".120.avi")==-1:
dir = os.path.split(fn)[0]
file = os.path.split(fn)[1]
title = os.path.splitext(file)[0]
def select_get_update_epg_ch(self, dhour):
db = self.connect_db()
dbexe = db[1].execute("SELECT bctype,chtxt,status FROM epg_ch \
- WHERE \
+ WHERE (\
( \
updatetime < DATE_SUB(now(),INTERVAL " + dhour + " HOUR) \
AND \
status = 1 \
) \
OR \
- status > 1 \
+ status > 1 )\
ORDER BY status DESC")
ret = []
#recdblist.printutf8(dbexe)
ret['deltaday'] = deltaday
recdatum.append(ret)
return recdatum
+ def select_bytime_all_timeline(self,btime,etime,chtxt):
+ db = self.connect_db()
+ recdatum = []
+ #dbr=db[1].execute("SELECT type, chtxt, title, btime, etime, deltatime ,deltaday ,opt FROM rectime WHERE btime < DATE_SUB(now(),INTERVAL "+dminutes+" MINUTE ) AND btime > DATE_ADD(now(),INTERVAL "+dminutes+" MINUTE )")
+ dbr = db[1].execute("SELECT \
+ type, chtxt, title, btime, etime, deltatime ,deltaday ,opt \
+ FROM timeline \
+ WHERE btime > %s AND \
+ etime < %s\
+ AND chtxt=%s ",(btime,etime,chtxt))
+ dbl = db[1].fetchall()
+ self.close_db(db)
+ #recdblist.printutf8(dbl)
+ if dbr > 0:
+ for typet, chtxt, title, btime, etime, deltatime, deltaday, opt in dbl:
+ ret = {}
+ ret['type'] = typet
+ ret['chtxt'] = chtxt
+ ret['title'] = title
+ btime = btime.strftime("%Y-%m-%d %H:%M:%S")
+ etime = etime.strftime("%Y-%m-%d %H:%M:%S")
+ ret['btime'] = btime
+ ret['etime'] = etime
+ ret['opt'] = opt
+ if deltatime == None or deltatime == "":
+ deltatime = "3"
+ if deltaday == None or deltaday == "":
+ deltaday = "7"
+ if typet == recdblist.REC_KEYWORD:
+ ret['deltatime'] = deltatime
+ elif typet == recdblist.REC_KEYWORD_EVERY_SOME_DAYS:
+ ret['deltatime'] = deltatime
+ ret['deltaday'] = deltaday
+ recdatum.append(ret)
+ return recdatum
def delete_old_timeline(self, dhour):
db = self.connect_db()
db[1].execute("\
ts2avi TINYINT DEFAULT 0,\
terec TINYINT DEFAULT 0,\
bscsrec TINYINT DEFAULT 0,\
- b252ts TINYINT DEFAULT 0\
+ b252ts TINYINT DEFAULT 0,\
installed TINYINT DEFAULT 0\
)")
db[1].execute("INSERT IGNORE into in_status VALUE (0,0,0,0,0)")
retall = db[1].fetchall()
self.close_db(db)
return retall
- def select_by_time_auto_suggest_epg_timeline(self,keyword,btime,etime):
+ def select_by_time_keyword_auto_suggest_epg_timeline(self,keyword,btime,etime):
db = self.connect_db()
dbexe = "\
SELECT \
AND \
start >= %s \
AND \
- start <= %s \
+ stop <= %s \
AND \
( \
( title LIKE \'%%"+keyword+"%%\' ) \
import datetime
import os
import shutil
+import time
import chdb
import n_gram
ts2epg.write(tmppath + bctype + "epgdata.xml", chdb.bctypesearch(bctype)['ch'])
xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.xml", bctype)
shutil.copyfile(tmppath + bctype + "epgdata.xml", tmppath + bctype + "epgdata.bak.xml")
+ time.sleep(5)
rec10d.rec10db.update_by_bctype_epg_ch(bctype)
except Exception, inst:
print "error occurs in updatebc(epgdb)"
beforetime = time.strftime("%Y%m%d%H%M%S")
aftertime = time + datetime.timedelta(hours=deltatime)
aftertime = aftertime.strftime("%Y%m%d%H%M%S")
- d = rec10d.rec10db.select_by_time_auto_suggest_epg_timeline(keytxt,beforetime, aftertime)
+ d = rec10d.rec10db.select_by_time_keyword_auto_suggest_epg_timeline(keytxt,beforetime, aftertime)
for chtxtt, title, start, stop ,exp,longexp,category in d:
btime = start
btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"
import time
import os.path
import ConfigParser
+import sys
import chdata
import recdblist
+import timerec
def install():
recdblist.printutf8(u"rec10のインストールを開始します。")
time.sleep(1)
csok=0
chdata.new_chdata(bsok,csok)
recdblist.printutf8(u"おめでとうございます 初期設定は完了しました。")
- recdblist.printutf8(u"rec10を実行するユーザーのcrontabに"+os.path.join(path,"rec10")+"を追加してください(5分周期が目安)")
+ recdblist.printutf8(u"rec10を実行するユーザーのcrontabに"+os.path.join(path,"rec10")+u"を追加してください(5分周期が目安)")
+ import rec10d
rec10d.rec10db.change_installed_in_status()
timerec.task()
if __name__ == "__main__":
point = point + i
return point
def trigram(str1, str2):
+ """
+ trigramによる単語の近さを計算します。
+ 単語文字列の長さも考慮にいれます。
+ """
str1 = zenhan.toHankaku(str1)
str2 = zenhan.toHankaku(str2)
str1 = str1.replace(" ", "")
str2 = str2.replace(" ", "")
- """
- trigramによる単語の近さを計算します。
- """
gram = []
if len(str1) < 3:
gram.append(str1)
if pid!=0:
""
else:
+ time.sleep(10)
auto_process.auto_check(recpath)
sys.exit()
update = chdb.update()
else:
recdb.del_reckey(recdblist.REC_AVI_TO_MKV, title, chtxt, btime)
recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt)
- tv2mkv.avi2mkv(os.path.join(recpath,title+".avi"),os.path.join(recpath,title+".mkv"))
+ tv2mkv.avi2mkv(os.path.join(recpath,title+".avi"),os.path.join(recpath,title+".mkv"),opt)
recdb.del_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime)
sys.exit()
elif task["type"] == recdblist.REC_AVI_TO_MP4:
tsを取得してepgの入ったxmlとして書き出す
"""
timet = "90"
- if re.search(u'cs', bctype):
+ if re.search(u'CS', ch):
timet = "180"
- elif re.search(u'bs', bctype):
+ elif len(ch)>2:
timet = "240"
write_time(pout, ch ,timet)
-def write_time(pout, ch ,time):
+def write_time(pout, ch ,times):
"""
指定された時間分tsを取得してepgの入ったxmlとして書き出す
"""
recdblist.printutf8(u"Ts-EPG XML書き出し処理開始")
- bctype = chdb.chsearch(ch)['bctype']
recdblist.printutf8(u"CH:"+ch)
- timet = time
+ timet = times
if re.search(u'CS', ch):
mode = "/CS"
elif len(ch)>2:
def encode(pin,pout,size,isvfr,is2pass):
encvf=""
txt=""
- encvf="-vf yadif=0"
+ encvf="-vf yadif=0,hqdn3d=2:1:2"
harddup=",harddup"
ofps="-ofps 30000/1001"
bm=1
crf=""
if isvfr==1:
ofps="-ofps 120000/1001"
- encvf="-vf pullup,softskip,yadif=0"
+ encvf="-vf pullup,softskip,yadif=0,hqdn3d=2:1:2"
bm=4
x264enc1=":me=hex"
- x264enc2=":frameref=3:subq=7:partitions=all:8x8dct:me=umh:bframes=3:b_pyramid:weight_b"
+ x264enc2=":frameref=3:subq=7:partitions=all:8x8dct:me=umh:bframes=3:weight_b"
harddup=""
if size == "HD":
encvf = encvf + ",scale=1280:720"+harddup
tv2avi.ts2avi(pin, tpavi, opt)
time.sleep(10)
isvfr=0
- if re.search("v", opt):
- isvfr=1
- avi2mkv(tpavi,tpmkv,isvfr)
+ avi2mkv(tpavi,tpmkv,opt)
#shutil.move(tpavi,pout.replace(".mkv",".avi"))
#shutil.move(tpmkv,pout)
-def avi2mkv(pin,pout,isvfr):
+def avi2mkv(pin,pout,opt):
+ isvfr=0
+ if re.search("v", opt):
+ isvfr=1
exe = configreader.getpath("mkvmerge")
doexe=""
doexe0=""
+ ffmpegdo=""
if isvfr==1:
wineexe=configreader.getpath("wine")
cfr2tc=configreader.getpath("cfr2tc")
pin120=pin.replace(".avi",".120.avi")
+ pints=pin.replace(".avi",".ts")
pintimecode=pin.replace(".avi",".timecode.txt")
- doexe0=wineexe+u" "+cfr2tc+u" "+pin+u" "+pintimecode+u" 2"
- doexe = exe +"-o '"+pout+"' --forced-track 0:no --timecodes '0:"+pintimecode+"' -d 0 -A -S '"+pin120+"' --forced-track 1:no -a 1 -D -S '"+pin+"' --track-order 0:0,1:1"
- doexe = exe + u" -o '" + pout + u"' --cues 0:all --forced-track 0:no --default-duration 0:120000/1001fps --sync 1:330 --forced-track 1:no -a 1 -d 0 -S '" + pin + u"' --track-order 0:0,0:1"
+ pinaac=pin.replace(".avi",".aac")
+ ffmpegdo="ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'"
+ doexe0 = wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
+ doexe = exe +" -o '"+pout+"' --forced-track 0:no --timecodes '0:"+pintimecode+"' -d 0 -A -S '"+pin120+"' --sync 0:-250 --forced-track 0:no -a 0 -D -S '"+pinaac+"' --track-order 0:0,1:0"
else:
doexe = exe + u" -o '" + pout + u"' --cues 0:all --forced-track 0:no --forced-track 1:no -a 1 -d 0 -S '" + pin + u"' --track-order 0:0,0:1"
doexe = "nice -n 17 " + doexe
recdblist.printutf8(doexe)
logo=pout.replace(".mkv",".log")
+ txt=""
os.environ['LANG']="ja_JP.UTF-8"
- txt= doexe+"\n"
+ if doexe0!="":
+ recdblist.printutf8(ffmpegdo)
+ txt= ffmpegdo+"\n"
+ txt=txt+unicode(commands.getoutput(ffmpegdo.encode('utf-8')),'utf-8')
+ recdblist.printutf8(doexe0)
+ txt= doexe0+"\n"
+ txt=txt+unicode(commands.getoutput(doexe0.encode('utf-8')),'utf-8')
+ txt= txt+ doexe+"\n"
txt = txt+unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8')
txt = "\n####mkvmerge-log####\n"+txt
f=open(logo,'a')
if not os.path.exists(tpavi):
if os.path.exists(pin):
tpavi=pin
- avi2mp4(tpavi,pout)
-def avi2mp4(pin,pout):
+ isvfr=0
+ if re.search("v", opt):
+ isvfr=1
+ avi2mp4(tpavi,pout,isvfr)
+def avi2mp4(pin,pout,isvfr):
exe = configreader.getpath(u"MP4Box")
dir=os.path.split(pin)[0]
title=os.path.split(pin)[1]
title=os.path.splitext(title)[0]
audiopath=os.path.join(dir,title+u"_audio.mp3")
videopath=os.path.join(dir,title+u"_video.h264")
+ if isvfr==1:
+ ""
#doexe = exe.encode('utf-8') + u' \"' + pin.encode('utf-8') + u'\" \"' + pout.encode('utf-8') + u'\"'
exe1=exe+u" -aviraw audio \'"+pin+u"\'"
exe2=exe+u" -aviraw video \'"+pin+u"\'"
# Copyright (C) 2009 Yukikaze
import xml.dom.minidom
+import datetime
+
import zenhan
import chdb
import auto_rec
import recdb
-
+import rec10d
+import n_gram
+import recdblist
def getText(elm):
nodelist = elm.childNodes
rc = ""
rec10d.rec10db.new_epg_timeline(bctype)
for channel,start,stop,title,desc,longdesc,category in tvlists:
rec10d.rec10db.add_epg_timeline(bctype, channel, start, stop, title, desc, longdesc, category)
-def writemultichDB(bctype,chlists):
+def writemultichDB(chlists):
for ontv,dn in chlists:
rec10d.rec10db.update_chname_by_ontv_epg_ch(ontv, dn)
def xml2db_dom(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る
category=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("category")))
tch=chdb.ontvsearch(channel)
if tch!=None:
- if tch.get('bctype',"")==ubctype:
+ if tch.get('bctype',"")==bctype:
bt=bayes.get(tch['chtxt'],["","",0])
bt2=[bt[0]+title+" ",bt[1]+desc+" "+longdesc+" ",bt[2]+1]
bayes[tch['chtxt']]=bt2
tvlist.append([channel,start,stop,title,desc,longdesc,category])
p=auto_rec.calc_key(tch['chtxt'], title,desc+" "+longdesc)
if p>2000:
- recdb.add_auto_bayes(tch['chtxt'],title,start,stop,p)
+ bttt=datetime.datetime.strptime(start,"%Y%m%d%H%M%S")
+ bttt=bttt-datetime.timedelta(seconds=1200)
+ bttime=bttt.strftime("%Y-%m-%d %H:%M:%S")
+ ettt=datetime.datetime.strptime(stop,"%Y%m%d%H%M%S")
+ ettt=ettt+datetime.timedelta(seconds=1200)
+ ettime=ettt.strftime("%Y-%m-%d %H:%M:%S")
+ chs=rec10d.rec10db.select_bytime_all_timeline(bttime,ettime,tch['chtxt'])
+ p2=0
+ if len(chs)>0:
+ for ch in chs:
+ p2t=n_gram.trigram(ch['title'],title)
+ if p2t>p2:
+ p2=p2t
+ if p2<400:
+ recdb.add_auto_bayes(tch['chtxt'],title,start,stop,p)
dom.unlink()
if len(chlist) > 0:
writemultichDB(chlist)
chlist = []
if len(tvlist) > 0:
- writemultitvDB(tvlist)
+ writemultitvDB(bctype,tvlist)
tvlist = []
for ct,list in bayes.items():
auto_rec.update_recall(ct,list[0],list[1],list[2])
global h_ascii
global z_number
global h_number
-z_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !”#$%&’()*+,−./:;<=>?@[¥]^_‘{|}〜 "
-h_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ "
+z_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !”#$%&’()*+,−./:;<=>?@[¥]^_‘{|}〜 ."
+h_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ ."
z_number = u"0123456789"
h_number = u"0123456789"
z_alphabet = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #"