From c363a10d99acf08f3a298919ffd20c5f4660b666 Mon Sep 17 00:00:00 2001 From: gn64_jp Date: Fri, 3 Dec 2010 14:45:44 +0000 Subject: [PATCH] fix rename miss. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@780 4e526526-5e11-4fc0-8910-f8fd03428081 --- rec10/trunk/src/auto_move.py | 298 ++++---- rec10/trunk/src/auto_process.py | 570 ++++++++-------- rec10/trunk/src/auto_test.py | 86 +-- rec10/trunk/src/chdata.py | 98 +-- rec10/trunk/src/chdb.py | 131 ++-- rec10/trunk/src/classify.py | 286 ++++---- rec10/trunk/src/configreader.py | 60 +- rec10/trunk/src/configwriter.py | 64 +- rec10/trunk/src/epgdb.py | 524 +++++++------- rec10/trunk/src/install.py | 620 ++++++++--------- rec10/trunk/src/rec10d.py | 58 +- rec10/trunk/src/recdb.py | 170 +++-- rec10/trunk/src/recdblist.py | 322 ++++----- rec10/trunk/src/recque.py | 132 ++-- rec10/trunk/src/scan_ch.py | 228 +++---- rec10/trunk/src/status.py | 82 +-- rec10/trunk/src/timerec.py | 1428 +++++++++++++++++++-------------------- rec10/trunk/src/ts2epg.py | 94 +-- rec10/trunk/src/ts2x264.py | 956 +++++++++++++------------- rec10/trunk/src/tv2audio.py | 540 +++++++-------- rec10/trunk/src/tv2avi.py | 210 +++--- rec10/trunk/src/tv2mkv.py | 42 +- rec10/trunk/src/tv2mp4.py | 26 +- rec10/trunk/src/xml2db_dom.py | 246 +++---- 24 files changed, 3629 insertions(+), 3642 deletions(-) diff --git a/rec10/trunk/src/auto_move.py b/rec10/trunk/src/auto_move.py index dedaf6d..dedc2eb 100644 --- a/rec10/trunk/src/auto_move.py +++ b/rec10/trunk/src/auto_move.py @@ -1,149 +1,149 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze - -import glob -import os -import os.path -import re -import time -import shutil -import traceback -import sys - -import recdblist -import guess -def getTitle(title): - rT=re.compile("(.+)_(\d+)\Z") - tT=rT.match(title) - rT2=re.compile("(.+)_(.+)_(\d*)\Z")#_(aichi)_2010-02-06T01:59:00.mkv - tT2=rT2.match(title) - rT3=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+:\d+:\d+\Z")#_(aichi)_2010-02-06T01:59:00.mkv - tT3=rT3.match(title) - rT4=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+-\d+-\d+\Z")#_(aichi)_2010-02-06T01-59-00.mkv - tT4=rT4.match(title) - rT5=re.compile("(.+)_(.+)_(.+)\Z")#_(aichi)_2010-02-06T01-59-00.mkv - tT5=rT5.match(title) - ntitle=title - if tT : - ntitle=tT.group(1) - elif tT2: - ntitle=tT2.group(1) - elif tT3: - ntitle=tT3.group(1) - elif tT4: - ntitle=tT4.group(1) - elif tT5: - ntitle=tT5.group(1) - return ntitle -def searchFile(temppath,recpath,ext): - """ - 録画一時フォルダ内ファイルを検索 - """ - avilist = glob.glob(temppath + "/*"+ext) - ret=[] - for avif in avilist: - ##b25f is title.ts.b25 avi is title.avi - dir = os.path.split(avif)[0] - title = os.path.split(avif)[1] - title = title.replace(ext, "") - avipath = os.path.join(dir, title + ext) - if os.path.exists(avipath): - dtime = time.time()-os.path.getmtime(avipath) - dtime = int(dtime) - if dtime > 300: - if veryfySize(avipath): - ret.append(title) - return ret -def getMoveDestpath(title,temppath,recpath,ext): - dstpath=os.path.join(recpath,title+ext) - srcpath=os.path.join(temppath,title+ext) - if os.path.exists(dstpath): - if not os.path.getsize(dstpath) == os.path.getsize(srcpath): - gmtime=time.gmtime(os.path.getmtime(srcpath)) - iff="" - try: - iff=u"("+configreader.getEnvSetting("iff")+u")_" - if iff==u"()_": - iff = u"" - except: - iff="" - title=title+u"_"+iff+time.strftime("%Y-%m-%dT%H-%M-%S",gmtime) - else: - recdblist.printutf8(u"同サイズのファイルが存在します") - - return title -def getDelpath(temppath,title,addfp=1): - delpath=[os.path.join(temppath,title+".ts")] - delpath.append(os.path.join(temppath,title+".avi")) - if addfp==1: - delpath.append(os.path.join(temppath,title+".mp4")) - delpath.append(os.path.join(temppath,title+".mkv")) - delpath.append(os.path.join(temppath,title+".m2v")) - delpath.append(os.path.join(temppath,title+".120.avi")) - delpath.append(os.path.join(temppath,title+".timecode.txt")) - delpath.append(os.path.join(temppath,title+".aac")) - delpath.append(os.path.join(temppath,title+".ts.b25")) - delpath.append(os.path.join(temppath,title+".ts.tsmix")) - delpath.append(os.path.join(temppath,title+".ts.log")) - delpath.append(os.path.join(temppath,title+".sa.avi")) - delpath.append(os.path.join(temppath,title+".sa.avi.log")) - delpath.append(os.path.join(temppath,title+".log")) - return delpath -def veryfySize(path): - #vsize=[297,497,596,1196]#SD 30m 1h 1.5h 2h - vsize=[245,275,295,591,830] - vsize=vsize+[325,449,560,590,602,690,805,860,1014,1138,1237] - vsize=vsize+[261,535,540,616,740]#HD 30m 1h - #vsize=vsize+[381,895,447] - ret = 0 - for size in vsize: - if os.path.getsize(path)>(size-10)*1024*1024 and os.path.getsize(path)<(size+10)*1024*1024: - ret=1 - if os.path.getsize(path)>270*1024*1024: - ret=1 - return ret -def execMove(title,temppath,recpath,ext,autodel): - srcpath=os.path.join(temppath,title+ext) - sf=guess.searchFolder(title, recpath) - if sf!="": - destpath=os.path.join(sf,getMoveDestpath(title, temppath, sf, ext)+ext) - if os.path.exists(destpath): - if os.path.getsize(destpath) == os.path.getsize(srcpath): - recdblist.printutf8(u"同名同サイズのファイルが存在します。") - if autodel==1: - recdblist.printutf8(u"関連ファイルを削除します。") - delpath=getDelpath(temppath, title) - for dp in delpath: - try: - os.remove(dp) - "" - except: - "" - else: - recdblist.printutf8("moving now..") - recdblist.printutf8(srcpath+" : "+destpath) - print srcpath - shutil.copy(srcpath, destpath) - #shutil.copy(srcpath, destpath) - if autodel==1: - delpath=getDelpath(temppath, title) - for dp in delpath: - try: - os.remove(dp) - "" - except: - "" -def execDelete(title,temppath): - delpath=getDelpath(temppath, title,0) - recdblist.printutf8(title+u" 関連の一時ファイルを削除します") - for dp in delpath: - try: - if os.path.exists(dp): - recdblist.printutf8(dp) - os.remove(dp) - except Exception, inst: - print type(inst) - print str(inst) - print traceback.print_exc(file=sys.stdout) \ No newline at end of file +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze + +import glob +import os +import os.path +import re +import time +import shutil +import traceback +import sys + +import recdblist +import guess +def getTitle(title): + rT=re.compile("(.+)_(\d+)\Z") + tT=rT.match(title) + rT2=re.compile("(.+)_(.+)_(\d*)\Z")#_(aichi)_2010-02-06T01:59:00.mkv + tT2=rT2.match(title) + rT3=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+:\d+:\d+\Z")#_(aichi)_2010-02-06T01:59:00.mkv + tT3=rT3.match(title) + rT4=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+-\d+-\d+\Z")#_(aichi)_2010-02-06T01-59-00.mkv + tT4=rT4.match(title) + rT5=re.compile("(.+)_(.+)_(.+)\Z")#_(aichi)_2010-02-06T01-59-00.mkv + tT5=rT5.match(title) + ntitle=title + if tT : + ntitle=tT.group(1) + elif tT2: + ntitle=tT2.group(1) + elif tT3: + ntitle=tT3.group(1) + elif tT4: + ntitle=tT4.group(1) + elif tT5: + ntitle=tT5.group(1) + return ntitle +def searchFile(temppath,recpath,ext): + """ + 録画一時フォルダ内ファイルを検索 + """ + avilist = glob.glob(temppath + "/*"+ext) + ret=[] + for avif in avilist: + ##b25f is title.ts.b25 avi is title.avi + dir = os.path.split(avif)[0] + title = os.path.split(avif)[1] + title = title.replace(ext, "") + avipath = os.path.join(dir, title + ext) + if os.path.exists(avipath): + dtime = time.time()-os.path.getmtime(avipath) + dtime = int(dtime) + if dtime > 300: + if veryfySize(avipath): + ret.append(title) + return ret +def getMoveDestpath(title,temppath,recpath,ext): + dstpath=os.path.join(recpath,title+ext) + srcpath=os.path.join(temppath,title+ext) + if os.path.exists(dstpath): + if not os.path.getsize(dstpath) == os.path.getsize(srcpath): + gmtime=time.gmtime(os.path.getmtime(srcpath)) + iff="" + try: + iff=u"("+configreader.getConfEnv("iff")+u")_" + if iff==u"()_": + iff = u"" + except: + iff="" + title=title+u"_"+iff+time.strftime("%Y-%m-%dT%H-%M-%S",gmtime) + else: + recdblist.printutf8(u"同サイズのファイルが存在します") + + return title +def getDelpath(temppath,title,addfp=1): + delpath=[os.path.join(temppath,title+".ts")] + delpath.append(os.path.join(temppath,title+".avi")) + if addfp==1: + delpath.append(os.path.join(temppath,title+".mp4")) + delpath.append(os.path.join(temppath,title+".mkv")) + delpath.append(os.path.join(temppath,title+".m2v")) + delpath.append(os.path.join(temppath,title+".120.avi")) + delpath.append(os.path.join(temppath,title+".timecode.txt")) + delpath.append(os.path.join(temppath,title+".aac")) + delpath.append(os.path.join(temppath,title+".ts.b25")) + delpath.append(os.path.join(temppath,title+".ts.tsmix")) + delpath.append(os.path.join(temppath,title+".ts.log")) + delpath.append(os.path.join(temppath,title+".sa.avi")) + delpath.append(os.path.join(temppath,title+".sa.avi.log")) + delpath.append(os.path.join(temppath,title+".log")) + return delpath +def veryfySize(path): + #vsize=[297,497,596,1196]#SD 30m 1h 1.5h 2h + vsize=[245,275,295,591,830] + vsize=vsize+[325,449,560,590,602,690,805,860,1014,1138,1237] + vsize=vsize+[261,535,540,616,740]#HD 30m 1h + #vsize=vsize+[381,895,447] + ret = 0 + for size in vsize: + if os.path.getsize(path)>(size-10)*1024*1024 and os.path.getsize(path)<(size+10)*1024*1024: + ret=1 + if os.path.getsize(path)>270*1024*1024: + ret=1 + return ret +def execMove(title,temppath,recpath,ext,autodel): + srcpath=os.path.join(temppath,title+ext) + sf=guess.searchFolder(title, recpath) + if sf!="": + destpath=os.path.join(sf,getMoveDestpath(title, temppath, sf, ext)+ext) + if os.path.exists(destpath): + if os.path.getsize(destpath) == os.path.getsize(srcpath): + recdblist.printutf8(u"同名同サイズのファイルが存在します。") + if autodel==1: + recdblist.printutf8(u"関連ファイルを削除します。") + delpath=getDelpath(temppath, title) + for dp in delpath: + try: + os.remove(dp) + "" + except: + "" + else: + recdblist.printutf8("moving now..") + recdblist.printutf8(srcpath+" : "+destpath) + print srcpath + shutil.copy(srcpath, destpath) + #shutil.copy(srcpath, destpath) + if autodel==1: + delpath=getDelpath(temppath, title) + for dp in delpath: + try: + os.remove(dp) + "" + except: + "" +def execDelete(title,temppath): + delpath=getDelpath(temppath, title,0) + recdblist.printutf8(title+u" 関連の一時ファイルを削除します") + for dp in delpath: + try: + if os.path.exists(dp): + recdblist.printutf8(dp) + os.remove(dp) + except Exception, inst: + print type(inst) + print str(inst) + print traceback.print_exc(file=sys.stdout) diff --git a/rec10/trunk/src/auto_process.py b/rec10/trunk/src/auto_process.py index b289b49..d6733c5 100644 --- a/rec10/trunk/src/auto_process.py +++ b/rec10/trunk/src/auto_process.py @@ -1,285 +1,285 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import os -import glob -import time -import datetime -import commands -import re -import os.path - -import chdb -import status -import configreader -import recdblist -import rec10d -import tv2mp4 -import epgdb -def updateToMP4(path): - """ - !現在未使用! - 録画一時フォルダ内mp4ファイルを検索 - """ - avilist = glob.glob(path + "/*.avi") - mkvlist = glob.glob(path+"/*.mkv") - avilist=avilist+mkvlist - for avif in avilist: - if avif.rfind("sa.avi")==-1: - dir = os.path.split(avif)[0] - title = os.path.split(avif)[1] - title = title.replace(".avi", "") - title = title.replace(".mkv", "") - avipath = os.path.join(dir, title + ".avi") - mkvpath = os.path.join(dir, title + ".mkv") - mp4path = os.path.join(dir, title + ".mp4") - if not os.path.exists(mp4path): - if os.path.exists(avipath): - avidtime = int(time.time()-os.path.getmtime(avipath)) - if avidtime>300: - if os.path.exists(mkvpath): - mkvdtime = int(time.time()-os.path.getmtime(mkvpath)) - if mkvdtime>300: - recdblist.printutf8(mkvpath+":"+mp4path) - tv2mp4.mkv2mp4(mkvpath,mp4path) - else: - recdblist.printutf8(avipath+":"+mp4path) - tv2mp4.avi2mp4(avipath,mp4path) - else: - recdblist.printutf8(avipath+":"+mp4path) - tv2mp4.avi2mp4(avipath,mp4path) - else: - if not os.path.exists(avipath): - if os.path.exists(mkvpath): - mkvdtime = int(time.time()-os.path.getmtime(mkvpath)) - if mkvdtime>300: - recdblist.printutf8(mkvpath+":"+mp4path) - tv2mp4.mkv2mp4(mkvpath,mp4path) -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+mp4list - add=[] - tbtime=datetime.datetime.now()+datetime.timedelta(seconds=60) - tbtime2=datetime.datetime.now()+datetime.timedelta(seconds=1200) - for fn in filelist: - if os.path.exists(fn): - if fn.rfind("sa.avi")==-1 and fn.rfind(".120.avi")==-1 and os.path.getsize(fn)>1*1000*1000: - dir = os.path.split(fn)[0] - file = os.path.split(fn)[1] - title = os.path.splitext(file)[0] - title = unicode(title,'utf-8') - ext = os.path.splitext(file)[1] - if ext == ".b25": - title=title.replace(".ts","") - dbs=rec10d.rec10db.select_by_name_time_timeline(title,tbtime,tbtime2) - if len(dbs)==0: - proc=check_process(dir, title) - chtxtt=rec10d.rec10db.select_chtxt_by_title_timeline_log(title) - nchtxt="" - if chtxtt!=None: - nchtxt=chtxtt - if proc=="b25": - add.append([recdblist.REC_AUTO_SUGGEST_DECODE,title,nchtxt]) - elif proc=="ts": - add.append([recdblist.REC_AUTO_SUGGEST_ENCODE,title,nchtxt]) - elif proc =="264": - add.append([recdblist.REC_AUTO_SUGGEST_AVI2FP,title,nchtxt]) - #elif proc =="mp4": - # add.append([recdblist.REC_AUTO_SUGGEST_AP2FP,title,nchtxt]) - #print add - if len(add)>0: - rec10d.rec10db.new_auto_proc() - for a in add: - rec10d.rec10db.add_auto_proc(a[0],a[1],a[2]) - time.sleep(1) -""" - 処理がどの段階まで言ったのかを調査し返す。 - return - recording - b25 - b25decoding - tssplitting - ts - encoding - avi - mp4making - mp4 -""" -def check_process(path,title): - path1 = os.path.join(path,title+".mkv") - if os.path.exists(path1): - if int(time.time()-os.path.getmtime(path1))>300: - return "mkv" - else: - return "mkvmaking" - elif os.path.exists(os.path.join(path,title+".mp4")): - if int(time.time()-os.path.getmtime(os.path.join(path,title+".mp4")))>300: - return "mp4" - else: - return "mp4making" - elif os.path.exists(os.path.join(path,title+".264")): - if int(time.time()-os.path.getmtime(os.path.join(path,title+".264")))>300: - return "264" - else: - return "encoding" - elif os.path.exists(os.path.join(path,title+".ts.log")): - if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))<300: - return "encoding" - else: - return "ts" - elif os.path.exists(os.path.join(path,title+".ts")): - if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))>300: - return "ts" - else: - return "tssplitting" - elif os.path.exists(os.path.join(path,title+".sa.avi")): - if int(time.time()-os.path.getmtime(os.path.join(path,title+".sa.avi")))>300: - return "ts" - else: - return "tssplitting" - elif os.path.exists(os.path.join(path,title+".ts.b25")): - if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts.b25")))>300: - return "b25" - else: - return "recording" -def update_all_timeline_epg(): - now=datetime.datetime.now() - et=now+datetime.timedelta(days=7) - update_timeline_epg(now.strftime("%Y-%m-%d %H:%M:%S"), et.strftime("%Y-%m-%d %H:%M:%S")) -def update_timeline_epg(btime,etime): - update_timeline_epg_schedule(btime,etime) - update_timeline_dup(btime,etime) -def update_timeline_epg_schedule(btime,etime): - dbl=rec10d.rec10db.select_bytime_all_timeline(btime, etime) - #print dbl - for db in dbl: - ret=[] - #[chtxtt, title, btime, etime,exp,longexp,category] - if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS: - ret=epgdb.searchTime(db['title'], db['btime'], db['deltatime'], db['chtxt']) - if len(ret)>4 and len(ret[2])>18: - rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4]) - if not (db['btime'] == ret[2] and db['etime']==ret[3]): - rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") - else: - rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0") - else: - rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") - elif db['type']==recdblist.REC_RESERVE or db['type']==recdblist.REC_FINAL_RESERVE : - ret=epgdb.searchTime(db['title'], db['btime'],"5", db['chtxt']) - if len(ret)>4 and len(ret[2])>18: - rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4]) - if not (db['btime'] == ret[2] and db['etime']==ret[3]): - rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") - else: - rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0") - else: - rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") -def update_timeline_dup(epgbtime,epgetime): - dbl=rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime) - for db in dbl: - if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS: - dbn=epgdb.countEpgSchedule(db['epgbtime'], db['epgetime']) - try: - bctypet=chdb.searchFromCHtxt(db['chtxt'])['bctype'] - if bctypet.find("cs") > -1 or bctypet.find("bs") > -1 : - if dbn[1]>status.getRecordingMax()[1]: - rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") - else: - rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0") - else: - if dbn[0]>status.getRecordingMax()[0]: - rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") - else: - rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0") - except: - "" -def kill_dead_encode(path): - rawlist = glob.glob(path + "/*.264") - for fn in rawlist: - if int(time.time()-os.path.getmtime(fn))>3000: - #print fn - - tspath=unicode(fn.replace(".264",".ts"),'utf-8') - m2vpath=unicode(fn.replace(".264",".m2v"),'utf-8') - x264path=unicode(fn.replace(".264",".264"),'utf-8') - os.environ['LANG']="ja_JP.UTF-8" - - #ktmp=u"ps auxw | grep \""+tspath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'" - #kmmp=u"ps auxw | grep \""+m2vpath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'" - #ktmt=commands.getoutput(ktmp.encode('utf-8')) - #kmmt=commands.getoutput(kmmp.encode('utf-8')) - - ktmp=u"ps auxw | grep \""+x264path+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep x264 | awk '{print $2}'" - #recdblist.printutf8(ktmp) - ktmt=commands.getoutput(ktmp.encode('utf-8')) - #print ktmt - if len(ktmt)>0: - ktmt=ktmt[0] - try: - if int(ktmt)>0: - ktmp=u"kill -9 `"+ktmp+u"`" - #print ktmp - recdblist.printutf8(ktmp) - os.system(ktmp.encode('utf-8')) - except: - "" - """if len(kmmt)>0: - kmmt=kmmt[0] - try: - if int(kmmt)>0: - kmmp=u"kill -9 '"+kmmp+u"'" - os.system(kmmp.encode('utf-8')) - except: - """"" -def deltmpfile(path,title,ext): - level= 0##0:b25 1:ts(del tsmix and ts.b25) 5:x264(del 2 and so on) 10:mp4/mkv - smsize= 0 - if re.search(".ts",ext): - level= 1 - smsize = 100*1000*1000 - elif re.search(".264",ext): - level= 5 - smsize = 10*1000*1000 - elif re.search(".mp4",ext): - level = 10 - smsize = 10*1000*1000 - elif re.search(".mkv",ext): - level = 15 - smsize = 10*1000*1000 - dp=[] - if level > 0 : - if os.path.exists(os.path.join(path,title+".ts")) and os.path.exists(os.path.join(path,title+".ts.b25")): - if os.path.getsize(os.path.join(path,title+".ts"))*12>os.path.getsize(os.path.join(path,title+".ts.b25")): - dp.append(os.path.join(path,title+".ts.b25")) - elif os.path.getsize(os.path.join(path,title+".ts"))>200*1000*1000: - dp.append(os.path.join(path,title+".ts.b25")) - if level > 4 : - if configreader.getEnvSetting("remove_ts")=="1": - dp.append(os.path.join(path,title+".ts")) - if level > 9 : - dp.append(os.path.join(path,title+".avi")) - dp.append(os.path.join(path,title+".264")) - dp.append(os.path.join(path,title+".120.avi")) - dp.append(os.path.join(path,title+".noodml.avi")) - dp.append(os.path.join(path,title+".aac")) - dp.append(os.path.join(path,title+".m2v")) - dp.append(os.path.join(path,title+"_1.aac")) - dp.append(os.path.join(path,title+"_2.aac")) - dp.append(os.path.join(path,title+"_1.mp3")) - dp.append(os.path.join(path,title+"_2.mp3")) - dp.append(os.path.join(path,title+".srt")) - if level > 14 : - dp.append(os.path.join(path,title+".mp4")) - if os.path.exists(os.path.join(path,title+ext)): - if os.path.getsize(os.path.join(path,title+ext))>smsize: - for ip in dp: - try: - os.remove(ip) - except: - "" \ No newline at end of file +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import os +import glob +import time +import datetime +import commands +import re +import os.path + +import chdb +import status +import configreader +import recdblist +import rec10d +import tv2mp4 +import epgdb +def updateToMP4(path): + """ + !現在未使用! + 録画一時フォルダ内mp4ファイルを検索 + """ + avilist = glob.glob(path + "/*.avi") + mkvlist = glob.glob(path+"/*.mkv") + avilist=avilist+mkvlist + for avif in avilist: + if avif.rfind("sa.avi")==-1: + dir = os.path.split(avif)[0] + title = os.path.split(avif)[1] + title = title.replace(".avi", "") + title = title.replace(".mkv", "") + avipath = os.path.join(dir, title + ".avi") + mkvpath = os.path.join(dir, title + ".mkv") + mp4path = os.path.join(dir, title + ".mp4") + if not os.path.exists(mp4path): + if os.path.exists(avipath): + avidtime = int(time.time()-os.path.getmtime(avipath)) + if avidtime>300: + if os.path.exists(mkvpath): + mkvdtime = int(time.time()-os.path.getmtime(mkvpath)) + if mkvdtime>300: + recdblist.printutf8(mkvpath+":"+mp4path) + tv2mp4.mkv2mp4(mkvpath,mp4path) + else: + recdblist.printutf8(avipath+":"+mp4path) + tv2mp4.avi2mp4(avipath,mp4path) + else: + recdblist.printutf8(avipath+":"+mp4path) + tv2mp4.avi2mp4(avipath,mp4path) + else: + if not os.path.exists(avipath): + if os.path.exists(mkvpath): + mkvdtime = int(time.time()-os.path.getmtime(mkvpath)) + if mkvdtime>300: + recdblist.printutf8(mkvpath+":"+mp4path) + tv2mp4.mkv2mp4(mkvpath,mp4path) +def autoCheck(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+mp4list + add=[] + tbtime=datetime.datetime.now()+datetime.timedelta(seconds=60) + tbtime2=datetime.datetime.now()+datetime.timedelta(seconds=1200) + for fn in filelist: + if os.path.exists(fn): + if fn.rfind("sa.avi")==-1 and fn.rfind(".120.avi")==-1 and os.path.getsize(fn)>1*1000*1000: + dir = os.path.split(fn)[0] + file = os.path.split(fn)[1] + title = os.path.splitext(file)[0] + title = unicode(title,'utf-8') + ext = os.path.splitext(file)[1] + if ext == ".b25": + title=title.replace(".ts","") + dbs=rec10d.rec10db.select_by_name_time_timeline(title,tbtime,tbtime2) + if len(dbs)==0: + proc=checkProcess(dir, title) + chtxtt=rec10d.rec10db.select_chtxt_by_title_timeline_log(title) + nchtxt="" + if chtxtt!=None: + nchtxt=chtxtt + if proc=="b25": + add.append([recdblist.REC_AUTO_SUGGEST_DECODE,title,nchtxt]) + elif proc=="ts": + add.append([recdblist.REC_AUTO_SUGGEST_ENCODE,title,nchtxt]) + elif proc =="264": + add.append([recdblist.REC_AUTO_SUGGEST_AVI2FP,title,nchtxt]) + #elif proc =="mp4": + # add.append([recdblist.REC_AUTO_SUGGEST_AP2FP,title,nchtxt]) + #print add + if len(add)>0: + rec10d.rec10db.new_auto_proc() + for a in add: + rec10d.rec10db.add_auto_proc(a[0],a[1],a[2]) + time.sleep(1) +""" + 処理がどの段階まで言ったのかを調査し返す。 + return + recording + b25 + b25decoding + tssplitting + ts + encoding + avi + mp4making + mp4 +""" +def checkProcess(path,title): + path1 = os.path.join(path,title+".mkv") + if os.path.exists(path1): + if int(time.time()-os.path.getmtime(path1))>300: + return "mkv" + else: + return "mkvmaking" + elif os.path.exists(os.path.join(path,title+".mp4")): + if int(time.time()-os.path.getmtime(os.path.join(path,title+".mp4")))>300: + return "mp4" + else: + return "mp4making" + elif os.path.exists(os.path.join(path,title+".264")): + if int(time.time()-os.path.getmtime(os.path.join(path,title+".264")))>300: + return "264" + else: + return "encoding" + elif os.path.exists(os.path.join(path,title+".ts.log")): + if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))<300: + return "encoding" + else: + return "ts" + elif os.path.exists(os.path.join(path,title+".ts")): + if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))>300: + return "ts" + else: + return "tssplitting" + elif os.path.exists(os.path.join(path,title+".sa.avi")): + if int(time.time()-os.path.getmtime(os.path.join(path,title+".sa.avi")))>300: + return "ts" + else: + return "tssplitting" + elif os.path.exists(os.path.join(path,title+".ts.b25")): + if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts.b25")))>300: + return "b25" + else: + return "recording" +def update_all_timeline_epg(): + now=datetime.datetime.now() + et=now+datetime.timedelta(days=7) + update_timeline_epg(now.strftime("%Y-%m-%d %H:%M:%S"), et.strftime("%Y-%m-%d %H:%M:%S")) +def update_timeline_epg(btime,etime): + update_timeline_epg_schedule(btime,etime) + update_timeline_dup(btime,etime) +def update_timeline_epg_schedule(btime,etime): + dbl=rec10d.rec10db.select_bytime_all_timeline(btime, etime) + #print dbl + for db in dbl: + ret=[] + #[chtxtt, title, btime, etime,exp,longexp,category] + if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS: + ret=epgdb.searchTime(db['title'], db['btime'], db['deltatime'], db['chtxt']) + if len(ret)>4 and len(ret[2])>18: + rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4]) + if not (db['btime'] == ret[2] and db['etime']==ret[3]): + rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") + else: + rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0") + else: + rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") + elif db['type']==recdblist.REC_RESERVE or db['type']==recdblist.REC_FINAL_RESERVE : + ret=epgdb.searchTime(db['title'], db['btime'],"5", db['chtxt']) + if len(ret)>4 and len(ret[2])>18: + rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4]) + if not (db['btime'] == ret[2] and db['etime']==ret[3]): + rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") + else: + rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0") + else: + rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") +def update_timeline_dup(epgbtime,epgetime): + dbl=rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime) + for db in dbl: + if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS: + dbn=epgdb.countEpgSchedule(db['epgbtime'], db['epgetime']) + try: + bctypet=chdb.searchCHFromChtxt(db['chtxt'])['bctype'] + if bctypet.find("cs") > -1 or bctypet.find("bs") > -1 : + if dbn[1]>status.getRecordingMax()[1]: + rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") + else: + rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0") + else: + if dbn[0]>status.getRecordingMax()[0]: + rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1") + else: + rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0") + except: + "" +def killDeadEncode(path): + rawlist = glob.glob(path + "/*.264") + for fn in rawlist: + if int(time.time()-os.path.getmtime(fn))>3000: + #print fn + + tspath=unicode(fn.replace(".264",".ts"),'utf-8') + m2vpath=unicode(fn.replace(".264",".m2v"),'utf-8') + x264path=unicode(fn.replace(".264",".264"),'utf-8') + os.environ['LANG']="ja_JP.UTF-8" + + #ktmp=u"ps auxw | grep \""+tspath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'" + #kmmp=u"ps auxw | grep \""+m2vpath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'" + #ktmt=commands.getoutput(ktmp.encode('utf-8')) + #kmmt=commands.getoutput(kmmp.encode('utf-8')) + + ktmp=u"ps auxw | grep \""+x264path+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep x264 | awk '{print $2}'" + #recdblist.printutf8(ktmp) + ktmt=commands.getoutput(ktmp.encode('utf-8')) + #print ktmt + if len(ktmt)>0: + ktmt=ktmt[0] + try: + if int(ktmt)>0: + ktmp=u"kill -9 `"+ktmp+u"`" + #print ktmp + recdblist.printutf8(ktmp) + os.system(ktmp.encode('utf-8')) + except: + "" + """if len(kmmt)>0: + kmmt=kmmt[0] + try: + if int(kmmt)>0: + kmmp=u"kill -9 '"+kmmp+u"'" + os.system(kmmp.encode('utf-8')) + except: + """"" +def deleteTmpFile(path,title,ext): + level= 0##0:b25 1:ts(del tsmix and ts.b25) 5:x264(del 2 and so on) 10:mp4/mkv + smsize= 0 + if re.search(".ts",ext): + level= 1 + smsize = 100*1000*1000 + elif re.search(".264",ext): + level= 5 + smsize = 10*1000*1000 + elif re.search(".mp4",ext): + level = 10 + smsize = 10*1000*1000 + elif re.search(".mkv",ext): + level = 15 + smsize = 10*1000*1000 + dp=[] + if level > 0 : + if os.path.exists(os.path.join(path,title+".ts")) and os.path.exists(os.path.join(path,title+".ts.b25")): + if os.path.getsize(os.path.join(path,title+".ts"))*12>os.path.getsize(os.path.join(path,title+".ts.b25")): + dp.append(os.path.join(path,title+".ts.b25")) + elif os.path.getsize(os.path.join(path,title+".ts"))>200*1000*1000: + dp.append(os.path.join(path,title+".ts.b25")) + if level > 4 : + if configreader.getConfEnv("remove_ts")=="1": + dp.append(os.path.join(path,title+".ts")) + if level > 9 : + dp.append(os.path.join(path,title+".avi")) + dp.append(os.path.join(path,title+".264")) + dp.append(os.path.join(path,title+".120.avi")) + dp.append(os.path.join(path,title+".noodml.avi")) + dp.append(os.path.join(path,title+".aac")) + dp.append(os.path.join(path,title+".m2v")) + dp.append(os.path.join(path,title+"_1.aac")) + dp.append(os.path.join(path,title+"_2.aac")) + dp.append(os.path.join(path,title+"_1.mp3")) + dp.append(os.path.join(path,title+"_2.mp3")) + dp.append(os.path.join(path,title+".srt")) + if level > 14 : + dp.append(os.path.join(path,title+".mp4")) + if os.path.exists(os.path.join(path,title+ext)): + if os.path.getsize(os.path.join(path,title+ext))>smsize: + for ip in dp: + try: + os.remove(ip) + except: + "" diff --git a/rec10/trunk/src/auto_test.py b/rec10/trunk/src/auto_test.py index 75ff69e..c76eae3 100644 --- a/rec10/trunk/src/auto_test.py +++ b/rec10/trunk/src/auto_test.py @@ -1,43 +1,43 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import os -import os.path -import time -import optparse -import sys -import datetime - -import configreader -import chdb -import tv2mp4 -import tv2ts -def testAllCHEncode(option,stime): - chl=chdb.getAll() - print chl - path= configreader.getPathSetting("test") - tpath=os.path.join(path, "encode_test") - if not os.path.exists(tpath): - os.mkdir(tpath) - dnowt=datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")+"_"+option+"" - tpatht=os.path.join(tpath,dnowt) - if not os.path.exists(tpatht): - os.mkdir(tpatht) - if len(chl)>0: - for t in chl: - print t - pathname=os.path.join(tpatht,t['chtxt']) - print pathname - tv2ts.tv2ts(pathname+".ts",t['ch'],t['csch'], stime) - tv2mp4.ts2mp4(pathname+".ts", pathname+".mp4", option) - time.sleep(2) -if __name__ == "__main__": - usage="usage: " - version="%prog 0.9.7" - parser=optparse.OptionParser(usage=usage,version=version) - parser.add_option("-e","--Encode",action="store",type="string",dest="encode_option",default="",metavar="TITLE",help="encode test(option)") - (opts,args)=parser.parse_args(sys.argv) - if opts.encode_option != "":##-sの場合 - print "test_all_ch_encode" - testAllCHEncode(opts.encode_option, "10") \ No newline at end of file +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import os +import os.path +import time +import optparse +import sys +import datetime + +import configreader +import chdb +import tv2mp4 +import tv2ts +def testAllCHEncode(option,stime): + chl=chdb.getAllCH() + print chl + path= configreader.getConfPath("test") + tpath=os.path.join(path, "encode_test") + if not os.path.exists(tpath): + os.mkdir(tpath) + dnowt=datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")+"_"+option+"" + tpatht=os.path.join(tpath,dnowt) + if not os.path.exists(tpatht): + os.mkdir(tpatht) + if len(chl)>0: + for t in chl: + print t + pathname=os.path.join(tpatht,t['chtxt']) + print pathname + tv2ts.tv2ts(pathname+".ts",t['ch'],t['csch'], stime) + tv2mp4.ts2mp4(pathname+".ts", pathname+".mp4", option) + time.sleep(2) +if __name__ == "__main__": + usage="usage: " + version="%prog 0.9.7" + parser=optparse.OptionParser(usage=usage,version=version) + parser.add_option("-e","--Encode",action="store",type="string",dest="encode_option",default="",metavar="TITLE",help="encode test(option)") + (opts,args)=parser.parse_args(sys.argv) + if opts.encode_option != "":##-sの場合 + print "test_all_ch_encode" + testAllCHEncode(opts.encode_option, "10") diff --git a/rec10/trunk/src/chdata.py b/rec10/trunk/src/chdata.py index ae2a1b4..97e73cf 100644 --- a/rec10/trunk/src/chdata.py +++ b/rec10/trunk/src/chdata.py @@ -1,49 +1,49 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import os.path -import configreader -import xml.dom.minidom - -import rec10d - -path = str(os.path.dirname(os.path.abspath(__file__))) + "/" - -def chAdd(bctype, chtxt, ch, csch):#すべて文字列 - rec10d.rec10db.add_epg_ch(bctype,chtxt, ch, csch, u"2010-01-01 00:00:00") -def addCHlist(cl): - if len(cl)>0: - for c in cl: - chAdd(c[0],c[1],c[2],c[3]) -def newCHdata(bs,cs): - rec10d.rec10db.new_epg_ch() - addCHlist(getCHlist(os.path.join(path,"chlist.xml"))) - if bs==1: - #bs放送の設定 全国共通のはず - addCHlist(getCHlist(os.path.join(path,"chlist_bs.xml"))) - if cs==1: - #CS放送(スカパーe2)主に基本パックに入ってるものを中心に - addCHlist(getCHlist(os.path.join(path,"chlist_cs.xml"))) -def newAllCHdata(): - bs=0 - cs=0 - try: - bs=int(configreader.getEnvSetting("bs")) - cs=int(configreader.getEnvSetting("cs")) - except: - "" - newCHdata(bs,cs) -def getCHlist(xmlpath): - dom=xml.dom.minidom.parse(file(xmlpath)) - chlist=[] - for ch in dom.getElementsByTagName('channel'): - bctype=ch.getAttribute("bctype") - chd=ch.getAttribute("ch") - csch=ch.getAttribute("csch") - chtxt=ch.getAttribute("chtxt") - ontv=ch.getAttribute("ontvcode") - chlist.append([bctype,ontv,chtxt,chd,csch]) - return chlist -if __name__ == "__main__": - newAllCHdata() \ No newline at end of file +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import os.path +import configreader +import xml.dom.minidom + +import rec10d + +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" + +def chAdd(bctype, chtxt, ch, csch):#すべて文字列 + rec10d.rec10db.add_epg_ch(bctype,chtxt, ch, csch, u"2010-01-01 00:00:00") +def addCHlist(cl): + if len(cl)>0: + for c in cl: + chAdd(c[0],c[1],c[2],c[3]) +def newChdata(bs,cs): + rec10d.rec10db.new_epg_ch() + addCHlist(getCHlist(os.path.join(path,"chlist.xml"))) + if bs==1: + #bs放送の設定 全国共通のはず + addCHlist(getCHlist(os.path.join(path,"chlist_bs.xml"))) + if cs==1: + #CS放送(スカパーe2)主に基本パックに入ってるものを中心に + chlistadd(getChList(os.path.join(path,"chlist_cs.xml"))) +def newChdataAll(): + bs=0 + cs=0 + try: + bs=int(configreader.getConfEnv("bs")) + cs=int(configreader.getConfEnv("cs")) + except: + "" + newChdata(bs,cs) +def getChList(xmlpath): + dom=xml.dom.minidom.parse(file(xmlpath)) + chlist=[] + for ch in dom.getElementsByTagName('channel'): + bctype=ch.getAttribute("bctype") + chd=ch.getAttribute("ch") + csch=ch.getAttribute("csch") + chtxt=ch.getAttribute("chtxt") + ontv=ch.getAttribute("ontvcode") + chlist.append([bctype,ontv,chtxt,chd,csch]) + return chlist +if __name__ == "__main__": + newChdataAll() diff --git a/rec10/trunk/src/chdb.py b/rec10/trunk/src/chdb.py index 1b76b34..56ffd7e 100644 --- a/rec10/trunk/src/chdb.py +++ b/rec10/trunk/src/chdb.py @@ -1,67 +1,64 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze - # モジュール属性 argv を取得するため -import rec10d - -def searchFromCHtxt(chtxtin): - chtxtt=chtxtin.replace("_0","_%") - ret = [] - for datum in rec10d.rec10db.select_by_chtxt_epg_ch(chtxtt): - rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3], 'update':datum[4]} - ret.append(rett) - if len(ret) == 0: - ret.append(None) - return ret[0] -def getChCSchFromCHtxt(chtxt): - ret = {'csch':chtxt.split("_")[1],'ch':chtxt.split("_")[0]} - return ret -def searchFromBctype(bctypein): - ret = [] - for datum in rec10d.rec10db.select_by_bctype_epg_ch(bctypein): - rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3], 'update':datum[4]} - ret.append(rett) - if len(ret) == 0: - ret.append(None) - return ret[0] -def searchFromCH(chin): - ret = [] - for datum in rec10d.rec10db.select_by_ch_epg_ch(chin): - rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3], 'update':datum[4]} - ret.append(rett) - if len(ret) == 0: - ret.append(None) - return ret[0] -def getAll(): - ret = [] - for datum in rec10d.rec10db.select_all_epg_ch(): - rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3], 'update':datum[4]} - ret.append(rett) - if len(ret) == 0: - ret.append(None) - return ret -def update(): - ret = [] - CSupdate = 0 - CS2update = 0 - BSupdate = 0 - HUupdate = 0 - rec10d.rec10db.set_new_status("8") - for datum in rec10d.rec10db.select_get_update_epg_ch("6"): - bctype = datum[0] - if bctype == "cs1" or bctype == u"cs1": - if CSupdate == 0: - ret.append(u"cs1") - CSupdate = 1 - elif bctype == "cs2" or bctype == u"cs2": - if CS2update == 0: - ret.append(u"cs2") - CS2update = 1 - elif bctype == "bs" or bctype == u"bs": - if BSupdate == 0: - ret.append(u"bs") - BSupdate = 1 - else: - ret.append(bctype) - return ret \ No newline at end of file +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze + # モジュール属性 argv を取得するため +import rec10d + +def searchCHFromChtxt(chtxtin): + chtxtt=chtxtin.replace("_0","_%") + ret = [] + for datum in rec10d.rec10db.select_by_chtxt_epg_ch(chtxtt): + rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3], 'update':datum[4]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret[0] +def searchCHFromBctype(bctypein): + ret = [] + for datum in rec10d.rec10db.select_by_bctype_epg_ch(bctypein): + rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3], 'update':datum[4]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret[0] +def searchCHFromCh(chin): + ret = [] + for datum in rec10d.rec10db.select_by_ch_epg_ch(chin): + rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3], 'update':datum[4]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret[0] +def getAllCH(): + ret = [] + for datum in rec10d.rec10db.select_all_epg_ch(): + rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3], 'update':datum[4]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret +def update(): + ret = [] + CSupdate = 0 + CS2update = 0 + BSupdate = 0 + HUupdate = 0 + rec10d.rec10db.set_new_status("8") + for datum in rec10d.rec10db.select_get_update_epg_ch("6"): + bctype = datum[0] + if bctype == "cs1" or bctype == u"cs1": + if CSupdate == 0: + ret.append(u"cs1") + CSupdate = 1 + elif bctype == "cs2" or bctype == u"cs2": + if CS2update == 0: + ret.append(u"cs2") + CS2update = 1 + elif bctype == "bs" or bctype == u"bs": + if BSupdate == 0: + ret.append(u"bs") + BSupdate = 1 + else: + ret.append(bctype) + return ret diff --git a/rec10/trunk/src/classify.py b/rec10/trunk/src/classify.py index 39e4217..b967010 100644 --- a/rec10/trunk/src/classify.py +++ b/rec10/trunk/src/classify.py @@ -1,143 +1,143 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze - -import os -import os.path -import optparse -import sys - -import configreader -import recdblist -import auto_move -import guess -recordedpath=unicode(configreader.getpath("recorded"),'utf-8') -recpath=unicode(configreader.getpath("recpath"),'utf-8') - -if __name__ == "__main__": - usage="usage: %prog read -h" - version="%prog 0.9.4" - parser=optparse.OptionParser(usage=usage,version=version) - parser.add_option("-s","--search",action="store",type="string",dest="ltitle",default="",metavar="TITLE",help="test to search where the title should be contained(test for -e)") - parser.add_option("-A","--Auto",action="store_true",dest="auto",default=False,help="auto classifying mode(not a test)") - parser.add_option("-D","--Delete",action="store_true",dest="delete",default=False,help="auto delete tempfile mode(not a test)") - parser.add_option("-e","--exec",action="store",type="string",dest="etitle",default="",metavar="TITLE",help="exec move(not a test)") - parser.add_option("-l","--list",action="store_true",dest="list",default=False,help="File listing mode(test for -A)") - parser.add_option("-t","--tssearch",action="store_true",dest="tssearch",default=False,help="Ts move auto search") - parser.add_option("-T","--Tsmove",action="store_true",dest="tsmove",default=False,help="Ts auto move.") - parser.add_option("-S","--SeriesNum",action="store",type="string",dest="seriespath",default="",metavar="TITLE",help="Search Series Number in the path.") - #parser.add_option("-f","--filenumlist",action="store_true",dest="filenumlist",default=False,help="Guess Program Number.") - - (opts,args)=parser.parse_args(sys.argv) - if opts.ltitle!="":##-sの場合 - ltitle=unicode(opts.ltitle,'utf-8') - sf=guess.searchFolder(ltitle, recordedpath) - print "###MKV###" - recdblist.printutf8(os.path.join(sf, auto_move.get_move_dest_path(ltitle,recpath,sf,".mkv")+".mkv"),verbose_level=100) - print "\n" - print "###MP4###" - recdblist.printutf8(os.path.join(sf, auto_move.get_move_dest_path(ltitle,recpath,sf,".mp4")+".mp4"),verbose_level=100) - print "\n" - elif opts.auto:##-A の場合 - sa=auto_move.search_file(recpath, recordedpath, ".mkv") - for t in sa: - recdblist.printutf8(u"自動推測実行中-MKV",verbose_level=100) - sf=guess.searchFolder(t,recordedpath) - if sf!="": - recdblist.printutf8(u"移動先",verbose_level=100) - recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mkv")+".mkv"),verbose_level=100) - recdblist.printutf8(u"実行中",verbose_level=100) - auto_move.execMove(t, recpath, recordedpath,".mkv",1) - else: - recdblist.printutf8(t+" can't find matching folder",verbose_level=100) - sa=auto_move.searchFile(recpath, recordedpath, ".mp4") - for t in sa: - recdblist.printutf8(u"自動推測実行中-MP4",verbose_level=100) - sf=guess.searchFolder(t,recordedpath) - if sf!="": - recdblist.printutf8(u"移動先",verbose_level=100) - recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mp4")+".mp4"),verbose_level=100) - recdblist.printutf8(u"実行中",verbose_level=100) - auto_move.execMove(t, recpath, recordedpath,".mp4",1) - else: - recdblist.printutf8(t+" can't find matching folder",verbose_level=100) - elif opts.delete:##-Dの場合 - sa=auto_move.search_file(recpath, recordedpath,".mkv") - for t in sa: - auto_move.execDelete(t, recpath) - sa=auto_move.searchFile(recpath, recordedpath,".mp4") - for t in sa: - auto_move.execDelete(t, recpath) - elif opts.list:##-lの場合 - sa=auto_move.search_file(recpath, recordedpath,".mkv") - for t in sa: - sf=guess.searchFolder(t,recordedpath) - if sf!="": - recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mkv")+".mkv"),verbose_level=100) - sa=auto_move.searchFile(recpath, recordedpath,".mp4") - for t in sa: - sf=guess.searchFolder(t,recordedpath) - if sf!="": - recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mp4")+".mp4"),verbose_level=100) - elif opts.etitle!="": - if os.path.exists(os.path.join(recpath, etitle+".mkv")): - auto_move.execMove(etitle,recpath, recordedpath,".mkv",1) - elif os.path.exists(os.path.join(recpath, etitle+".mp4")): - auto_move.execMove(etitle,recpath, recordedpath,".mp4",1) - elif opts.tssearch:## -tの場合 - tsmovepath="" - try: - tsmovepath=unicode(configreader.getpath("ts_movepath"),'utf-8') - except: - "" - if tsmovepath!="": - sa=auto_move.searchFile(recpath, tsmovepath,".ts") - for t in sa: - sf=guess.searchFolder(t,tsmovepath,700) - if sf!="": - recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".ts")+".ts")) - print "\n" - sa=auto_move.searchFile(recpath, tsmovepath,".ts") - else: - recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。",verbose_level=100) - elif opts.tsmove:##-Tの場合 - tsmovepath="" - try: - tsmovepath=unicode(configreader.getpath("ts_movepath"),'utf-8') - except: - "" - if tsmovepath!="": - sa=auto_move.search_file(recpath, tsmovepath,".ts") - searchFilein sa: - sf=guess.searchFolder(t,tsmovepath,700) - if sf!="": - recdblist.printutf8(u"移動先",verbose_level=100) - recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".ts")+".ts"),verbose_level=100) - recdblist.printutf8(u"実行中",verbose_level=100) - auto_move.execMove(t, recpath, tsmovepath,".ts",0) - sa=auto_move.search_file(recpath, tsmovepath,".ts") - else: - recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。",verbose_level=100) - elif opts.seriespath!="":##-Sの場合##与えられたパスにシリーズがそろっているかを調べる。 - ss=guess.detSeriesNum(opts.seriespath) - for sstitle, ssv in ss.iteritems(): - if len(ssv)>0: - maxt=0 - bt=0 - alr=[] - for ssi,ssiv in ssv.iteritems(): - alr.append(ssi) - if maxt0: + maxt=0 + bt=0 + alr=[] + for ssi,ssiv in ssv.iteritems(): + alr.append(ssi) + if maxt 2 * 60 * 60: - ts2epg.write(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.getChCSchFromCHtxt(chtxt)['ch']) - xml2db_dom.xml2db_dom(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.searchFromCHtxt(chtxt)['bctype']) -def updateForBctype(bctype): - bctypel = chdb.searchFromBctype(bctype) - #print bctype - try: - ts2epg.write(tmppath + bctype + "epgdata.xml", chdb.searchFromBctype(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: - recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200) - xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype) - rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "2") -def searchTime(titletxt, timet, deltatime, chtxt): - time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S") - ret = [] - deltatime = int(deltatime) - beforetime = time.strftime("%Y%m%d%H%M%S") - beforetime = time - datetime.timedelta(hours=deltatime) - aftertime = time + datetime.timedelta(hours=deltatime) - beforetime = beforetime.strftime("%Y%m%d%H%M%S") - aftertime = aftertime.strftime("%Y%m%d%H%M%S") - one = ["", "", "", "","","",""] - tempt = 0 - chtxtt=chtxt.replace("_0","_%") - d = rec10d.rec10db.select_by_time_ngram_epg_timeline(beforetime, aftertime, chtxtt) - for chtxtt, title, start, stop ,exp,longexp,category in d: - #recdblist.printutf8(chtxtt+":"+title+":"+start+":"+stop) - p = n_gram.bigram(titletxt, title) - btime = start - btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00" - etime = stop - etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00" - bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") - dt = bt-time - dt = abs(dt) - dt = 24 * 60 * 60 * dt.days + dt.seconds + 1 - p = p * 90 - dt = 1000-1000 * dt / (7 * 24 * 60 * 60) - if p > 0: - p = p + dt - if p > tempt: - one = [chtxtt, title, btime, etime,exp,longexp,category] - tempt = p - if p > 0: - #recdblist.printutf8(title + ":" + str(p) + u"点") - "" - ret = one - #print ret - return ret -def searchTimeAuto(keytxt, timet, deltatime): - time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S") - ret = [] - deltatime = int(deltatime) - 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_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" - etime = stop - etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00" - ret.append([chtxtt, title, btime, etime,exp,longexp,category]) - return ret -def countSchedule(btime,etime): - """ - return rec num (int return[0]:TE /int return[1]:BS/CS) - """ - def cmpare(x, y): - xt = x - yt = y - if xt > yt: - return -1 - elif xt == yt: - return 0 - else: - return 1 - dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime) - times = [] - btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") - etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") - for dl in dls: - dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S") - dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S") - if dd1 < btd: - dd1 = btd - if dd2 > etd: - dd2 = etd - times.append(dd1) - times.append(dd2) - times = list(set(times)) - times.sort(cmpare) - times.reverse() - retcount = [0, 0] - for i in xrange(0, len(times)-2, 1): - bt1 = times[i] - et1 = times[i + 1] - btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S") - etime1 = et1.strftime("%Y-%m-%d %H:%M:%S") - ret1 = rec10d.rec10db.count_schedule_timeline(btime1, etime1) - if retcount[0] < ret1[0]: - retcount[0] = ret1[0] - if retcount[1] < ret1[1]: - retcount[1] = ret1[1] - return retcount - -def searchSchedule(btime,etime): - """ - return rec num (int return[0]:TE /int return[1]:BS/CS) - """ - def cmpare(x, y): - xt = x - yt = y - if xt > yt: - return -1 - elif xt == yt: - return 0 - else: - return 1 - dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime) - times = [] - btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") - etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") - for dl in dls: - dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S") - dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S") - if dd1 < btd: - dd1 = btd - if dd2 > etd: - dd2 = etd - times.append(dd1) - times.append(dd2) - times = list(set(times)) - times.sort(cmpare) - times.reverse() - ret=[] - for i in xrange(0, len(times)-2, 1): - bt1 = times[i] - et1 = times[i + 1] - btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S") - etime1 = et1.strftime("%Y-%m-%d %H:%M:%S") - ret1 = rec10d.rec10db.search_schedule_timeline(btime1, etime1) - ret.append(ret1) - ret = list(set(ret)) - return ret - -def countEpgSchedule(epgbtime,epgetime): - """ - return rec num (int return[0]:TE /int return[1]:BS/CS) - """ - def cmpare(x, y): - xt = x - yt = y - if xt > yt: - return -1 - elif xt == yt: - return 0 - else: - return 1 - dls = rec10d.rec10db.select_byepgtime_over_timeline(epgbtime, epgetime) - #print dls - times = [] - btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S") - etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S") - for dl in dls: - dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S") - dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S") - if dd1 < btd: - dd1 = btd - if dd2 > etd: - dd2 = etd - times.append(dd1) - times.append(dd2) - times = list(set(times)) - times.sort(cmpare) - times.reverse() - retcount = [0, 0] - for i in xrange(0, len(times)-1, 1): - bt1 = times[i] - et1 = times[i + 1] - epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S") - epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S") - ret1 = rec10d.rec10db.count_epgschedule_timeline(epgbtime1, epgetime1) - if retcount[0] < ret1[0]: - retcount[0] = ret1[0] - if retcount[1] < ret1[1]: - retcount[1] = ret1[1] - return retcount -def searchEpgSchedule(epgbtime,epgetime): - """ - return rec num (int return[0]:TE /int return[1]:BS/CS) - """ - def cmpare(x, y): - xt = x - yt = y - if xt > yt: - return -1 - elif xt == yt: - return 0 - else: - return 1 - dls = rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime) - times = [] - btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S") - etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S") - for dl in dls: - dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S") - dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S") - if dd1 < btd: - dd1 = btd - if dd2 > etd: - dd2 = etd - times.append(dd1) - times.append(dd2) - times = list(set(times)) - times.sort(cmpare) - times.reverse() - ret=[] - for i in xrange(0, len(times)-2, 1): - bt1 = times[i] - et1 = times[i + 1] - epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S") - epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S") - ret1 = rec10d.rec10db.search_epgschedule_timeline(epgbtime1, epgetime1) - ret.append(ret1) - ret = list(set(ret)) - return ret \ No newline at end of file +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import datetime +import os +import shutil +import time +import os.path +import traceback + +import chdb +import n_gram +import rec10d +import ts2epg +import xml2db_dom +import configreader +import recdblist +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" +tmppath = configreader.getConfPath("tmp")+"/" +if tmppath=="/": + tmppath=path +def update(chtxt): + recdblist.printutf8(chtxt) + tnow = datetime.datetime.now() + try: + lastup = datetime.datetime.strptime(chdb.searchCHFromChtxt(chtxt)[0]['update'], "%Y-%m-%d %H:%M:%S") + except: + 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 + if dt > 2 * 60 * 60: + ts2epg.writeEpgXML(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.searchCHFromChtxt(chtxt)['ch']) + xml2db_dom.xml2db_dom(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.searchCHFromChtxt(chtxt)['bctype']) +def updatebc(bctype): + bctypel = chdb.searchCHFromBctype(bctype) + #print bctype + try: + ts2epg.writeEpgXML(tmppath + bctype + "epgdata.xml", chdb.searchCHFromBctype(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: + recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200) + xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype) + rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "2") +def searchTime(titletxt, timet, deltatime, chtxt): + time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S") + ret = [] + deltatime = int(deltatime) + beforetime = time.strftime("%Y%m%d%H%M%S") + beforetime = time - datetime.timedelta(hours=deltatime) + aftertime = time + datetime.timedelta(hours=deltatime) + beforetime = beforetime.strftime("%Y%m%d%H%M%S") + aftertime = aftertime.strftime("%Y%m%d%H%M%S") + one = ["", "", "", "","","",""] + tempt = 0 + chtxtt=chtxt.replace("_0","_%") + d = rec10d.rec10db.select_by_time_ngram_epg_timeline(beforetime, aftertime, chtxtt) + for chtxtt, title, start, stop ,exp,longexp,category in d: + #recdblist.printutf8(chtxtt+":"+title+":"+start+":"+stop) + p = n_gram.bigram(titletxt, title) + btime = start + btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00" + etime = stop + etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00" + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + dt = bt-time + dt = abs(dt) + dt = 24 * 60 * 60 * dt.days + dt.seconds + 1 + p = p * 90 + dt = 1000-1000 * dt / (7 * 24 * 60 * 60) + if p > 0: + p = p + dt + if p > tempt: + one = [chtxtt, title, btime, etime,exp,longexp,category] + tempt = p + if p > 0: + #recdblist.printutf8(title + ":" + str(p) + u"点") + "" + ret = one + #print ret + return ret +def searchTimeAuto(keytxt, timet, deltatime): + time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S") + ret = [] + deltatime = int(deltatime) + 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_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" + etime = stop + etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00" + ret.append([chtxtt, title, btime, etime,exp,longexp,category]) + return ret +def countSchedule(btime,etime): + """ + return rec num (int return[0]:TE /int return[1]:BS/CS) + """ + def cmpare(x, y): + xt = x + yt = y + if xt > yt: + return -1 + elif xt == yt: + return 0 + else: + return 1 + dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime) + times = [] + btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + for dl in dls: + dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S") + dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S") + if dd1 < btd: + dd1 = btd + if dd2 > etd: + dd2 = etd + times.append(dd1) + times.append(dd2) + times = list(set(times)) + times.sort(cmpare) + times.reverse() + retcount = [0, 0] + for i in xrange(0, len(times)-2, 1): + bt1 = times[i] + et1 = times[i + 1] + btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S") + etime1 = et1.strftime("%Y-%m-%d %H:%M:%S") + ret1 = rec10d.rec10db.count_schedule_timeline(btime1, etime1) + if retcount[0] < ret1[0]: + retcount[0] = ret1[0] + if retcount[1] < ret1[1]: + retcount[1] = ret1[1] + return retcount + +def searchSchedule(btime,etime): + """ + return rec num (int return[0]:TE /int return[1]:BS/CS) + """ + def cmpare(x, y): + xt = x + yt = y + if xt > yt: + return -1 + elif xt == yt: + return 0 + else: + return 1 + dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime) + times = [] + btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + for dl in dls: + dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S") + dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S") + if dd1 < btd: + dd1 = btd + if dd2 > etd: + dd2 = etd + times.append(dd1) + times.append(dd2) + times = list(set(times)) + times.sort(cmpare) + times.reverse() + ret=[] + for i in xrange(0, len(times)-2, 1): + bt1 = times[i] + et1 = times[i + 1] + btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S") + etime1 = et1.strftime("%Y-%m-%d %H:%M:%S") + ret1 = rec10d.rec10db.search_schedule_timeline(btime1, etime1) + ret.append(ret1) + ret = list(set(ret)) + return ret + +def countEpgSchedule(epgbtime,epgetime): + """ + return rec num (int return[0]:TE /int return[1]:BS/CS) + """ + def cmpare(x, y): + xt = x + yt = y + if xt > yt: + return -1 + elif xt == yt: + return 0 + else: + return 1 + dls = rec10d.rec10db.select_byepgtime_over_timeline(epgbtime, epgetime) + #print dls + times = [] + btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S") + etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S") + for dl in dls: + dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S") + dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S") + if dd1 < btd: + dd1 = btd + if dd2 > etd: + dd2 = etd + times.append(dd1) + times.append(dd2) + times = list(set(times)) + times.sort(cmpare) + times.reverse() + retcount = [0, 0] + for i in xrange(0, len(times)-1, 1): + bt1 = times[i] + et1 = times[i + 1] + epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S") + epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S") + ret1 = rec10d.rec10db.count_epgschedule_timeline(epgbtime1, epgetime1) + if retcount[0] < ret1[0]: + retcount[0] = ret1[0] + if retcount[1] < ret1[1]: + retcount[1] = ret1[1] + return retcount +def searchEpgSchedule(epgbtime,epgetime): + """ + return rec num (int return[0]:TE /int return[1]:BS/CS) + """ + def cmpare(x, y): + xt = x + yt = y + if xt > yt: + return -1 + elif xt == yt: + return 0 + else: + return 1 + dls = rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime) + times = [] + btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S") + etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S") + for dl in dls: + dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S") + dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S") + if dd1 < btd: + dd1 = btd + if dd2 > etd: + dd2 = etd + times.append(dd1) + times.append(dd2) + times = list(set(times)) + times.sort(cmpare) + times.reverse() + ret=[] + for i in xrange(0, len(times)-2, 1): + bt1 = times[i] + et1 = times[i + 1] + epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S") + epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S") + ret1 = rec10d.rec10db.search_epgschedule_timeline(epgbtime1, epgetime1) + ret.append(ret1) + ret = list(set(ret)) + return ret diff --git a/rec10/trunk/src/install.py b/rec10/trunk/src/install.py index daac879..ef9f3b4 100644 --- a/rec10/trunk/src/install.py +++ b/rec10/trunk/src/install.py @@ -1,310 +1,310 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import time -import os.path -import ConfigParser -import sys -import commands -import configwriter -import shutil -import traceback - -import recdblist -def printutf8(str): - print str.encode('utf-8') -def install(): - version = recdblist.version - recdblist.printutf8(u"rec10の環境インストールを開始します。",verbose_level=100) - time.sleep(1) - recdblist.printutf8(u"環境インストール処理中・・・",verbose_level=100) - path = str(os.path.dirname(os.path.abspath(__file__))) - confp = ConfigParser.SafeConfigParser() - Conf = 'rec10.conf' - confpath="" - if os.path.exists(os.path.join(path,Conf)): - confpath=os.path.join(path,Conf) - elif os.path.exists(os.path.join("/etc","rec10.conf")): - confpath=os.path.join("/etc","rec10.conf") - elif os.path.exists(os.path.join("/etc/rec10","rec10.conf")): - confpath=os.path.join("/etc/rec10","rec10.conf") - if confpath!="": - confp.read(confpath) - else: - recdblist.printutf8(u"rec10.confが見つかりません。",verbose_level=100) - recdblist.printutf8(u"このinstall.pyと同じフォルダに置くか、/etc/rec10.confもしくは/etc/rec10/rec10.confにおいてください。",verbose_level=100) - sys.exit(1) - recdblist.printutf8(u"設定ファイルの読み込みを確認//設定ファイルのパスは"+confpath,verbose_level=100) - if confp.get('path',"recpath")=="/path of /recording": - recdblist.printutf8(u"録画先のフォルダを設定してください(recpath=)",verbose_level=100) - sys.exit(1) - recdblist.printutf8(u"DB処理に入ります",verbose_level=100) - if os.path.exists(os.path.join(path,"rec10d.py")): - try: - update_db_all() - except Exception, inst: - recdblist.printutf8(u"DB処理中にエラーが出ました。configファイルのDB設定を見直してください。",verbose_level=100) - recdblist.printutf8(str(type(inst)),verbose_level=100) - recdblist.printutf8(str(inst)+"\n"+traceback.format_exc(),verbose_level=100) - import rec10d - rec10d.rec10db.change_installed_in_status() - recdblist.printutf8(u"チャンネル設定に入ります",verbose_level=100) - import scan_ch - rec10d.rec10db.new_epg_ch() - recdblist.printutf8(u"チャンネルスキャンの開始",verbose_level=100) - scan_ch.searchCh() - rec10d.rec10db.change_chscaned_in_status() - #if os.path.exists(os.path.join(path,"chlist.xml")): - # recdblist.printutf8(u"チャンネルリストが見つかりました。||chlist.xml",verbose_level=100) - #else: - # recdblist.printutf8(u"チャンネルリストが見つかりません。"+os.path.join(path,"chlist.xml")+u"を作成してください。",verbose_level=100) - # recdblist.printutf8(u"東京/名古屋/神戸のサンプルがchlist_sample_*.xmlにあるため、参考にしてください。",verbose_level=100) - # sys.exit(1) - #bsok=int(confp.get('env',"bs")) - #csok=int(confp.get('env',"cs")) - #import chdata - #chdata.new_chdata(bsok,csok) - recdblist.printutf8(u"おめでとうございます 初期設定は完了しました。",verbose_level=100) - recdblist.printutf8(u"rec10を実行するユーザーのcrontabに"+os.path.join(path,"rec10")+u"を追加してください(5分周期が目安)",verbose_level=100) - -def getLocalPath(cmd): - printutf8(cmd+u"の場所を確認中") - txt=commands.getoutput(u"which "+cmd) - if len(txt.split(" "))>3: - printutf8(cmd+u"の場所を確認できませんでした。終了します") - sys.exit(1) - else: - printutf8(cmd+u" : "+txt) - if len(txt.splitlines()): - txt=txt.splitlines()[0] - return txt.strip() -def move(): - useB=0 - path = str(os.path.dirname(os.path.abspath(__file__))) - printutf8(u"rec10 ver "+recdblist.version_str+" installer.") - printutf8(u"rec10のインストールを開始します。") - maxn=16 - configwriter.setPath(u"wine", getLocalPath(u"wine")) - configwriter.setPath(u"recpt1", getLocalPath(u"recpt1")) - #configwriter.setpath(u"x264", getpath(u"x264")) - configwriter.setPath(u"mp4box", getLocalPath(u"MP4Box")) - configwriter.setPath(u"mencoder", getLocalPath(u"mencoder")) - configwriter.setPath(u"ffmpeg", getLocalPath(u"ffmpeg")) - configwriter.setPath(u"mkvmerge", getLocalPath(u"mkvmerge")) - configwriter.setPath(u"b25", getLocalPath(u"b25")) - printutf8(u"必須環境の設定が完了しました") - printutf8(u"個人設定に入ります") - if os.path.exists("/etc/rec10.conf"): - printutf8(u"以前の設定ファイルが見つかりました。") - printutf8(u"インポートしますか?") - useB=raw_input("[Y/n]:") - if useB=="N" or useB == "n": - useB=0 - else: - useB=1 - printutf8(u"設定ファイルのインポートを行います。") - printutf8(u"rec10の録画ファイルが置かれる場所を入力してください(1/"+str(maxn)+")") - printutf8(u"100GB程度は確保されている必要があります") - recpath=getConf(useB,"/etc/rec10.conf","path","recpath","path : ") - configwriter.setPath(u"recpath",recpath) - printutf8(u"DBの設定に入ります。") - printutf8(u"rec10が使用するMySQLのユーザーを設定してください。(2/"+str(maxn)+")") - mysql_user=getConf(useB,"/etc/rec10.conf","db","mysql_user","mysql_user : ") - configwriter.setDBPath("mysql_user", mysql_user) - printutf8(u"パスワードを設定してください(3/"+str(maxn)+")") - mysql_passwd=getConf(useB,"/etc/rec10.conf","db","mysql_passwd","mysql_passwd : ") - configwriter.setDBPath("mysql_passwd", mysql_passwd) - printutf8(u"同時録画可能数の設定に入ります") - printutf8(u"TE(地デジ)録画可能数(PT*だと2 白Friioだと1)(4/"+str(maxn)+")") - te_max=str(int(getConf(useB,"/etc/rec10.conf","env","te_max","te_max : "))) - configwriter.setEnv("te_max", te_max) - printutf8(u"BS/CS110録画可能数(PT*だと2 黒Friioだと1)(5/"+str(maxn)+")") - bscs_max=str(int(getConf(useB,"/etc/rec10.conf","env","bscs_max","bscs_max : "))) - configwriter.setEnv("bscs_max", bscs_max) - printutf8(u"同時エンコード最大数を設定してください(6/"+str(maxn)+")") - printutf8(u"CPUのコア数が目安です") - enc_max=raw_input("[2]:") - if enc_max=="": - enc_max="2" - else: - enc_max=str(int(enc_max)) - configwriter.setEnv("enc_max", enc_max) - printutf8(u"二カ国語放送/5.1ch放送の音声変換の設定です。\nNeroAACエンコーダーを使用しますか?(NeroAACEncを別途入手してtstoolsに入れてください。))") - printutf8(u"入手先:http://www.nero.com/jpn/technologies-aac-codec.html\n (7/"+str(maxn)+")") - audioenc=raw_input("[y/N]: ") - if audioenc=="y" or audioenc=="Y": - configwriter.setPath("useNeroAAC", "1") - printutf8(u"NeroAACEncのパスを指定してください") - aacpath=getConf(useB,"/etc/rec10.conf","path","NeroAAC","[/usr/local/bin/neroAacEnc] : ") - if aacpath.replace(" ","")=="": - aacpath="/usr/local/bin/neroAacEnc" - configwriter.setpath("NeroAAC",aacpath) - else: - configwriter.setPath("useNeroAAC", "0") - printutf8(u"lameを使用します。") - printutf8(u"x264のパスを指定してください(7/"+str(maxn)+")") - x264path=getConf(useB,"/etc/rec10.conf","path","x264","x264 path : ") - if x264path.replace(" ","")=="" or not os.path.isfile(x264path): - x264path=getLocalPath(u"x264") - configwriter.setPath("x264",x264path) - printutf8(u"保存する画質を教えてください(8/"+str(maxn)+")") - printutf8(u"x264のcrfの値です。標準だと30分で800MBほどになります") - crf=getConf(useB,"/etc/rec10.conf","env","crf","[24] : ") - if crf.replace(" ","")=="": - crf="24" - configwriter.setEnv("crf", crf) - printutf8(u"アニメーションを保存する画質を教えてください(9/"+str(maxn)+")") - printutf8(u"x264のcrfの値です。標準だと30分で800MBほどになります") - a_crf=getConf(useB,"/etc/rec10.conf","env","animation_crf","[20] : ") - if a_crf.replace(" ","")=="": - a_crf="20" - configwriter.setEnv("animation_crf", a_crf) - printutf8(u"x264の圧縮率を設定してください(10/"+str(maxn)+")") - printutf8(u"x264のpresetの値です。標準だとmedium、小さければ小さいほど高圧縮になります") - preset=getConf(useB,"/etc/rec10.conf","env","x264_preset","[4] : ") - if preset.replace(" ","")=="": - preset="4" - configwriter.setEnv("x264_preset", preset) - printutf8(u"保存するコンテナの設定(11/"+str(maxn)+")") - printutf8(u"MP4を標準にしますか(もしくはMKVが使えます)") - useMP4=raw_input("[y/N]:") - if useMP4=="Y" or useMP4 == "y" : - useMP4="1" - else: - useMP4="0" - configwriter.setEnv("make_mp4", useMP4) - printutf8(u"TSファイルの自動削除(12/"+str(maxn)+")") - printutf8(u"中間体のtsファイルを削除しますか") - printutf8(u"(削除するとやり直しができないため残しておくことを推奨します。)") - removeTS=raw_input("[y/N]:") - if removeTS=="Y" or removeTS == "y" : - removeTS="1" - else: - removeTS="0" - configwriter.setEnv("remove_ts", removeTS) - printutf8(u"チャンネルの設定に入ります(13/"+str(maxn)+")") - printutf8(u"rec10を設置する地域を選んでください。") - printutf8(u"1:東京 2:神戸 3:名古屋 4:その他") - ch=raw_input() - ch=int(ch) - if ch==1: - try: - shutil.copy(os.path.join(path,"chlist_sample_tokyo.xml"),os.path.join(path,"chlist.xml")) - except: - printutf8(u"既存のchlis.xmlを上書きできないため、前のものを使います。") - elif ch==2: - try: - shutil.copy(os.path.join(path,"chlist_sample_kobe.xml"),os.path.join(path,"chlist.xml")) - except: - printutf8(u"既存のchlis.xmlを上書きできないため、前のものを使います。") - elif ch==3: - try: - shutil.copy(os.path.join(path,"chlist_sample_nagoya.xml"),os.path.join(path,"chlist.xml")) - except: - printutf8(u"既存のchlis.xmlを上書きできないため、前のものを使います。") - elif ch==4: - if not os.path.exists(os.path.join(path,"chlist.xml")): - printutf8(u"チャンネルの設定が必要です。") - printutf8(u"chlist_sample_*を参考にchlist.xmlを作成した後に次のステップに進んでください。") - time.sleep(5) - printutf8(u"BS放送は受信可能ですか?(14/"+str(maxn)+")") - bsok=raw_input("y/N:") - if bsok=="Y" or bsok == "y" : - bsok="1" - else: - bsok="0" - configwriter.setEnv("bs", bsok) - printutf8(u"CS放送(スカパーe2)は受信可能ですか?(15/"+str(maxn)+")") - csok=raw_input("y/N:") - if csok=="Y" or csok == "y" : - csok="1" - printutf8(u"標準パックの番組は入力してありますがそれ以外は追加でchlist_cs.xmlに追加する必要があります。") - else: - csok="0" - configwriter.setEnv("cs", csok) - - printutf8(u"自機識別オプション(16/"+str(maxn)+")") - printutf8(u"本rec10の識別名を入力してください") - printutf8(u"複数台のrec10を運用する場合に効果的です。空白でもかまいません。") - printutf8(u"例 kobe01") - iff=getConf(useB,"/etc/rec10.conf","env","iff","[] : ") - configwriter.setEnv("iff", iff) - confp = ConfigParser.SafeConfigParser() - confp.read("/etc/rec10.conf") - if useB: - configwriter.setPath("recorded",confp.get("path","recorded")) - configwriter.setPath("move_destpath",confp.get("path","move_destpath")) - configwriter.setpath("tmp",confp.get("path","tmp")) - try: - configwriter.setenv("x264_addline",confp.get("env","x264_addline")) - except: - configwriter.setEnv("x264_addline","") - if confp.get("path","b25_remote")=="": - configwriter.setpath("b25_remote", "0") - elif confp.get("path","b25_remote")=="1": - configwriter.setPath("b25_remote", confp.get("path","b25_remote")) - configwriter.setPath("b25", confp.get("path","b25")) - configwriter.setpath("b25_env", confp.get("path","b25_env")) - else: - configwriter.setPath("b25_remote", confp.get("path","b25_remote")) - - configwriter.writeConf() - printutf8(u"初期設定が終了しました。") - printutf8(u"makeを実行した後にrootにてmake installを実行するとインストールされます。") -def getConf(useBeforeConf,Confpath,dbsection,key,defaultstr): - tstr=defaultstr - if os.path.exists(Confpath) and useBeforeConf==1: - try: - confp = ConfigParser.SafeConfigParser() - confp.read("/etc/rec10.conf") - tstr=u"["+confp.get(dbsection,key)+u"]:" - except: - tstr=defaultstr - tmpconf=raw_input(tstr) - if tmpconf.replace(" ","")=="" and os.path.exists(Confpath) and useBeforeConf==1 : - confp = ConfigParser.SafeConfigParser() - confp.read("/etc/rec10.conf") - try: - tmpconf=confp.get(dbsection,key) - except: - tmpconf="" - return tmpconf -def update_db_all(): - import rec10d - tversion=0 - if rec10d.rec10db.select_installed_in_status()==1: - if rec10d.rec10db.select_version_in_status()==0: - tversion=0 - recdblist.printutf8(u"既存のDBが見つかりました。0.9.1と仮定してアップデート処理を行います。",verbose_level=100) - update_db(0) - time.sleep(1) - else: - recdblist.printutf8(u"既存のDBが見つかりました。アップデート処理を行います。",verbose_level=100) - tversion=int(rec10d.rec10db.select_version_in_status()) - while (recdblist.version>tversion): - update_db(tversion) - tversion=int(rec10d.rec10db.select_version_in_status()) - else: - rec10d.rec10db.drop_in_status() - rec10d.rec10db.drop_in_settings() - time.sleep(2) - rec10d.rec10db.new_in_status() - rec10d.rec10db.new_in_settings() - rec10d.rec10db.change_version_in_status(recdblist.version) -def update_db(version): - import rec10d - if version==0: - rec10d.rec10db.update_db_to93() - elif version==93: - rec10d.rec10db.update_db_93to94() - elif version==94: - rec10d.rec10db.update_db_94to95() - elif version==95: - rec10d.rec10db.update_db_95to96() - elif version==96: - rec10d.rec10db.update_db_96to98() - elif version==98: - rec10d.rec10db.update_db_98to100() -if __name__ == "__main__": - move() +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import time +import os.path +import ConfigParser +import sys +import commands +import configwriter +import shutil +import traceback + +import recdblist +def printutf8(str): + print str.encode('utf-8') +def install(): + version = recdblist.version + recdblist.printutf8(u"rec10の環境インストールを開始します。",verbose_level=100) + time.sleep(1) + recdblist.printutf8(u"環境インストール処理中・・・",verbose_level=100) + path = str(os.path.dirname(os.path.abspath(__file__))) + confp = ConfigParser.SafeConfigParser() + Conf = 'rec10.conf' + confpath="" + if os.path.exists(os.path.join(path,Conf)): + confpath=os.path.join(path,Conf) + elif os.path.exists(os.path.join("/etc","rec10.conf")): + confpath=os.path.join("/etc","rec10.conf") + elif os.path.exists(os.path.join("/etc/rec10","rec10.conf")): + confpath=os.path.join("/etc/rec10","rec10.conf") + if confpath!="": + confp.read(confpath) + else: + recdblist.printutf8(u"rec10.confが見つかりません。",verbose_level=100) + recdblist.printutf8(u"このinstall.pyと同じフォルダに置くか、/etc/rec10.confもしくは/etc/rec10/rec10.confにおいてください。",verbose_level=100) + sys.exit(1) + recdblist.printutf8(u"設定ファイルの読み込みを確認//設定ファイルのパスは"+confpath,verbose_level=100) + if confp.get('path',"recpath")=="/path of /recording": + recdblist.printutf8(u"録画先のフォルダを設定してください(recpath=)",verbose_level=100) + sys.exit(1) + recdblist.printutf8(u"DB処理に入ります",verbose_level=100) + if os.path.exists(os.path.join(path,"rec10d.py")): + try: + update_db_all() + except Exception, inst: + recdblist.printutf8(u"DB処理中にエラーが出ました。configファイルのDB設定を見直してください。",verbose_level=100) + recdblist.printutf8(str(type(inst)),verbose_level=100) + recdblist.printutf8(str(inst)+"\n"+traceback.format_exc(),verbose_level=100) + import rec10d + rec10d.rec10db.change_installed_in_status() + recdblist.printutf8(u"チャンネル設定に入ります",verbose_level=100) + import scan_ch + rec10d.rec10db.new_epg_ch() + recdblist.printutf8(u"チャンネルスキャンの開始",verbose_level=100) + scan_ch.searchCh() + rec10d.rec10db.change_chscaned_in_status() + #if os.path.exists(os.path.join(path,"chlist.xml")): + # recdblist.printutf8(u"チャンネルリストが見つかりました。||chlist.xml",verbose_level=100) + #else: + # recdblist.printutf8(u"チャンネルリストが見つかりません。"+os.path.join(path,"chlist.xml")+u"を作成してください。",verbose_level=100) + # recdblist.printutf8(u"東京/名古屋/神戸のサンプルがchlist_sample_*.xmlにあるため、参考にしてください。",verbose_level=100) + # sys.exit(1) + #bsok=int(confp.get('env',"bs")) + #csok=int(confp.get('env',"cs")) + #import chdata + #chdata.new_chdata(bsok,csok) + recdblist.printutf8(u"おめでとうございます 初期設定は完了しました。",verbose_level=100) + recdblist.printutf8(u"rec10を実行するユーザーのcrontabに"+os.path.join(path,"rec10")+u"を追加してください(5分周期が目安)",verbose_level=100) + +def getLocalPath(cmd): + printutf8(cmd+u"の場所を確認中") + txt=commands.getoutput(u"which "+cmd) + if len(txt.split(" "))>3: + printutf8(cmd+u"の場所を確認できませんでした。終了します") + sys.exit(1) + else: + printutf8(cmd+u" : "+txt) + if len(txt.splitlines()): + txt=txt.splitlines()[0] + return txt.strip() +def move(): + useB=0 + path = str(os.path.dirname(os.path.abspath(__file__))) + printutf8(u"rec10 ver "+recdblist.version_str+" installer.") + printutf8(u"rec10のインストールを開始します。") + maxn=16 + configwriter.setTempConfPath(u"wine", getpath(u"wine")) + configwriter.setTempConfPath(u"recpt1", getpath(u"recpt1")) + #configwriter.setpath(u"x264", getpath(u"x264")) + configwriter.setTempConfPath(u"mp4box", getpath(u"MP4Box")) + configwriter.setTempConfPath(u"mencoder", getpath(u"mencoder")) + configwriter.setTempConfPath(u"ffmpeg", getpath(u"ffmpeg")) + configwriter.setTempConfPath(u"mkvmerge", getpath(u"mkvmerge")) + configwriter.setTempConfPath(u"b25", getpath(u"b25")) + printutf8(u"必須環境の設定が完了しました") + printutf8(u"個人設定に入ります") + if os.path.exists("/etc/rec10.conf"): + printutf8(u"以前の設定ファイルが見つかりました。") + printutf8(u"インポートしますか?") + useB=raw_input("[Y/n]:") + if useB=="N" or useB == "n": + useB=0 + else: + useB=1 + printutf8(u"設定ファイルのインポートを行います。") + printutf8(u"rec10の録画ファイルが置かれる場所を入力してください(1/"+str(maxn)+")") + printutf8(u"100GB程度は確保されている必要があります") + recpath=getConf(useB,"/etc/rec10.conf","path","recpath","path : ") + configwriter.setTempConfPath(u"recpath",recpath) + printutf8(u"DBの設定に入ります。") + printutf8(u"rec10が使用するMySQLのユーザーを設定してください。(2/"+str(maxn)+")") + mysql_user=getConf(useB,"/etc/rec10.conf","db","mysql_user","mysql_user : ") + configwriter.setTempConfDB("mysql_user", mysql_user) + printutf8(u"パスワードを設定してください(3/"+str(maxn)+")") + mysql_passwd=getConf(useB,"/etc/rec10.conf","db","mysql_passwd","mysql_passwd : ") + configwriter.setTempConfDB("mysql_passwd", mysql_passwd) + printutf8(u"同時録画可能数の設定に入ります") + printutf8(u"TE(地デジ)録画可能数(PT*だと2 白Friioだと1)(4/"+str(maxn)+")") + te_max=str(int(getConf(useB,"/etc/rec10.conf","env","te_max","te_max : "))) + configwriter.setTempConfEnv("te_max", te_max) + printutf8(u"BS/CS110録画可能数(PT*だと2 黒Friioだと1)(5/"+str(maxn)+")") + bscs_max=str(int(getConf(useB,"/etc/rec10.conf","env","bscs_max","bscs_max : "))) + configwriter.setTempConfEnv("bscs_max", bscs_max) + printutf8(u"同時エンコード最大数を設定してください(6/"+str(maxn)+")") + printutf8(u"CPUのコア数が目安です") + enc_max=raw_input("[2]:") + if enc_max=="": + enc_max="2" + else: + enc_max=str(int(enc_max)) + configwriter.setTempConfEnv("enc_max", enc_max) + printutf8(u"二カ国語放送/5.1ch放送の音声変換の設定です。\nNeroAACエンコーダーを使用しますか?(NeroAACEncを別途入手してtstoolsに入れてください。))") + printutf8(u"入手先:http://www.nero.com/jpn/technologies-aac-codec.html\n (7/"+str(maxn)+")") + audioenc=raw_input("[y/N]: ") + if audioenc=="y" or audioenc=="Y": + configwriter.setTempConfPath("useNeroAAC", "1") + printutf8(u"NeroAACEncのパスを指定してください") + aacpath=getConf(useB,"/etc/rec10.conf","path","NeroAAC","[/usr/local/bin/neroAacEnc] : ") + if aacpath.replace(" ","")=="": + aacpath="/usr/local/bin/neroAacEnc" + configwriter.setTempConfPath("NeroAAC",aacpath) + else: + configwriter.setTempConfPath("useNeroAAC", "0") + printutf8(u"lameを使用します。") + printutf8(u"x264のパスを指定してください(7/"+str(maxn)+")") + x264path=getConf(useB,"/etc/rec10.conf","path","x264","x264 path : ") + if x264path.replace(" ","")=="" or not os.path.isfile(x264path): + x264path=getpath(u"x264") + configwriter.setTempConfPath("x264",x264path) + printutf8(u"保存する画質を教えてください(8/"+str(maxn)+")") + printutf8(u"x264のcrfの値です。標準だと30分で800MBほどになります") + crf=getConf(useB,"/etc/rec10.conf","env","crf","[24] : ") + if crf.replace(" ","")=="": + crf="24" + configwriter.setTempConfEnv("crf", crf) + printutf8(u"アニメーションを保存する画質を教えてください(9/"+str(maxn)+")") + printutf8(u"x264のcrfの値です。標準だと30分で800MBほどになります") + a_crf=getConf(useB,"/etc/rec10.conf","env","animation_crf","[20] : ") + if a_crf.replace(" ","")=="": + a_crf="20" + configwriter.setTempConfEnv("animation_crf", a_crf) + printutf8(u"x264の圧縮率を設定してください(10/"+str(maxn)+")") + printutf8(u"x264のpresetの値です。標準だとmedium、小さければ小さいほど高圧縮になります") + preset=getConf(useB,"/etc/rec10.conf","env","x264_preset","[4] : ") + if preset.replace(" ","")=="": + preset="4" + configwriter.setTempConfEnv("x264_preset", preset) + printutf8(u"保存するコンテナの設定(11/"+str(maxn)+")") + printutf8(u"MP4を標準にしますか(もしくはMKVが使えます)") + useMP4=raw_input("[y/N]:") + if useMP4=="Y" or useMP4 == "y" : + useMP4="1" + else: + useMP4="0" + configwriter.setTempConfEnv("make_mp4", useMP4) + printutf8(u"TSファイルの自動削除(12/"+str(maxn)+")") + printutf8(u"中間体のtsファイルを削除しますか") + printutf8(u"(削除するとやり直しができないため残しておくことを推奨します。)") + removeTS=raw_input("[y/N]:") + if removeTS=="Y" or removeTS == "y" : + removeTS="1" + else: + removeTS="0" + configwriter.setTempConfEnv("remove_ts", removeTS) + printutf8(u"チャンネルの設定に入ります(13/"+str(maxn)+")") + printutf8(u"rec10を設置する地域を選んでください。") + printutf8(u"1:東京 2:神戸 3:名古屋 4:その他") + ch=raw_input() + ch=int(ch) + if ch==1: + try: + shutil.copy(os.path.join(path,"chlist_sample_tokyo.xml"),os.path.join(path,"chlist.xml")) + except: + printutf8(u"既存のchlis.xmlを上書きできないため、前のものを使います。") + elif ch==2: + try: + shutil.copy(os.path.join(path,"chlist_sample_kobe.xml"),os.path.join(path,"chlist.xml")) + except: + printutf8(u"既存のchlis.xmlを上書きできないため、前のものを使います。") + elif ch==3: + try: + shutil.copy(os.path.join(path,"chlist_sample_nagoya.xml"),os.path.join(path,"chlist.xml")) + except: + printutf8(u"既存のchlis.xmlを上書きできないため、前のものを使います。") + elif ch==4: + if not os.path.exists(os.path.join(path,"chlist.xml")): + printutf8(u"チャンネルの設定が必要です。") + printutf8(u"chlist_sample_*を参考にchlist.xmlを作成した後に次のステップに進んでください。") + time.sleep(5) + printutf8(u"BS放送は受信可能ですか?(14/"+str(maxn)+")") + bsok=raw_input("y/N:") + if bsok=="Y" or bsok == "y" : + bsok="1" + else: + bsok="0" + configwriter.setTempConfEnv("bs", bsok) + printutf8(u"CS放送(スカパーe2)は受信可能ですか?(15/"+str(maxn)+")") + csok=raw_input("y/N:") + if csok=="Y" or csok == "y" : + csok="1" + printutf8(u"標準パックの番組は入力してありますがそれ以外は追加でchlist_cs.xmlに追加する必要があります。") + else: + csok="0" + configwriter.setTempConfEnv("cs", csok) + + printutf8(u"自機識別オプション(16/"+str(maxn)+")") + printutf8(u"本rec10の識別名を入力してください") + printutf8(u"複数台のrec10を運用する場合に効果的です。空白でもかまいません。") + printutf8(u"例 kobe01") + iff=getConf(useB,"/etc/rec10.conf","env","iff","[] : ") + configwriter.setTempConfEnv("iff", iff) + confp = ConfigParser.SafeConfigParser() + confp.read("/etc/rec10.conf") + if useB: + configwriter.setTempConfPath("recorded",confp.get("path","recorded")) + configwriter.setTempConfPath("move_destpath",confp.get("path","move_destpath")) + configwriter.setTempConfPath("tmp",confp.get("path","tmp")) + try: + configwriter.setTempConfEnv("x264_addline",confp.get("env","x264_addline")) + except: + configwriter.setTempConfEnv("x264_addline","") + if confp.get("path","b25_remote")=="": + configwriter.setTempConfPath("b25_remote", "0") + elif confp.get("path","b25_remote")=="1": + configwriter.setTempConfPath("b25_remote", confp.get("path","b25_remote")) + configwriter.setTempConfPath("b25", confp.get("path","b25")) + configwriter.setTempConfPath("b25_env", confp.get("path","b25_env")) + else: + configwriter.setTempConfPath("b25_remote", confp.get("path","b25_remote")) + + configwriter.writeTempConf() + printutf8(u"初期設定が終了しました。") + printutf8(u"makeを実行した後にrootにてmake installを実行するとインストールされます。") +def getConf(useBeforeConf,Confpath,dbsection,key,defaultstr): + tstr=defaultstr + if os.path.exists(Confpath) and useBeforeConf==1: + try: + confp = ConfigParser.SafeConfigParser() + confp.read("/etc/rec10.conf") + tstr=u"["+confp.get(dbsection,key)+u"]:" + except: + tstr=defaultstr + tmpconf=raw_input(tstr) + if tmpconf.replace(" ","")=="" and os.path.exists(Confpath) and useBeforeConf==1 : + confp = ConfigParser.SafeConfigParser() + confp.read("/etc/rec10.conf") + try: + tmpconf=confp.get(dbsection,key) + except: + tmpconf="" + return tmpconf +def update_db_all(): + import rec10d + tversion=0 + if rec10d.rec10db.select_installed_in_status()==1: + if rec10d.rec10db.select_version_in_status()==0: + tversion=0 + recdblist.printutf8(u"既存のDBが見つかりました。0.9.1と仮定してアップデート処理を行います。",verbose_level=100) + update_db(0) + time.sleep(1) + else: + recdblist.printutf8(u"既存のDBが見つかりました。アップデート処理を行います。",verbose_level=100) + tversion=int(rec10d.rec10db.select_version_in_status()) + while (recdblist.version>tversion): + update_db(tversion) + tversion=int(rec10d.rec10db.select_version_in_status()) + else: + rec10d.rec10db.drop_in_status() + rec10d.rec10db.drop_in_settings() + time.sleep(2) + rec10d.rec10db.new_in_status() + rec10d.rec10db.new_in_settings() + rec10d.rec10db.change_version_in_status(recdblist.version) +def update_db(version): + import rec10d + if version==0: + rec10d.rec10db.update_db_to93() + elif version==93: + rec10d.rec10db.update_db_93to94() + elif version==94: + rec10d.rec10db.update_db_94to95() + elif version==95: + rec10d.rec10db.update_db_95to96() + elif version==96: + rec10d.rec10db.update_db_96to98() + elif version==98: + rec10d.rec10db.update_db_98to100() +if __name__ == "__main__": + move() diff --git a/rec10/trunk/src/rec10d.py b/rec10/trunk/src/rec10d.py index f89c0b1..6b99b16 100644 --- a/rec10/trunk/src/rec10d.py +++ b/rec10/trunk/src/rec10d.py @@ -1,29 +1,29 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import os - -import warnings -warnings.filterwarnings('ignore', "the sets module is deprecated") -import configreader -import dbMySQL -import timerec -path = str(os.path.dirname(os.path.abspath(__file__))) + "/" -global rec10db -def main(): - timerec.task() -db = configreader.getDBPathSetting("db") -if db == "MySQL": - dbn = configreader.getDBPathSetting("mysql_dbname") - dbh = configreader.getDBPathSetting("mysql_host") - dbu = configreader.getDBPathSetting("mysql_user") - dbpwd = configreader.getDBPathSetting("mysql_passwd") - dbport = int(configreader.getDBPathSetting("mysql_port")) - rec10db = dbMySQL.DB_MySQL(dbname=dbn, host=dbh, user=dbu, passwd=dbpwd, port=dbport) - rec10db.new_in_status() -else: - rec10db = dbSQLite.DB_SQLite(path + "ch.db") -if __name__ == "__main__": - main() - +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import os + +import warnings +warnings.filterwarnings('ignore', "the sets module is deprecated") +import configreader +import dbMySQL +import timerec +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" +global rec10db +def main(): + timerec.task() +db = configreader.getConfDB("db") +if db == "MySQL": + dbn = configreader.getConfDB("mysql_dbname") + dbh = configreader.getConfDB("mysql_host") + dbu = configreader.getConfDB("mysql_user") + dbpwd = configreader.getConfDB("mysql_passwd") + dbport = int(configreader.getConfDB("mysql_port")) + rec10db = dbMySQL.DB_MySQL(dbname=dbn, host=dbh, user=dbu, passwd=dbpwd, port=dbport) + rec10db.new_in_status() +else: + rec10db = dbSQLite.DB_SQLite(path + "ch.db") +if __name__ == "__main__": + main() + diff --git a/rec10/trunk/src/recdb.py b/rec10/trunk/src/recdb.py index 6361821..0b9d625 100644 --- a/rec10/trunk/src/recdb.py +++ b/rec10/trunk/src/recdb.py @@ -1,87 +1,83 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import chdb -import rec10d -import recdblist - -def recreserv(title, chtxt, btime, etime, opt):#optにはa(アニメ)d(副音声)v(xvid) - rec_reckey("res", title, chtxt, btime, etime, opt) -def auto_keyreserv(keyword, chtxt, btime, etime, deltatime, opt): - rec10d.rec10db.add_timeline(type=recdblist.REC_AUTO_KEYWORD, chtxt=chtxt, title=keyword, btime=btime, etime=etime, deltatime=deltatime, opt=opt) -def keyreserv(keyword, chtxt, btime, etime, deltatime, opt): - rec10d.rec10db.add_timeline(type=recdblist.REC_KEYWORD, chtxt=chtxt, title=keyword, btime=btime, etime=etime, deltatime=deltatime, opt=opt) -def everyreserv(keyword, chtxt, btime, etime, deltatime, opt, deltaday,count): - rec10d.rec10db.add_timeline(type=recdblist.REC_KEYWORD_EVERY_SOME_DAYS, chtxt=chtxt, title=keyword, btime=btime, etime=etime, deltatime=deltatime, opt=opt, deltaday=deltaday,counter=count) -def rec_reckey(type, title, chtxt, btime, etime, opt): - rec10d.rec10db.add_timeline(type=type, chtxt=chtxt, title=title, btime=btime, etime=etime, opt=opt) -def del_reckey(type, title, chtxt, btime): - rec10d.rec10db.del_timeline(type=type, title=title, chtxt=chtxt, btime=btime) -def add_auto_keyword(chtxt,title,btime,etime): - rec10d.rec10db.add_auto_timeline_keyword(chtxt, title, btime, etime) -def add_auto_bayes(chtxt,title,btime,etime,point): - rec10d.rec10db.add_auto_timeline_bayes(chtxt, title, btime, etime,point) -def getnow(dhour): - dhour = int(dhour) - dminutes = 60 * dhour - dminutes = str(dminutes) - return rec10d.rec10db.select_bytime_timeline(dminutes) -def getnow_minutes(dminutes): - return rec10d.rec10db.select_bytime_timeline(dminutes) -def countRecNow(dhour): - d = getnow(dhour) - ret = 0 - for i in d: - t = i['type'] - if t == "key" or t == "keyevery" or t == "rec" or t == "res": - ret = ret + 1 - return ret -def countRecNow_minutes(dminutes): - d = getnow_minutes(dminutes) - ret = 0 - for i in d: - t = i['type'] - if t == "key" or t == "keyevery" or t == "rec" or t == "res": - ret = ret + 1 - return ret -def countRecNow_minutes_BSCS(dminutes): - d = getnow_minutes(dminutes) - ret = 0 - for i in d: - t = i['type'] - if t == "key" or t == "keyevery" or t == "rec" or t == "res": - if len(chdb.getChCSchFromCHtxt(i['chtxt'])['ch']) > 2: - ret = ret + 1 - return ret -def countRecNow_minutes_TE(dminutes): - d = getnow_minutes(dminutes) - ret = 0 - for i in d: - t = i['type'] - if t == "key" or t == "keyevery" or t == "rec" or t == "res": - if len(chdb.getChCSchFromCHtxt(i['chtxt'])['ch']) < 3: - ret = ret + 1 - return ret -def delete_old(dhour): - """ - delete keys except recdblist.REC_MISS_ENCODE and recdblist.REC_KEYWORD_EVERY_SOME_DAYS before dhour hours from now. - """ - rec10d.rec10db.delete_old_timeline(dhour) -def delete_old_auto_keyword(dhour): - rec10d.rec10db.delete_old_auto_timeline_keyword(dhour) -def delete_old_auto_bayes(dhour): - rec10d.rec10db.delete_old_auto_timeline_bayes(dhour) -def getAll(): - return rec10d.rec10db.select_all_timeline() -def rec_reclog(title,chtxt,btime,etime,opt,exp,longexp,category): - rec10d.rec10db.add_in_timeline_log(chtxt,title,btime,etime,opt,exp,longexp,category) -def get_key(): - return rec10d.rec10db.select_all_in_auto_jbk_key() -def checkduplicate(title,chtxt,epgbtime,epgetime): - tl=rec10dbselect_byepgtime_all_timeline(epgbtime,epgetime) - dup=0 - for t in tl: - if t["title"]==title and t["chtxt"]==chtxt: - dup=1 - return dup \ No newline at end of file +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import chdb +import rec10d +import recdblist + +def reserveKeyword(keyword, chtxt, btime, etime, deltatime, opt): + rec10d.rec10db.add_timeline(type=recdblist.REC_KEYWORD, chtxt=chtxt, title=keyword, btime=btime, etime=etime, deltatime=deltatime, opt=opt) +def reserveEverydayKeyword(keyword, chtxt, btime, etime, deltatime, opt, deltaday,count): + rec10d.rec10db.add_timeline(type=recdblist.REC_KEYWORD_EVERY_SOME_DAYS, chtxt=chtxt, title=keyword, btime=btime, etime=etime, deltatime=deltatime, opt=opt, deltaday=deltaday,counter=count) +def reserveReckey(type, title, chtxt, btime, etime, opt): + rec10d.rec10db.add_timeline(type=type, chtxt=chtxt, title=title, btime=btime, etime=etime, opt=opt) +def deleteReckey(type, title, chtxt, btime): + rec10d.rec10db.del_timeline(type=type, title=title, chtxt=chtxt, btime=btime) +def reserveAutoKeyword(chtxt,title,btime,etime): + rec10d.rec10db.add_auto_timeline_keyword(chtxt, title, btime, etime) +def addAutoBayesKeyword(chtxt,title,btime,etime,point): + rec10d.rec10db.add_auto_timeline_bayes(chtxt, title, btime, etime,point) +def getProgramsInTheseHours(dhour): + dhour = int(dhour) + dminutes = 60 * dhour + dminutes = str(dminutes) + return rec10d.rec10db.select_bytime_timeline(dminutes) +def getProgramsInTheseMinutes(dminutes): + return rec10d.rec10db.select_bytime_timeline(dminutes) +def countRecNow(dhour): + d = getProgramsInTheseHours(dhour) + ret = 0 + for i in d: + t = i['type'] + if t == "key" or t == "keyevery" or t == "rec" or t == "res": + ret = ret + 1 + return ret +def countRecNow_minutes(dminutes): + d = getProgramsInTheseMinutes(dminutes) + ret = 0 + for i in d: + t = i['type'] + if t == "key" or t == "keyevery" or t == "rec" or t == "res": + ret = ret + 1 + return ret +def countRecNow_minutes_BSCS(dminutes): + d = getProgramsInTheseMinutes(dminutes) + ret = 0 + for i in d: + t = i['type'] + if t == "key" or t == "keyevery" or t == "rec" or t == "res": + if len(chdb.searchCHFromChtxt(i['chtxt'])['ch']) > 2: + ret = ret + 1 + return ret +def countRecNow_minutes_TE(dminutes): + d = getProgramsInTheseMinutes(dminutes) + ret = 0 + for i in d: + t = i['type'] + if t == "key" or t == "keyevery" or t == "rec" or t == "res": + if len(chdb.searchCHFromChtxt(i['chtxt'])['ch']) < 3: + ret = ret + 1 + return ret +def deleteOldProgramBeforeTheseHours(dhour): + """ + delete keys except recdblist.REC_MISS_ENCODE and recdblist.REC_KEYWORD_EVERY_SOME_DAYS before dhour hours from now. + """ + rec10d.rec10db.delete_old_timeline(dhour) +def delete_old_auto_keyword(dhour): + rec10d.rec10db.delete_old_auto_timeline_keyword(dhour) +def delete_old_auto_bayes(dhour): + rec10d.rec10db.delete_old_auto_timeline_bayes(dhour) +def getAll(): + return rec10d.rec10db.select_all_timeline() +def addRecLogProgram(title,chtxt,btime,etime,opt,exp,longexp,category): + rec10d.rec10db.add_in_timeline_log(chtxt,title,btime,etime,opt,exp,longexp,category) +def getAllJbkKeyword(): + return rec10d.rec10db.select_all_in_auto_jbk_key() +def checkDuplicated(title,chtxt,epgbtime,epgetime): + tl=rec10dbselect_byepgtime_all_timeline(epgbtime,epgetime) + dup=0 + for t in tl: + if t["title"]==title and t["chtxt"]==chtxt: + dup=1 + return dup diff --git a/rec10/trunk/src/recdblist.py b/rec10/trunk/src/recdblist.py index bcaa133..b0a6d60 100644 --- a/rec10/trunk/src/recdblist.py +++ b/rec10/trunk/src/recdblist.py @@ -1,161 +1,161 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze - -""" -task names -""" -import datetime -import os -import os.path -import traceback - -import configreader - -global REC_RESERVE -global REC_FINAL_RESERVE -global REC_ENCODE_GRID -global REC_ENCODE_LOCAL -global REC_ENCODE_QUE -global REC_MISS_ENCODE -global REC_KEYWORD -global REC_KEYWORD_EVERY_SOME_DAYS -global REC_FIN_LOCAL -global REC_MISS_DECODE -global REC_TS_DECODE_QUE -global REC_TS_DECODING -global REC_TS_RECORDING -global REC_AVI_TO_MKV -global REC_AVI_TO_MP4 -global REC_MKV_TO_MP4 -global REC_CHANGING_CANTAINER - -#ここから処理のちに移動 - -global REC_MOVE_END - -#ここから自動で提起される処理。 -global REC_AUTO_SUGGEST_REC -global REC_AUTO_SUGGEST_DECODE -global REC_AUTO_SUGGEST_ENCODE -global REC_AUTO_SUGGEST_AVI2MP4 -global REC_AUTO_SUGGEST_MKV2MP4 -global REC_AUTO_SUGGEST_AVI2FP -global REC_AUTO_SUGGEST_AP2FP -global REC_BAYES_SUGGEST -global REC_AUTO_KEYWORD -REC_RESERVE = "reserve_flexible" -REC_FINAL_RESERVE = "reserve_fixed" -REC_ENCODE_GRID = "convert_ts_mp4_network" -REC_ENCODE_LOCAL = "convert_ts_mp4_running" -REC_ENCODE_QUE = "convert_ts_mp4" -REC_MISS_ENCODE = "convert_avi_mp4_miss" -REC_KEYWORD = "search_today" -REC_KEYWORD_EVERY_SOME_DAYS = "search_everyday" -REC_FIN_LOCAL = "convert_ts_mp4_finished" -REC_MISS_DECODE = "convert_b25_ts_miss" -REC_TS_DECODE_QUE = "convert_b25_ts" -REC_TS_DECODING = "convert_b25_ts_running" -REC_TS_RECORDING = "reserve_running" -REC_CHANGING_CANTAINER = "convert_mkv_mp4_runnings" -REC_AVI_TO_MKV = "convert_avi_mkv" -REC_AVI_TO_MP4 = "convert_avi_mp4" -REC_MKV_TO_MP4 = "convert_mkv_mp4" - -REC_MOVE_END = "move_end" - -REC_AUTO_SUGGEST_REC = "auto_suggest_rec" -REC_AUTO_SUGGEST_DECODE = "auto_suggest_dec" -REC_AUTO_SUGGEST_ENCODE = "auto_suggest_enc" -REC_AUTO_SUGGEST_AVI2FP = "auto_suggest_avi2fp" -REC_AUTO_SUGGEST_AP2FP = "auto_suggest_ap2fp" -REC_AUTO_KEYWORD = "auto_keyword" -REC_BAYES_SUGGEST ="bayes_suggest" - -global BONTSDEMUX_DELAY -BONTSDEMUX_DELAY="0" - -version = 100 -version_str="0.9.10" - -global verbose_level_now -global log_level_now - -try: - log_level_now=int(configreader.getLogSetting("log_level")) - verbose_level_now=int(configreader.getLogSetting("verbose_level")) -except: - log_level_now=900 - verbose_level_now=400 -def printutf8(unicode,verbose_level=500): - if verbose_level_now > verbose_level: - try: - str=unicode.encode('utf-8') - print str - except Exception, inst: - recdblist.addCommonlogEX("Error", "printutf8(recdblist.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) -def printuft8ex(unicode,verbose_level=500,log_level=500): - str=unicode.encode('utf-8') - if verbose_level_now > verbose_level: - print str - logfname="/var/log/rec10" - mode="a" - if log_level_now > log_level: - if os.path.exists(logfname): - f=open(logfname,mode) - f.write(str+"\n") - f.close() -def addCommonlogEX(type,place,inst,txt,verbose_level=500,log_level=500): - lt=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+u":" - if txt=="": - lt=lt+u"["+type+u"] "+place+u" "+inst - else: - lt=lt+u"["+type+u"] "+place+u" "+inst+u"\n"+txt - lt=lt.encode('utf-8') - logfname="/var/log/rec10" - mode="a" - if verbose_level_now > verbose_level: - print lt - if log_level_now > log_level: - if os.path.exists(logfname): - f=open(logfname,mode) - f.write(lt+"\n") - f.close() -def addCommandLog(tspath,log_title,cmd,cmd_log=""): - addLog(tspath,cmd,log_title+u"ログ-コマンド") - addLog(tspath,cmd_log,log_title+u"ログ-詳細") -def addLog(tspath,txt,log_title): - logo=tspath - logo=logo.replace("_1.wav",".ts") - logo=logo.replace("_2.wav",".ts") - logo=logo.replace("_1.aac",".ts") - logo=logo.replace("_2.aac",".ts") - logo=logo.replace("_1.mp3",".ts") - logo=logo.replace("_2.mp3",".ts") - logo=logo.replace(".ts.tsmix",".ts") - logo=logo.replace(".ts.b25",".ts") - logo=logo.replace(".sa.avi",".ts") - logo=logo.replace(".m2v",".ts") - logo=logo.replace(".avi",".ts") - logo=logo.replace(".mkv",".ts") - logo=logo.replace(".wav",".ts") - logo=logo.replace(".mp4",".ts") - logo=logo.replace(".mp3",".ts") - logo=logo.replace(".aac",".ts") - logo=logo.replace(".srt",".ts") - logo=logo.replace(".ts",".log") - f=open(logo,'a') - s=len(txt) - stxt="" - if s>3000: - stxt=txt[0:1500]+"\n\n(ry..)\n" - st=txt[s-1500:].find("\n") - if st>0: - stxt=stxt+txt[s-1500+st:] - else: - stxt=txt - txtw= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") - txtw=txtw+"\n####"+log_title+"####\n"+stxt - f.write(txtw.encode('utf-8')) - f.close() +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze + +""" +task names +""" +import datetime +import os +import os.path +import traceback + +import configreader + +global REC_RESERVE +global REC_FINAL_RESERVE +global REC_ENCODE_GRID +global REC_ENCODE_LOCAL +global REC_ENCODE_QUE +global REC_MISS_ENCODE +global REC_KEYWORD +global REC_KEYWORD_EVERY_SOME_DAYS +global REC_FIN_LOCAL +global REC_MISS_DECODE +global REC_TS_DECODE_QUE +global REC_TS_DECODING +global REC_TS_RECORDING +global REC_AVI_TO_MKV +global REC_AVI_TO_MP4 +global REC_MKV_TO_MP4 +global REC_CHANGING_CANTAINER + +#ここから処理のちに移動 + +global REC_MOVE_END + +#ここから自動で提起される処理。 +global REC_AUTO_SUGGEST_REC +global REC_AUTO_SUGGEST_DECODE +global REC_AUTO_SUGGEST_ENCODE +global REC_AUTO_SUGGEST_AVI2MP4 +global REC_AUTO_SUGGEST_MKV2MP4 +global REC_AUTO_SUGGEST_AVI2FP +global REC_AUTO_SUGGEST_AP2FP +global REC_BAYES_SUGGEST +global REC_AUTO_KEYWORD +REC_RESERVE = "reserve_flexible" +REC_FINAL_RESERVE = "reserve_fixed" +REC_ENCODE_GRID = "convert_ts_mp4_network" +REC_ENCODE_LOCAL = "convert_ts_mp4_running" +REC_ENCODE_QUE = "convert_ts_mp4" +REC_MISS_ENCODE = "convert_avi_mp4_miss" +REC_KEYWORD = "search_today" +REC_KEYWORD_EVERY_SOME_DAYS = "search_everyday" +REC_FIN_LOCAL = "convert_ts_mp4_finished" +REC_MISS_DECODE = "convert_b25_ts_miss" +REC_TS_DECODE_QUE = "convert_b25_ts" +REC_TS_DECODING = "convert_b25_ts_running" +REC_TS_RECORDING = "reserve_running" +REC_CHANGING_CANTAINER = "convert_mkv_mp4_runnings" +REC_AVI_TO_MKV = "convert_avi_mkv" +REC_AVI_TO_MP4 = "convert_avi_mp4" +REC_MKV_TO_MP4 = "convert_mkv_mp4" + +REC_MOVE_END = "move_end" + +REC_AUTO_SUGGEST_REC = "auto_suggest_rec" +REC_AUTO_SUGGEST_DECODE = "auto_suggest_dec" +REC_AUTO_SUGGEST_ENCODE = "auto_suggest_enc" +REC_AUTO_SUGGEST_AVI2FP = "auto_suggest_avi2fp" +REC_AUTO_SUGGEST_AP2FP = "auto_suggest_ap2fp" +REC_AUTO_KEYWORD = "auto_keyword" +REC_BAYES_SUGGEST ="bayes_suggest" + +global BONTSDEMUX_DELAY +BONTSDEMUX_DELAY="0" + +version = 100 +version_str="0.9.10" + +global verbose_level_now +global log_level_now + +try: + log_level_now=int(configreader.getConfLog("log_level")) + verbose_level_now=int(configreader.getConfLog("verbose_level")) +except: + log_level_now=900 + verbose_level_now=400 +def printutf8(unicode,verbose_level=500): + if verbose_level_now > verbose_level: + try: + str=unicode.encode('utf-8') + print str + except Exception, inst: + recdblist.addCommonlogEX("Error", "printutf8(recdblist.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) +def printuft8ex(unicode,verbose_level=500,log_level=500): + str=unicode.encode('utf-8') + if verbose_level_now > verbose_level: + print str + logfname="/var/log/rec10" + mode="a" + if log_level_now > log_level: + if os.path.exists(logfname): + f=open(logfname,mode) + f.write(str+"\n") + f.close() +def addCommonlogEX(type,place,inst,txt,verbose_level=500,log_level=500): + lt=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+u":" + if txt=="": + lt=lt+u"["+type+u"] "+place+u" "+inst + else: + lt=lt+u"["+type+u"] "+place+u" "+inst+u"\n"+txt + lt=lt.encode('utf-8') + logfname="/var/log/rec10" + mode="a" + if verbose_level_now > verbose_level: + print lt + if log_level_now > log_level: + if os.path.exists(logfname): + f=open(logfname,mode) + f.write(lt+"\n") + f.close() +def addCommandLog(tspath,log_title,cmd,cmd_log=""): + addLog(tspath,cmd,log_title+u"ログ-コマンド") + addLog(tspath,cmd_log,log_title+u"ログ-詳細") +def addLog(tspath,txt,log_title): + logo=tspath + logo=logo.replace("_1.wav",".ts") + logo=logo.replace("_2.wav",".ts") + logo=logo.replace("_1.aac",".ts") + logo=logo.replace("_2.aac",".ts") + logo=logo.replace("_1.mp3",".ts") + logo=logo.replace("_2.mp3",".ts") + logo=logo.replace(".ts.tsmix",".ts") + logo=logo.replace(".ts.b25",".ts") + logo=logo.replace(".sa.avi",".ts") + logo=logo.replace(".m2v",".ts") + logo=logo.replace(".avi",".ts") + logo=logo.replace(".mkv",".ts") + logo=logo.replace(".wav",".ts") + logo=logo.replace(".mp4",".ts") + logo=logo.replace(".mp3",".ts") + logo=logo.replace(".aac",".ts") + logo=logo.replace(".srt",".ts") + logo=logo.replace(".ts",".log") + f=open(logo,'a') + s=len(txt) + stxt="" + if s>3000: + stxt=txt[0:1500]+"\n\n(ry..)\n" + st=txt[s-1500:].find("\n") + if st>0: + stxt=stxt+txt[s-1500+st:] + else: + stxt=txt + txtw= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + txtw=txtw+"\n####"+log_title+"####\n"+stxt + f.write(txtw.encode('utf-8')) + f.close() diff --git a/rec10/trunk/src/recque.py b/rec10/trunk/src/recque.py index 77125f1..0471326 100644 --- a/rec10/trunk/src/recque.py +++ b/rec10/trunk/src/recque.py @@ -1,66 +1,66 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import datetime -import os -import os.path -import glob -import time -import traceback - -import configreader -import recdblist -import recdb -def writeRecQue(parentpath,chtxt,title,opts): - f=open(os.path.join(parentpath,title+".recq"),"w") - optt=opts - #optt=opts.replace("E","") - #optt=optt.replace("D","") - #optt=optt.replace("R","") - str="99"+","+datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+","+configreader.getEnvSetting("iff")+","+chtxt+","+title+","+optt - f.write(str.encode('utf-8')) - f.close() - -def readRecQue(recquepath): - f=open(recquepath,"r") - line = unicode(f.readline(),'utf-8') - title="" - opts="" - chtxt="" - while line: - linec=line.split(",") - if len(linec)>3: - if linec[0]=="99": - title=linec[4] - opts=linec[5] - chtxt=linec[2]+u"_"+linec[3] - break - line = unicode(f.readline(),'utf-8') - dbkey="" - if opts.find("E"): - dbkey="" - opts=opts.replace("E","") - if opts.find("D"): - dbkey=recdblist.REC_ENCODE_QUE - opts=opts.replace("D","") - if opts.find("R"): - dbkey=recdblist.REC_TS_DECODE_QUE - opts=opts.replace("R","") - bt=datetime.datetime.now()+datetime.timedelta(minutes=5) - et=bt+datetime.timedelta(minutes=30) - btime=bt.strftime("%Y-%m-%d %H:%M:%S") - etime=et.strftime("%Y-%m-%d %H:%M:%S") - if len(dbkey)>2: - recdb.rec_reckey(dbkey, title, chtxt, btime, etime, opts) -def searchRecQue(folderpath): - for file in glob.glob(os.path.join(folderpath,"*.recq")): - dtime = time.time()-os.path.getmtime(file) - dtime = int(dtime) - if dtime > 300: - try: - readRecQue(os.path.join(folderpath, file)) - os.remove(os.path.join(folderpath, file)) - except Exception, inst: - recdblist.addCommonlogEX("Error", "searchRecQue(recque.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) - \ No newline at end of file +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import datetime +import os +import os.path +import glob +import time +import traceback + +import configreader +import recdblist +import recdb +def writeRecQue(parentpath,chtxt,title,opts): + f=open(os.path.join(parentpath,title+".recq"),"w") + optt=opts + #optt=opts.replace("E","") + #optt=optt.replace("D","") + #optt=optt.replace("R","") + str="99"+","+datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+","+configreader.getConfEnv("iff")+","+chtxt+","+title+","+optt + f.write(str.encode('utf-8')) + f.close() + +def readRecQue(recquepath): + f=open(recquepath,"r") + line = unicode(f.readline(),'utf-8') + title="" + opts="" + chtxt="" + while line: + linec=line.split(",") + if len(linec)>3: + if linec[0]=="99": + title=linec[4] + opts=linec[5] + chtxt=linec[2]+u"_"+linec[3] + break + line = unicode(f.readline(),'utf-8') + dbkey="" + if opts.find("E"): + dbkey="" + opts=opts.replace("E","") + if opts.find("D"): + dbkey=recdblist.REC_ENCODE_QUE + opts=opts.replace("D","") + if opts.find("R"): + dbkey=recdblist.REC_TS_DECODE_QUE + opts=opts.replace("R","") + bt=datetime.datetime.now()+datetime.timedelta(minutes=5) + et=bt+datetime.timedelta(minutes=30) + btime=bt.strftime("%Y-%m-%d %H:%M:%S") + etime=et.strftime("%Y-%m-%d %H:%M:%S") + if len(dbkey)>2: + recdb.reserveReckey(dbkey, title, chtxt, btime, etime, opts) +def searchRecQue(folderpath): + for file in glob.glob(os.path.join(folderpath,"*.recq")): + dtime = time.time()-os.path.getmtime(file) + dtime = int(dtime) + if dtime > 300: + try: + readRecQue(os.path.join(folderpath, file)) + os.remove(os.path.join(folderpath, file)) + except Exception, inst: + recdblist.addCommonlogEX("Error", "searchRecQue(recque.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) + diff --git a/rec10/trunk/src/scan_ch.py b/rec10/trunk/src/scan_ch.py index 5ec6685..e94c3c2 100644 --- a/rec10/trunk/src/scan_ch.py +++ b/rec10/trunk/src/scan_ch.py @@ -1,114 +1,114 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import os -import os.path -import time -import commands -import traceback - -import rec10d -import configreader -import recdblist -import tv2ts -tmppath = configreader.getPathSetting("tmp")+"/" -tssplitterp = configreader.getPathSetting("tssplitter") -def searchCh(): - #地上デジタル - for i in xrange(13,62): - recdblist.printuft8ex(u"チャンネルスキャン:地上デジタル CH "+str(i), 200, 200) - if checkTs(str(i))>0: - addCh(str(i),u"te"+str(i),str(i)) - #BSデジタル - recdblist.printuft8ex(u"チャンネルスキャン:BSデジタル "+str(i), 200, 200) - for i in xrange(100,240): - recdblist.printuft8ex(u"チャンネルスキャン:BSデジタル CH "+str(i), 200, 200) - if checkTs(str(i))>0: - addCh(str(i),u"bs",str(i)) - #スカパーe2! - #http://www5e.biglobe.ne.jp/~kazu_f/digital-sat/trapon-nsat110.html - # - #CS1ネットワーク - if checkTs("CS2")>0: - addCh("CS2","cs1","CS2") - if checkTs("CS8")>0: - addCh("CS8","cs1","CS8") - if checkTs("CS10")>0: - addCh("CS10","cs1","CS10") - #CS2ネットワーク - if checkTs("CS4")>0: - addCh("CS4","cs2","CS4") - if checkTs("CS6")>0: - addCh("CS6","cs2","CS6") - if checkTs("CS12")>0: - addCh("CS12","cs2","CS12") - if checkTs("CS14")>0: - addCh("CS14","cs2","CS14") - if checkTs("CS16")>0: - addCh("CS16","cs2","CS16") - if checkTs("CS18")>0: - addCh("CS18","cs2","CS18") - if checkTs("CS20")>0: - addCh("CS20","cs2","CS20") - if checkTs("CS22")>0: - addCh("CS22","cs2","CS22") - if checkTs("CS24")>0: - addCh("CS24","cs2","CS24") -def checkTs(ch): - tv2ts.tv2b25ts(os.path.join(tmppath,"ch_"+str(ch)+".ts"), ch, "1") - if os.path.exists(os.path.join(tmppath,"ch_"+str(ch)+".ts")): - os.remove(os.path.join(tmppath,"ch_"+str(ch)+".ts")) - return 1 - else: - return 0 -def addCh(ch,bctype,chtxthead): - prglist=getChProgNum(ch) - for lstr in prglist: - #print [bctype,chtxthead+"_"+lstr, ch, lstr] - try: - if ch.find("bs")>-1: - if int(lstr)<300: - rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr, u"2010-01-01 00:00:00") - else: - rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr, u"2010-01-01 00:00:00") - except Exception, inst: - recdblist.addCommonlogEX("Warning", "addCh (scan_ch.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) -def getChProgNum(ch): - pout=os.path.join(tmppath,"ch_"+str(ch)+".ts") - tv2ts.tv2tsmix(pout, ch, "10") - retl=getTsProgNum(ch,pout) - os.remove(pout) - return retl -def getTsProgNum(ch,tspath): - pin=tspath - pout=os.path.join(tmppath,"chscan.txt") - chopt="-ch" - if ch.find("CS")>-1: - chopt="-cs" - elif int(ch)>99: - chopt="-bs" - doexe = tssplitterp + " "+chopt+" \""+ pin + "\" \""+ pout + "\"" - doexe = "nice -n 18 " + doexe - os.environ['LANG']="ja_JP.UTF-8" - txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8','ignore') - f=open(pout) - lines=f.readlines() - f.close() - ret=[] - for l in lines: - try: - l=l.replace(" ","") - l=l.replace("\n","") - ret.append(str(int(l))) - except: - "" - recdblist.addLog(pin, doexe, u"TsSplitログ-コマンド") - recdblist.addLog(pin, txt, u"TsSplitログ-詳細") - time.sleep(1) - try: - "" - #os.remove(pout) - except: - "" - return ret \ No newline at end of file +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import os +import os.path +import time +import commands +import traceback + +import rec10d +import configreader +import recdblist +import tv2ts +tmppath = configreader.getConfPath("tmp")+"/" +tssplitterp = configreader.getConfPath("tssplitter") +def searchCh(): + #地上デジタル + for i in xrange(13,62): + recdblist.printuft8ex(u"チャンネルスキャン:地上デジタル CH "+str(i), 200, 200) + if checkTs(str(i))>0: + addCh(str(i),u"te"+str(i),str(i)) + #BSデジタル + recdblist.printuft8ex(u"チャンネルスキャン:BSデジタル "+str(i), 200, 200) + for i in xrange(100,240): + recdblist.printuft8ex(u"チャンネルスキャン:BSデジタル CH "+str(i), 200, 200) + if checkTs(str(i))>0: + addCh(str(i),u"bs",str(i)) + #スカパーe2! + #http://www5e.biglobe.ne.jp/~kazu_f/digital-sat/trapon-nsat110.html + # + #CS1ネットワーク + if checkTs("CS2")>0: + addCh("CS2","cs1","CS2") + if checkTs("CS8")>0: + addCh("CS8","cs1","CS8") + if checkTs("CS10")>0: + addCh("CS10","cs1","CS10") + #CS2ネットワーク + if checkTs("CS4")>0: + addCh("CS4","cs2","CS4") + if checkTs("CS6")>0: + addCh("CS6","cs2","CS6") + if checkTs("CS12")>0: + addCh("CS12","cs2","CS12") + if checkTs("CS14")>0: + addCh("CS14","cs2","CS14") + if checkTs("CS16")>0: + addCh("CS16","cs2","CS16") + if checkTs("CS18")>0: + addCh("CS18","cs2","CS18") + if checkTs("CS20")>0: + addCh("CS20","cs2","CS20") + if checkTs("CS22")>0: + addCh("CS22","cs2","CS22") + if checkTs("CS24")>0: + addCh("CS24","cs2","CS24") +def checkTs(ch): + tv2ts.tv2b25ts(os.path.join(tmppath,"ch_"+str(ch)+".ts"), ch, "1") + if os.path.exists(os.path.join(tmppath,"ch_"+str(ch)+".ts")): + os.remove(os.path.join(tmppath,"ch_"+str(ch)+".ts")) + return 1 + else: + return 0 +def addCh(ch,bctype,chtxthead): + prglist=getChProgNum(ch) + for lstr in prglist: + #print [bctype,chtxthead+"_"+lstr, ch, lstr] + try: + if ch.find("bs")>-1: + if int(lstr)<300: + rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr, u"2010-01-01 00:00:00") + else: + rec10d.rec10db.add_epg_ch(bctype,chtxthead+"_"+lstr, ch, lstr, u"2010-01-01 00:00:00") + except Exception, inst: + recdblist.addCommonlogEX("Warning", "addCh (scan_ch.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) +def getChProgNum(ch): + pout=os.path.join(tmppath,"ch_"+str(ch)+".ts") + tv2ts.tv2tsmix(pout, ch, "10") + retl=getTsProgNum(ch,pout) + os.remove(pout) + return retl +def getTsProgNum(ch,tspath): + pin=tspath + pout=os.path.join(tmppath,"chscan.txt") + chopt="-ch" + if ch.find("CS")>-1: + chopt="-cs" + elif int(ch)>99: + chopt="-bs" + doexe = tssplitterp + " "+chopt+" \""+ pin + "\" \""+ pout + "\"" + doexe = "nice -n 18 " + doexe + os.environ['LANG']="ja_JP.UTF-8" + txt = unicode(commands.getoutput(doexe.encode('utf-8')),'utf-8','ignore') + f=open(pout) + lines=f.readlines() + f.close() + ret=[] + for l in lines: + try: + l=l.replace(" ","") + l=l.replace("\n","") + ret.append(str(int(l))) + except: + "" + recdblist.addLog(pin, doexe, u"TsSplitログ-コマンド") + recdblist.addLog(pin, txt, u"TsSplitログ-詳細") + time.sleep(1) + try: + "" + #os.remove(pout) + except: + "" + return ret diff --git a/rec10/trunk/src/status.py b/rec10/trunk/src/status.py index 1248e57..b8fee6d 100755 --- a/rec10/trunk/src/status.py +++ b/rec10/trunk/src/status.py @@ -1,41 +1,41 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import configreader -import os -import rec10d -path = os.path.dirname(os.path.abspath(__file__)) + "/" -def changeEncoding(i): - """ - iはint 増減 - """ - rec10d.rec10db.change_ts2avi_in_status(i) -def changeTERecording(i): - rec10d.rec10db.change_terec_in_status(i) -def changeBSCSRecording(i): - rec10d.rec10db.change_bscsrec_in_status(i) -def changeB25Decoding(i): - rec10d.rec10db.change_b252ts_in_status(i) -def getEncoding(): - """ - エンコードしている数を帰すint型 - """ - return int(rec10d.rec10db.select_all_in_status()[0][0]) -def getTERecording(): - return int(rec10d.rec10db.select_all_in_status()[0][1]) -def getBSCSRecording(): - return int(rec10d.rec10db.select_all_in_status()[0][2]) -def getB25Decoding(): - return int(rec10d.rec10db.select_all_in_status()[0][3]) -def getSettings_auto_bayes(): - return int(rec10d.rec10db.select_all_in_settings()[0][1]) -def getSettings_auto_jbk(): - return int(rec10d.rec10db.select_all_in_settings()[0][0]) -def getSettings_auto_del_tmp(): - return int(rec10d.rec10db.select_all_in_settings()[0][2]) -def getSettings_auto_opt(): - return rec10d.rec10db.select_all_in_settings()[0][3] - -def getRecordingMax(): - return [int(configreader.getEnvSetting("te_max")),int(configreader.getEnvSetting("bscs_max"))] +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import configreader +import os +import rec10d +path = os.path.dirname(os.path.abspath(__file__)) + "/" +def changeEncoding(i): + """ + iはint 増減 + """ + rec10d.rec10db.change_ts2avi_in_status(i) +def changeTERecording(i): + rec10d.rec10db.change_terec_in_status(i) +def changeBSCSRecording(i): + rec10d.rec10db.change_bscsrec_in_status(i) +def changeB25Decoding(i): + rec10d.rec10db.change_b252ts_in_status(i) +def getEncoding(): + """ + エンコードしている数を帰すint型 + """ + return int(rec10d.rec10db.select_all_in_status()[0][0]) +def getTERecording(): + return int(rec10d.rec10db.select_all_in_status()[0][1]) +def getBSCSRecording(): + return int(rec10d.rec10db.select_all_in_status()[0][2]) +def getB25Decoding(): + return int(rec10d.rec10db.select_all_in_status()[0][3]) +def getSettings_auto_bayes(): + return int(rec10d.rec10db.select_all_in_settings()[0][1]) +def getSettings_auto_jbk(): + return int(rec10d.rec10db.select_all_in_settings()[0][0]) +def getSettings_auto_del_tmp(): + return int(rec10d.rec10db.select_all_in_settings()[0][2]) +def getSettings_auto_opt(): + return rec10d.rec10db.select_all_in_settings()[0][3] + +def getRecordingMax(): + return [int(configreader.getConfEnv("te_max")),int(configreader.getConfEnv("bscs_max"))] diff --git a/rec10/trunk/src/timerec.py b/rec10/trunk/src/timerec.py index caef0a2..8d03302 100644 --- a/rec10/trunk/src/timerec.py +++ b/rec10/trunk/src/timerec.py @@ -1,714 +1,714 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import datetime -import os -import os.path -import re -import sys -import time -import shutil -import traceback - -import auto_rec -import auto_process -import chdb -import configreader -import epgdb -import rec10d -import recdb -import status -import tv2audio -import tv2avi -import tv2mkv -import tv2mp4 -import install -import recdblist -import recque -recpath = configreader.getPathSetting('recpath') -movepath = configreader.getPathSetting('move_destpath') -path = str(os.path.dirname(os.path.abspath(__file__))) + "/" -def task(): - """ - 数分毎に実行されるタスク処理 - 予定によって子プロセスを生成し処理する。 - """ - try: - if rec10d.rec10db.select_installed_in_status()==0 or rec10d.rec10db.select_version_in_status() 0: - pid = os.fork() - if pid != 0: - "" - else: - i = 0 - for bctype in update: - recnum = 0 - if bctype.find('te') > -1: - recnum = status.getTERecording() + recdb.countRecNow_minutes_TE("10") - recdblist.printutf8(u"放送種別:"+bctype + u"||該当チューナー実行中件数:" + str(status.getTERecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_TE("10")),verbose_level=800) - recnum = int(configreader.getEnvSetting("te_max")) -recnum - else: - recnum = status.getBSCSRecording() + recdb.countRecNow_minutes_BSCS("10") - recdblist.printutf8(u"放送種別:"+bctype + u"||該当チューナー実行中件数:" + str(status.getBSCSRecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_BSCS("10")),verbose_level=800) - recnum = int(configreader.getEnvSetting("bscs_max")) -recnum - if recnum >0 : - recdblist.printutf8(str(update),verbose_level=750) - rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "0") - epgdb.updateForBctype(bctype) - update = chdb.update() - i = i + 1 - if i > 0: - break - time.sleep(5) - auto_process.update_all_timeline_epg() - sys.exit() - else: - pid = os.fork() - if pid != 0: - "" - else: - auto_process.update_all_timeline_epg() - sys.exit() - for task in tasks: - typetxt = task["type"] - try: - chtxt = task['chtxt'] - except: - chtxt = "" - try: - title = task['title'] - except: - title = "" - try: - btime = task['btime'] - bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") - except: - btime = "" - bt = datetime.datetime.strptime("2009-01-01 00:00:00", "%Y-%m-%d %H:%M:%S") - try: - etime = task['etime'] - et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") - except: - etime = "" - et = datetime.datetime.strptime("2009-01-01 00:00:00", "%Y-%m-%d %H:%M:%S") - try: - opt = task['opt'] - except: - opt = "" - tnow = datetime.datetime.now() - dtt = bt-tnow - dt = dtt.days * 24 * 60 * 60 + dtt.seconds - if task["type"] == recdblist.REC_RESERVE:#"res,"+chtxt+","+title+","+btime+","+etime+","+opt - pid = os.fork() - if pid != 0:#親プロセスの場合 - "" - else:#子プロセスの場合 アップデートを行って終了 - type_reserve(task["type"],chtxt,title,bt,et,opt) - sys.exit() - elif task["type"] == recdblist.REC_KEYWORD:#"key,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt - deltatime = task['deltatime'] - pid = os.fork() - if pid != 0:#親プロセスの場合 - "" - else:#子プロセスの場合 アップデートを行って終了 - type_keyword(task["type"],chtxt,title, bt, et, opt, deltatime) - sys.exit() - elif task["type"] == recdblist.REC_KEYWORD_EVERY_SOME_DAYS:#"keyevery,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt+","+deltaday - deltatime = task['deltatime'] - deltaday = task['deltaday'] - try: - keyeverycounter=task['counter'] - except: - keyeverycounter=-1 - pid = os.fork() - if pid != 0:#親プロセスの場合 - "" - else:#子プロセスの場合 アップデートを行って終了 - type_keyword_every_day(task["type"],chtxt, title, bt, et, opt, deltatime, deltaday,keyeverycounter) - sys.exit() - elif task["type"] == recdblist.REC_FINAL_RESERVE:#"rec,"+chtxt+","+title+","+btime+","+etime+","+opt - pid = os.fork() - if pid != 0:#親プロセスの場合 - "" - else:#子プロセスの場合 アップデートを行って終了 - type_final(task["type"],chtxt, title, bt, et, opt) - sys.exit() - elif task["type"] == recdblist.REC_TS_DECODE_QUE: - b25num=b25num+1 - pid = os.fork() - if pid != 0:#親プロセスの場合 - "" - else:#子プロセスの場合 アップデートを行って終了 - time.sleep(5*b25num) - type_decode_que(task["type"],chtxt, title, bt, et, opt) - sys.exit() - elif task["type"] == recdblist.REC_ENCODE_QUE: - encodenum=encodenum+1 - pid = os.fork() - if pid != 0:#親プロセスの場合 - "" - else:#子プロセスの場合 アップデートを行って終了 - time.sleep(5*encodenum) - type_encode_que(task["type"],chtxt, title, bt, et, opt) - sys.exit() - elif task["type"] == recdblist.REC_AVI_TO_MKV: - if dt < 10 * 60: - pid = os.fork() - if pid > 0:#親プロセスの場合 - "" - else: - makeMP4=0 - try: - if configreader.getEnvSetting("make_mp4")==1: - makeMP4=1 - except: - "" - if re.search("m", opt): - makeMP4=0 - if re.search("4", opt): - makeMP4=1 - recdb.del_reckey(recdblist.REC_AVI_TO_MKV, title, chtxt, btime) - recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt) - if makeMP4==1: - tv2mp4.raw2mp4(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mp4"),opt) - else: - tv2mkv.raw2mkv(os.path.join(recpath,title+".264"),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: - if dt < 10 * 60: - pid = os.fork() - if pid > 0:#親プロセスの場合 - "" - else: - makeMP4=0 - try: - if configreader.getEnvSetting("make_mp4")==1: - makeMP4=1 - except: - "" - if re.search("m", opt): - makeMP4=0 - if re.search("4", opt): - makeMP4=1 - recdb.del_reckey(recdblist.REC_AVI_TO_MP4, title, chtxt, btime) - recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt) - if makeMP4==1: - tv2mp4.ts2mp4(pin, pout, opt) - tv2mp4.raw2mp4(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mp4"),opt) - else: - tv2mkv.raw2mkv(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mkv"),opt) - recdb.del_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime) - sys.exit() - elif task["type"] == recdblist.REC_MKV_TO_MP4: - if dt < 10 * 60: - pid = os.fork() - if pid > 0:#親プロセスの場合 - "" - else: - recdb.del_reckey(recdblist.REC_MKV_TO_MP4, title, chtxt, btime) - recdb.rec_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt) - tv2mp4.mkv2mp4(os.path.join(recpath,title+".mkv"),os.path.join(recpath,title+".mp4")) - recdb.del_reckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime) - sys.exit() - sys.exit() -def search_keyword(key): - tnow = datetime.datetime.now() - nows =tnow.strftime("%Y-%m-%d %H:%M:%S") - for k,auto,opt in key: - recdatum = epgdb.searchTimeAuto(k,nows, "144") - for recdata in recdatum: - if recdata[1] != "": - chtxtt = recdata[0] - titlet = recdata[1] - btimet = recdata[2] - etimet = recdata[3] - btt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S") - ett = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S") - btimet = btt.strftime("%Y-%m-%d %H:%M:%S") - etimet = ett.strftime("%Y-%m-%d %H:%M:%S") - #if status.getSettings_auto_jbk()==1: - if auto==1 or status.getSettings_auto_jbk()==1: - topt=opt - if len(topt)==0: - topt=status.getSettings_auto_opt() - try: - maxnum=0 - if len(ch['ch'])>2: - maxnum=epgdb.count_schedule_timeline(btimet, etimet)[1] - maxnum=int(configreader.getEnvSetting("bscs_max"))-maxnum - else: - maxnum=epgdb.count_schedule_timeline(btimet, etimet)[0] - maxnum=int(configreader.getEnvSetting("te_max"))-maxnum - if maxnum>0: - if recdb.checkduplicate(titlet, chtxtt, btimet, etimet)==0: - recdb.recreserv(titlet,chtxtt, btimet, etimet,topt) - except Exception, inst: - recdblist.addCommonlogEX("Error", "search_keyword_auto_jbk(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) - else: - try: - recdb.add_auto_keyword(chtxtt, titlet, btimet, etimet) - except Exception, inst: - recdblist.addCommonlogEX("Error", "search_keyword(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) -def type_reserve(typetxt,chtxt,title,bt,et,opt): - btime = bt.strftime("%Y-%m-%d %H:%M:%S") - etime = et.strftime("%Y-%m-%d %H:%M:%S") - typetxtnow=typetxt - typetxtfinal="" - if typetxt==recdblist.REC_RESERVE: - typetxtfinal=recdblist.REC_FINAL_RESERVE - tnow = datetime.datetime.now() - dtt = bt-tnow - dt = dtt.days * 24 * 60 * 60 + dtt.seconds - if (dt < 58 * 60 and dt > 30 * 60): - bctypet = chdb.searchFromCHtxt(chtxt)['bctype'] - chdatat = rec10d.rec10db.select_by_bctype_epg_ch(bctypet) - dt1 = datetime.datetime.strptime(chdatat[0][4], "%Y-%m-%d %H:%M:%S")-datetime.datetime.now() - dt1 = dt1.days * 24 * 60 * 60 + dt1.seconds - if dt1 < 60 * 60: - recdata = epgdb.searchTime(title, btime, "5", chtxt) - chtxtn = recdata[0] - titlen = recdata[1] - btimen = recdata[2] - etimen = recdata[3] - exp = recdata[4] - longexp = recdata[5] - category=recdata[6] - bt = datetime.datetime.strptime(btimen, "%Y-%m-%d %H:%M:%S") - et = datetime.datetime.strptime(etimen, "%Y-%m-%d %H:%M:%S") - btimen = bt.strftime("%Y-%m-%d %H:%M:%S") - etimen = et.strftime("%Y-%m-%d %H:%M:%S") - if chtxt != "": - try: - recdb.del_reckey(typetxtnow, title, chtxt, btime) - recdb.rec_reckey(typetxtfinal, titlen, chtxtn, btimen, etimen, opt) - recdb.rec_reclog(titlen, chtxtn, btimen, etimen, opt, exp, longexp, category) - auto_rec.addKey(chtxt, titlen,exp+" "+longexp) - auto_rec.addKey("ALL", titlen,exp+" "+longexp) - recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen) - except Exception, inst: - recdblist.addCommonlogEX("Error", "Oikake DB(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) - else: - recdblist.printutf8(u"追いかけ機能エラー:番組データが見付かりません。") - else: - if rec10d.rec10db.select_by_bctype_epg_ch(bctypet)[0][5] != "0": - rec10d.rec10db.update_status_by_bctype_epg_ch(bctypet, "3") - sys.exit() - elif (dt <= 30 * 60 and dt > 20 * 60): - recdata = epgdb.searchTime(title, btime, "5", chtxt) - chtxtn = recdata[0] - titlen = recdata[1] - btimen = recdata[2] - etimen = recdata[3] - exp = recdata[4] - longexp = recdata[5] - category=recdata[6] - bt = datetime.datetime.strptime(btimen, "%Y-%m-%d %H:%M:%S") - et = datetime.datetime.strptime(etimen, "%Y-%m-%d %H:%M:%S") - btimen = bt.strftime("%Y-%m-%d %H:%M:%S") - etimen = et.strftime("%Y-%m-%d %H:%M:%S") - if chtxt != "": - try: - recdb.del_reckey(typetxtnow, title, chtxt, btime) - recdb.rec_reckey(typetxtfinal, titlen, chtxtn, btimen, etimen, opt) - recdb.rec_reclog(titlen, chtxtn, btimen, etimen, opt, exp, longexp, category) - auto_rec.addKey(chtxt, titlen,exp+" "+longexp) - auto_rec.addKey("ALL", titlen,exp+" "+longexp) - #recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen) - recdblist.addCommonlogEX(u"通常", "Oikake (timerec.py)",u"追いかけ機能実行中",u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen,log_level=500) - except Exception, inst: - recdblist.addCommonlogEX("Error", "Oikake DB(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) - elif dt <= 20 * 60: - try: - recdb.del_reckey(typetxtnow, title, chtxt, btime) - recdb.rec_reckey(typetxtfinal, title, chtxt, btime, etime, opt) - except Exception, inst: - recdblist.addCommonlogEX("Error", "Oikake DB(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) -def type_final(typetxt,chtxt,title,bt,et,opt): - btime = bt.strftime("%Y-%m-%d %H:%M:%S") - etime = et.strftime("%Y-%m-%d %H:%M:%S") - typetxtnow=typetxt - typetxting="" - typetxtdecque="" - if typetxt==recdblist.REC_FINAL_RESERVE: - typetxting=recdblist.REC_TS_RECORDING - typetxtdecque=recdblist.REC_TS_DECODE_QUE - tnow = datetime.datetime.now() - dtt = bt-tnow - dt = dtt.days * 24 * 60 * 60 + dtt.seconds - if dt < 6 * 60 and dt > 0: - newtitle=title - recdb.del_reckey(typetxtnow, title, chtxt, btime) - testpath=[os.path.join(recpath,title+".ts.b25")] - testpath.append(os.path.join(recpath,title+".ts")) - testpath.append(os.path.join(recpath,title+".avi")) - testpath.append(os.path.join(recpath,title+".mp4")) - testpath.append(os.path.join(recpath,title+".log")) - tcheck=0 - for ti in testpath: - if os.path.exists(ti): - tcheck=tcheck+1 - if re.search("N", opt) or tcheck>0: - iff="" - try: - iff=u"("+configreader.getEnvSetting("iff")+u")_" - except: - iff="" - newtime=bt - newtitle=newtitle+u"_"+iff+newtime.strftime("%Y-%m-%dT%H-%M-%S") - recdb.rec_reckey(typetxting, newtitle, chtxt, btime, etime, opt) - recdblist.addCommonlogEX(u"通常","timerec.py",u"録画開始 "+newtitle+" "+btime+" "+etime,"",log_level=500) - tv2avi.timetv2b25(recpath + "/" + newtitle + ".avi", chtxt, btime, etime, opt) - recdb.del_reckey(typetxting, newtitle, chtxt, btime) - if not re.search("R", opt): - tnow = datetime.datetime.now() - bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") - et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") - dt = tnow-bt - bt = tnow + datetime.timedelta(seconds=600) - et = et + dt + datetime.timedelta(seconds=600) - btime = bt.strftime("%Y-%m-%d %H:%M:%S") - etime = et.strftime("%Y-%m-%d %H:%M:%S") - recdb.rec_reckey(typetxtdecque, newtitle, chtxt, btime, etime, opt) - else: - try: - try: - shutil.copy(os.path.join(recpath,title+".ts.b25"), os.path.join(movepath,title+".ts.b25")) - except: - "" - try: - os.chmod(os.path.join(movepath,title+".ts.b25"),0777) - except: - "" - recque.writeRecQue(movepath, chtxt, title, opt) - try: - os.chmod(os.path.join(movepath,title+".recq"),0777) - except: - "" - except Exception, inst: - recdblist.addCommonlogEX("Error", "Move option(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) - recdb.rec_reckey(recdblist.REC_MOVE_END, newtitle, chtxt, btime, etime, opt) - sys.exit() -def type_keyword(typetxt,chtxt,title,bt,et,opt,deltatime): - btime = bt.strftime("%Y-%m-%d %H:%M:%S") - etime = et.strftime("%Y-%m-%d %H:%M:%S") - typetxtnow=typetxt - typetxtres="" - if typetxt==recdblist.REC_KEYWORD: - typetxtres=recdblist.REC_RESERVE - tnow = datetime.datetime.now() - dtt = bt-tnow - dt = dtt.days * 24 * 60 * 60 + dtt.seconds - recdblist.printutf8(str(dt), verbose_level=800) - if dt < 90 * 60: - recdata = epgdb.searchTime(title, btime, deltatime, chtxt) - if recdata[1] != "": - chtxtt = recdata[0] - titlet = recdata[1] - btimet = recdata[2] - etimet = recdata[3] - exp = recdata[4] - longexp = recdata[5] - category=recdata[6] - bt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S") - et = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S") - btimet = bt.strftime("%Y-%m-%d %H:%M:%S") - etimet = et.strftime("%Y-%m-%d %H:%M:%S") - #try: - recdb.del_reckey(typetxtnow, title, chtxt, btime) - recdb.rec_reckey(typetxtres, titlet, chtxt, btimet, etimet, opt) - recdb.rec_reclog(titlet, chtxtt, btimet, etimet, opt, exp,longexp,category) - auto_rec.addKey(chtxt, titlet,exp+" "+longexp) - auto_rec.addKey("ALL", titlet,exp+" "+longexp) - recdblist.addCommonlogEX(u"通常","timerec.py",u"key "+title+u" : "+titlet+u" "+btimet+u" "+etimet,"",log_level=500) - #except Exception, inst: - # recdblist.printutf8("Error happened in REC_KEYWORD DB") - # recdblist.printutf8(type(inst)) - # recdblist.printutf8(inst) - else: - recdblist.printutf8("nothing match") -def type_keyword_every_day(type,chtxt,title,bt,et,opt,deltatime,deltaday,counter): - btime = bt.strftime("%Y-%m-%d %H:%M:%S") - etime = et.strftime("%Y-%m-%d %H:%M:%S") - tnow = datetime.datetime.now() - dtt = bt-tnow - dt = dtt.days * 24 * 60 * 60 + dtt.seconds - dd = datetime.timedelta(days=int(deltaday)) - if dtt.days < 0: - recdb.del_reckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime) - 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 dt < 120 * 60: - recdb.del_reckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime) - bt = bt + dd - et = et + dd - btxt = bt.strftime("%Y-%m-%d %H:%M:%S") - etxt = et.strftime("%Y-%m-%d %H:%M:%S") - if counter>0: - recdb.everyreserv(title, chtxt, btxt, etxt, deltatime, opt, deltaday,counter-1) - elif counter==-1: - recdb.everyreserv(title, chtxt, btxt, etxt, deltatime, opt, deltaday,-1) - recdata = epgdb.searchTime(title, btime, deltatime, chtxt) - if recdata[1] != "": - chtxtt = recdata[0] - titlet = recdata[1] - btimet = recdata[2] - etimet = recdata[3] - exp = recdata[4] - longexp = recdata[5] - category=recdata[6] - bt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S") - et = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S") - btimet = bt.strftime("%Y-%m-%d %H:%M:%S") - etimet = et.strftime("%Y-%m-%d %H:%M:%S") - #try: - recdb.keyreserv(titlet, chtxt, btimet, etimet, deltatime, opt) - else: - recdb.keyreserv(title, chtxt, btime, etime, deltatime, opt) -def type_decode_que(typetxt,chtxt,title,bt,et,opt): - btime = bt.strftime("%Y-%m-%d %H:%M:%S") - etime = et.strftime("%Y-%m-%d %H:%M:%S") - tnow = datetime.datetime.now() - dtt = bt-tnow - dt = dtt.days * 24 * 60 * 60 + dtt.seconds - typetxtnow=typetxt - typetxting="" - typetxtmiss="" - typetxtencque="" - if typetxt== recdblist.REC_TS_DECODE_QUE: - typetxting=recdblist.REC_TS_DECODING - typetxtmiss=recdblist.REC_MISS_DECODE - typetxtencque=recdblist.REC_ENCODE_QUE - tnow = datetime.datetime.now() - dtt = bt-tnow - dt = dtt.days * 24 * 60 * 60 + dtt.seconds - if dt < 10 * 60: - if status.getB25Decoding() < 2: - pin = recpath + "/" + title - recdb.del_reckey(typetxtnow, title, chtxt, btime) - recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt) - tv2avi.b252ts(pin, chtxt, btime, etime, opt) - recdb.del_reckey(typetxting, title, chtxt, btime) - if not os.access(recpath + "/" + title + ".ts", os.F_OK): - recdb.del_reckey(typetxting, title, chtxt, btime) - recdb.rec_reckey(typetxtmiss, title, chtxt, btime, etime, opt) - else: - auto_process.deltmpfile(recpath, title, ".ts") - bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") - et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") - dt = et-bt - if not re.search("D", opt): - tnow = datetime.datetime.now() - bt = tnow + datetime.timedelta(seconds=600) - et = bt + dt - btime = bt.strftime("%Y-%m-%d %H:%M:%S") - etime = et.strftime("%Y-%m-%d %H:%M:%S") - recdb.rec_reckey(typetxtencque, title, chtxt, btime, etime, opt) - else: - try: - try: - shutil.copy(os.path.join(recpath,title+".ts"), os.path.join(movepath,title+".ts")) - except: - "" - try: - os.chmod(os.path.join(movepath,title+".ts"),0777) - except: - "" - recque.writeRecQue(movepath, chtxt, title, opt) - try: - os.chmod(os.path.join(movepath,title+".recq"),0777) - except: - "" - time.sleep(5) - if os.path.getsize(os.path.join(recpath,title+".ts"))==os.path.getsize(os.path.join(movepath,title+".ts")): - os.remove(os.path.join(recpath,title+".ts")) - except Exception, inst: - errtxt1="move ts error.\n" - errtxt2=str(type(inst))+"\n" - errtxt2=errtxt2+str(inst) - recdblist.addCommonlogEX("Error", "type_decode_que(timerec.py)", errtxt1,errtxt2+traceback.format_exc(),log_level=200) - recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt) - else: - recdb.del_reckey(typetxtnow, title, chtxt, btime) - bt = bt + datetime.timedelta(seconds=600) - et = et + datetime.timedelta(seconds=600) - btime = bt.strftime("%Y-%m-%d %H:%M:%S") - etime = et.strftime("%Y-%m-%d %H:%M:%S") - recdb.rec_reckey(typetxtnow, title, chtxt, btime, etime, opt) - sys.exit() - -def type_encode_que(typetxt,chtxt,title,bt,et,opt): - btime = bt.strftime("%Y-%m-%d %H:%M:%S") - etime = et.strftime("%Y-%m-%d %H:%M:%S") - tnow = datetime.datetime.now() - dtt = bt-tnow - dt = dtt.days * 24 * 60 * 60 + dtt.seconds - typetxtnow=typetxt - typetxting="" - typetxtfin="" - if typetxt==recdblist.REC_ENCODE_QUE: - typetxting=recdblist.REC_ENCODE_LOCAL - typetxtfin=recdblist.REC_FIN_LOCAL - if dt < 10 * 60: - if status.getEncoding() < int(configreader.getEnvSetting("enc_max")): - recdb.del_reckey(typetxtnow, title, chtxt, btime) - recdb.rec_reckey(typetxting, title, chtxt, btime, etime, opt) - recdblist.printutf8(opt) - pin = recpath + "/" + title + ".ts" - if re.search("d", opt): - pin = recpath + "/" + title + ".m2v" - if not os.path.exists(pin) or os.path.getsize(pin)<100*1000: - paac2 = recpath + "/" + title + "_2.aac" - pmp32 = recpath + "/" + title + "_2.mp3" - if not os.path.exists(paac2) and not os.path.exists(pmp32): - tv2audio.ts2dualaudio_BonTsDemux(os.path.join(recpath, title+".ts"),recdblist.BONTSDEMUX_DELAY,opt) - time.sleep(3) - elif re.search("5", opt): - pin = recpath + "/" + title + ".m2v" - if not os.path.exists(pin) or os.path.getsize(pin)<100*1000: - paac2 = recpath + "/" + title + "_2.aac" - pmp32 = recpath + "/" + title + "_2.mp3" - if not os.path.exists(paac2) and not os.path.exists(pmp32): - tv2audio.ts2pentaaudio_BonTsDemux(os.path.join(recpath, title+".ts"), recdblist.BONTSDEMUX_DELAY, opt) - time.sleep(3) - makeMP4=0 - try: - if configreader.getEnvSetting("make_mp4")=="1": - makeMP4=1 - except: - "" - if re.search("m", opt): - makeMP4=0 - if re.search("4", opt): - makeMP4=1 - recdblist.printutf8(pin) - if not re.search("0", opt): - if makeMP4==1: - pout = recpath + "/" + title + ".mp4" - tv2mp4.ts2mp4(pin, pout, opt) - else: - pout = recpath + "/" + title + ".mkv" - tv2mkv.ts2mkv(pin, pout, opt) - if re.search("8", opt) or re.search("9", opt): - optt=opt - poutt = recpath + "/" + "m_"+title + ".mp4" - if re.search("d", opt) or re.search("5", opt): - if os.path.exists(os.path.join(recpath, "m_"+title+".m2v")): - shutil.move(os.path.join(recpath, title+".m2v"),os.path.join(recpath, "m_"+title+".m2v")) - if os.path.exists(os.path.join(recpath, "m_"+title+"_1.aac")): - shutil.move(os.path.join(recpath, title+"_1.aac"),os.path.join(recpath, "m_"+title+"_1.aac")) - if os.path.exists(os.path.join(recpath, "m_"+title+"_1.mp3")): - shutil.move(os.path.join(recpath, title+"_1.mp3"),os.path.join(recpath, "m_"+title+"_1.mp3")) - if os.path.exists(os.path.join(recpath, "m_"+title+"_2.aac")): - shutil.move(os.path.join(recpath, title+"_2.aac"),os.path.join(recpath, "m_"+title+"_2.aac")) - if os.path.exists(os.path.join(recpath, "m_"+title+"_2.mp3")): - shutil.move(os.path.join(recpath, title+"_2.mp3"),os.path.join(recpath, "m_"+title+"_2.mp3")) - shutil.move(os.path.join(recpath, title+".ts"),os.path.join(recpath, "m_"+title+".ts")) - tv2mp4.ts2mp4(os.path.join(recpath, "m_"+title+".ts"), poutt, optt) - shutil.move(os.path.join(recpath, "m_"+title+".ts"),os.path.join(recpath, title+".ts")) - else: - optt=opt - poutt = recpath + "/" + "m_"+title + ".mp4" - shutil.move(os.path.join(recpath, title+".ts"),os.path.join(recpath, "m_"+title+".ts")) - if re.search("d", opt) or re.search("5", opt): - if os.path.exists(os.path.join(recpath, "m_"+title+".m2v")): - shutil.move(os.path.join(recpath, title+".m2v"),os.path.join(recpath, "m_"+title+".m2v")) - if os.path.exists(os.path.join(recpath, "m_"+title+"_1.aac")): - shutil.move(os.path.join(recpath, title+"_1.aac"),os.path.join(recpath, "m_"+title+"_1.aac")) - if os.path.exists(os.path.join(recpath, "m_"+title+"_1.mp3")): - shutil.move(os.path.join(recpath, title+"_1.mp3"),os.path.join(recpath, "m_"+title+"_1.mp3")) - if os.path.exists(os.path.join(recpath, "m_"+title+"_2.aac")): - shutil.move(os.path.join(recpath, title+"_2.aac"),os.path.join(recpath, "m_"+title+"_2.aac")) - if os.path.exists(os.path.join(recpath, "m_"+title+"_2.mp3")): - shutil.move(os.path.join(recpath, title+"_2.mp3"),os.path.join(recpath, "m_"+title+"_2.mp3")) - tv2mp4.ts2mp4(os.path.join(recpath, "m_"+title+".ts"), poutt, optt) - shutil.move(os.path.join(recpath, "m_"+title+".ts"),os.path.join(recpath, title+".ts")) - recdb.del_reckey(typetxting, title, chtxt, btime) - time.sleep(10) - if re.search("E", opt): - try: - if os.path.exists(os.path.join(recpath,title+".mp4")): - try: - shutil.copy(os.path.join(recpath,title+".mp4"), os.path.join(movepath,title+".mp4")) - except: - "" - try: - os.chmod(os.path.join(movepath,title+".mp4"),0777) - except: - "" - recque.writeRecQue(movepath, chtxt, title, opt) - try: - os.chmod(os.path.join(movepath,title+".recq"),0777) - except: - "" - elif os.path.exists(os.path.join(recpath,title+".mkv")): - try: - shutil.copy(os.path.join(recpath,title+".mkv"), os.path.join(movepath,title+".mkv")) - except: - "" - try: - os.chmod(os.path.join(movepath,title+".mkv"),0777) - except: - "" - recque.writeRecQue(movepath, chtxt, title, opt) - try: - os.chmod(os.path.join(movepath,title+".recq"),0777) - except: - "" - except Exception, inst: - errtxt1="move mkv/mp4 error." - errtxt2=str(type(inst))+"\n" - errtxt2=errtxt2+str(inst) - recdblist.addCommonlogEX("Error", "type_encode_que(timerec.py)", errtxt1,errtxt2+traceback.format_exc(),log_level=200) - recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt) - recdb.rec_reckey(typetxtfin, title, chtxt, btime, etime, opt) - sys.exit() - else: - recdb.del_reckey(typetxtnow, title, chtxt, btime) - bt = bt + datetime.timedelta(seconds=600) - et = et + datetime.timedelta(seconds=600) - btime = bt.strftime("%Y-%m-%d %H:%M:%S") - etime = et.strftime("%Y-%m-%d %H:%M:%S") - recdb.rec_reckey(typetxtnow, title, chtxt, btime, etime, opt) - sys.exit() \ No newline at end of file +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import datetime +import os +import os.path +import re +import sys +import time +import shutil +import traceback + +import auto_rec +import auto_process +import chdb +import configreader +import epgdb +import rec10d +import recdb +import status +import tv2audio +import tv2avi +import tv2mkv +import tv2mp4 +import install +import recdblist +import recque +recpath = configreader.getConfPath('recpath') +movepath = configreader.getConfPath('move_destpath') +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" +def task(): + """ + 数分毎に実行されるタスク処理 + 予定によって子プロセスを生成し処理する。 + """ + try: + if rec10d.rec10db.select_installed_in_status()==0 or rec10d.rec10db.select_version_in_status() 0: + pid = os.fork() + if pid != 0: + "" + else: + i = 0 + for bctype in update: + recnum = 0 + if bctype.find('te') > -1: + recnum = status.getTERecording() + recdb.countRecNow_minutes_TE("10") + recdblist.printutf8(u"放送種別:"+bctype + u"||該当チューナー実行中件数:" + str(status.getTERecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_TE("10")),verbose_level=800) + recnum = int(configreader.getConfEnv("te_max")) -recnum + else: + recnum = status.getBSCSRecording() + recdb.countRecNow_minutes_BSCS("10") + recdblist.printutf8(u"放送種別:"+bctype + u"||該当チューナー実行中件数:" + str(status.getBSCSRecording()) + u":直近予約件数:" + str(recdb.countRecNow_minutes_BSCS("10")),verbose_level=800) + recnum = int(configreader.getConfEnv("bscs_max")) -recnum + if recnum >0 : + recdblist.printutf8(str(update),verbose_level=750) + rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "0") + epgdb.updateForBctype(bctype) + update = chdb.update() + i = i + 1 + if i > 0: + break + time.sleep(5) + auto_process.update_all_timeline_epg() + sys.exit() + else: + pid = os.fork() + if pid != 0: + "" + else: + auto_process.update_all_timeline_epg() + sys.exit() + for task in tasks: + typetxt = task["type"] + try: + chtxt = task['chtxt'] + except: + chtxt = "" + try: + title = task['title'] + except: + title = "" + try: + btime = task['btime'] + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + except: + btime = "" + bt = datetime.datetime.strptime("2009-01-01 00:00:00", "%Y-%m-%d %H:%M:%S") + try: + etime = task['etime'] + et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + except: + etime = "" + et = datetime.datetime.strptime("2009-01-01 00:00:00", "%Y-%m-%d %H:%M:%S") + try: + opt = task['opt'] + except: + opt = "" + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + if task["type"] == recdblist.REC_RESERVE:#"res,"+chtxt+","+title+","+btime+","+etime+","+opt + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + type_reserve(task["type"],chtxt,title,bt,et,opt) + sys.exit() + elif task["type"] == recdblist.REC_KEYWORD:#"key,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt + deltatime = task['deltatime'] + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + type_keyword(task["type"],chtxt,title, bt, et, opt, deltatime) + sys.exit() + elif task["type"] == recdblist.REC_KEYWORD_EVERY_SOME_DAYS:#"keyevery,"+chtxt+","+keyword+","+btime+","+deltatime+","+opt+","+deltaday + deltatime = task['deltatime'] + deltaday = task['deltaday'] + try: + keyeverycounter=task['counter'] + except: + keyeverycounter=-1 + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + type_keyword_every_day(task["type"],chtxt, title, bt, et, opt, deltatime, deltaday,keyeverycounter) + sys.exit() + elif task["type"] == recdblist.REC_FINAL_RESERVE:#"rec,"+chtxt+","+title+","+btime+","+etime+","+opt + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + type_final(task["type"],chtxt, title, bt, et, opt) + sys.exit() + elif task["type"] == recdblist.REC_TS_DECODE_QUE: + b25num=b25num+1 + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + time.sleep(5*b25num) + type_decode_que(task["type"],chtxt, title, bt, et, opt) + sys.exit() + elif task["type"] == recdblist.REC_ENCODE_QUE: + encodenum=encodenum+1 + pid = os.fork() + if pid != 0:#親プロセスの場合 + "" + else:#子プロセスの場合 アップデートを行って終了 + time.sleep(5*encodenum) + type_encode_que(task["type"],chtxt, title, bt, et, opt) + sys.exit() + elif task["type"] == recdblist.REC_AVI_TO_MKV: + if dt < 10 * 60: + pid = os.fork() + if pid > 0:#親プロセスの場合 + "" + else: + makeMP4=0 + try: + if configreader.getConfEnv("make_mp4")==1: + makeMP4=1 + except: + "" + if re.search("m", opt): + makeMP4=0 + if re.search("4", opt): + makeMP4=1 + recdb.deleteReckey(recdblist.REC_AVI_TO_MKV, title, chtxt, btime) + recdb.reserveReckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt) + if makeMP4==1: + tv2mp4.raw2mp4(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mp4"),opt) + else: + tv2mkv.raw2mkv(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mkv"),opt) + recdb.deleteReckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime) + sys.exit() + elif task["type"] == recdblist.REC_AVI_TO_MP4: + if dt < 10 * 60: + pid = os.fork() + if pid > 0:#親プロセスの場合 + "" + else: + makeMP4=0 + try: + if configreader.getConfEnv("make_mp4")==1: + makeMP4=1 + except: + "" + if re.search("m", opt): + makeMP4=0 + if re.search("4", opt): + makeMP4=1 + recdb.deleteReckey(recdblist.REC_AVI_TO_MP4, title, chtxt, btime) + recdb.reserveReckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt) + if makeMP4==1: + tv2mp4.ts2mp4(pin, pout, opt) + tv2mp4.raw2mp4(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mp4"),opt) + else: + tv2mkv.raw2mkv(os.path.join(recpath,title+".264"),os.path.join(recpath,title+".mkv"),opt) + recdb.deleteReckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime) + sys.exit() + elif task["type"] == recdblist.REC_MKV_TO_MP4: + if dt < 10 * 60: + pid = os.fork() + if pid > 0:#親プロセスの場合 + "" + else: + recdb.deleteReckey(recdblist.REC_MKV_TO_MP4, title, chtxt, btime) + recdb.reserveReckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime, etime, opt) + tv2mp4.mkv2mp4(os.path.join(recpath,title+".mkv"),os.path.join(recpath,title+".mp4")) + recdb.deleteReckey(recdblist.REC_CHANGING_CANTAINER, title, chtxt, btime) + sys.exit() + sys.exit() +def search_keyword(key): + tnow = datetime.datetime.now() + nows =tnow.strftime("%Y-%m-%d %H:%M:%S") + for k,auto,opt in key: + recdatum = epgdb.searchTimeAuto(k,nows, "144") + for recdata in recdatum: + if recdata[1] != "": + chtxtt = recdata[0] + titlet = recdata[1] + btimet = recdata[2] + etimet = recdata[3] + btt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S") + ett = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S") + btimet = btt.strftime("%Y-%m-%d %H:%M:%S") + etimet = ett.strftime("%Y-%m-%d %H:%M:%S") + #if status.getSettings_auto_jbk()==1: + if auto==1 or status.getSettings_auto_jbk()==1: + topt=opt + if len(topt)==0: + topt=status.getSettings_auto_opt() + try: + maxnum=0 + if len(ch['ch'])>2: + maxnum=epgdb.count_schedule_timeline(btimet, etimet)[1] + maxnum=int(configreader.getConfEnv("bscs_max"))-maxnum + else: + maxnum=epgdb.count_schedule_timeline(btimet, etimet)[0] + maxnum=int(configreader.getConfEnv("te_max"))-maxnum + if maxnum>0: + if recdb.checkDuplicated(titlet, chtxtt, btimet, etimet)==0: + recdb.recreserv(titlet,chtxtt, btimet, etimet,topt) + except Exception, inst: + recdblist.addCommonlogEX("Error", "search_keyword_auto_jbk(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + else: + try: + recdb.reserveAutoKeyword(chtxtt, titlet, btimet, etimet) + except Exception, inst: + recdblist.addCommonlogEX("Error", "search_keyword(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) +def type_reserve(typetxt,chtxt,title,bt,et,opt): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + typetxtnow=typetxt + typetxtfinal="" + if typetxt==recdblist.REC_RESERVE: + typetxtfinal=recdblist.REC_FINAL_RESERVE + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + if (dt < 58 * 60 and dt > 30 * 60): + bctypet = chdb.searchCHFromChtxt(chtxt)['bctype'] + chdatat = rec10d.rec10db.select_by_bctype_epg_ch(bctypet) + dt1 = datetime.datetime.strptime(chdatat[0][4], "%Y-%m-%d %H:%M:%S")-datetime.datetime.now() + dt1 = dt1.days * 24 * 60 * 60 + dt1.seconds + if dt1 < 60 * 60: + recdata = epgdb.searchTime(title, btime, "5", chtxt) + chtxtn = recdata[0] + titlen = recdata[1] + btimen = recdata[2] + etimen = recdata[3] + exp = recdata[4] + longexp = recdata[5] + category=recdata[6] + bt = datetime.datetime.strptime(btimen, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etimen, "%Y-%m-%d %H:%M:%S") + btimen = bt.strftime("%Y-%m-%d %H:%M:%S") + etimen = et.strftime("%Y-%m-%d %H:%M:%S") + if chtxt != "": + try: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxtfinal, titlen, chtxtn, btimen, etimen, opt) + recdb.addRecLogProgram(titlen, chtxtn, btimen, etimen, opt, exp, longexp, category) + auto_rec.addKey(chtxt, titlen,exp+" "+longexp) + auto_rec.addKey("ALL", titlen,exp+" "+longexp) + recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen) + except Exception, inst: + recdblist.addCommonlogEX("Error", "Oikake DB(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + else: + recdblist.printutf8(u"追いかけ機能エラー:番組データが見付かりません。") + else: + if rec10d.rec10db.select_by_bctype_epg_ch(bctypet)[0][5] != "0": + rec10d.rec10db.update_status_by_bctype_epg_ch(bctypet, "3") + sys.exit() + elif (dt <= 30 * 60 and dt > 20 * 60): + recdata = epgdb.searchTime(title, btime, "5", chtxt) + chtxtn = recdata[0] + titlen = recdata[1] + btimen = recdata[2] + etimen = recdata[3] + exp = recdata[4] + longexp = recdata[5] + category=recdata[6] + bt = datetime.datetime.strptime(btimen, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etimen, "%Y-%m-%d %H:%M:%S") + btimen = bt.strftime("%Y-%m-%d %H:%M:%S") + etimen = et.strftime("%Y-%m-%d %H:%M:%S") + if chtxt != "": + try: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxtfinal, titlen, chtxtn, btimen, etimen, opt) + recdb.addRecLogProgram(titlen, chtxtn, btimen, etimen, opt, exp, longexp, category) + auto_rec.addKey(chtxt, titlen,exp+" "+longexp) + auto_rec.addKey("ALL", titlen,exp+" "+longexp) + #recdblist.printutf8(u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen) + recdblist.addCommonlogEX(u"通常", "Oikake (timerec.py)",u"追いかけ機能実行中",u"追いかけ機能実行中: "+title+" : "+titlen+" "+btimen+" "+etimen,log_level=500) + except Exception, inst: + recdblist.addCommonlogEX("Error", "Oikake DB(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + elif dt <= 20 * 60: + try: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxtfinal, title, chtxt, btime, etime, opt) + except Exception, inst: + recdblist.addCommonlogEX("Error", "Oikake DB(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) +def type_final(typetxt,chtxt,title,bt,et,opt): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + typetxtnow=typetxt + typetxting="" + typetxtdecque="" + if typetxt==recdblist.REC_FINAL_RESERVE: + typetxting=recdblist.REC_TS_RECORDING + typetxtdecque=recdblist.REC_TS_DECODE_QUE + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + if dt < 6 * 60 and dt > 0: + newtitle=title + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + testpath=[os.path.join(recpath,title+".ts.b25")] + testpath.append(os.path.join(recpath,title+".ts")) + testpath.append(os.path.join(recpath,title+".avi")) + testpath.append(os.path.join(recpath,title+".mp4")) + testpath.append(os.path.join(recpath,title+".log")) + tcheck=0 + for ti in testpath: + if os.path.exists(ti): + tcheck=tcheck+1 + if re.search("N", opt) or tcheck>0: + iff="" + try: + iff=u"("+configreader.getConfEnv("iff")+u")_" + except: + iff="" + newtime=bt + newtitle=newtitle+u"_"+iff+newtime.strftime("%Y-%m-%dT%H-%M-%S") + recdb.reserveReckey(typetxting, newtitle, chtxt, btime, etime, opt) + recdblist.addCommonlogEX(u"通常","timerec.py",u"録画開始 "+newtitle+" "+btime+" "+etime,"",log_level=500) + tv2avi.timetv2b25(recpath + "/" + newtitle + ".avi", chtxt, btime, etime, opt) + recdb.deleteReckey(typetxting, newtitle, chtxt, btime) + if not re.search("R", opt): + tnow = datetime.datetime.now() + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + dt = tnow-bt + bt = tnow + datetime.timedelta(seconds=600) + et = et + dt + datetime.timedelta(seconds=600) + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.reserveReckey(typetxtdecque, newtitle, chtxt, btime, etime, opt) + else: + try: + try: + shutil.copy(os.path.join(recpath,title+".ts.b25"), os.path.join(movepath,title+".ts.b25")) + except: + "" + try: + os.chmod(os.path.join(movepath,title+".ts.b25"),0777) + except: + "" + recque.writeRecQue(movepath, chtxt, title, opt) + try: + os.chmod(os.path.join(movepath,title+".recq"),0777) + except: + "" + except Exception, inst: + recdblist.addCommonlogEX("Error", "Move option(timerec.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + recdb.reserveReckey(recdblist.REC_MOVE_END, newtitle, chtxt, btime, etime, opt) + sys.exit() +def type_keyword(typetxt,chtxt,title,bt,et,opt,deltatime): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + typetxtnow=typetxt + typetxtres="" + if typetxt==recdblist.REC_KEYWORD: + typetxtres=recdblist.REC_RESERVE + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + recdblist.printutf8(str(dt), verbose_level=800) + if dt < 90 * 60: + recdata = epgdb.searchTime(title, btime, deltatime, chtxt) + if recdata[1] != "": + chtxtt = recdata[0] + titlet = recdata[1] + btimet = recdata[2] + etimet = recdata[3] + exp = recdata[4] + longexp = recdata[5] + category=recdata[6] + bt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S") + btimet = bt.strftime("%Y-%m-%d %H:%M:%S") + etimet = et.strftime("%Y-%m-%d %H:%M:%S") + #try: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxtres, titlet, chtxt, btimet, etimet, opt) + recdb.addRecLogProgram(titlet, chtxtt, btimet, etimet, opt, exp,longexp,category) + auto_rec.addKey(chtxt, titlet,exp+" "+longexp) + auto_rec.addKey("ALL", titlet,exp+" "+longexp) + recdblist.addCommonlogEX(u"通常","timerec.py",u"key "+title+u" : "+titlet+u" "+btimet+u" "+etimet,"",log_level=500) + #except Exception, inst: + # recdblist.printutf8("Error happened in REC_KEYWORD DB") + # recdblist.printutf8(type(inst)) + # recdblist.printutf8(inst) + else: + recdblist.printutf8("nothing match") +def type_keyword_every_day(type,chtxt,title,bt,et,opt,deltatime,deltaday,counter): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + dd = datetime.timedelta(days=int(deltaday)) + if dtt.days < 0: + recdb.deleteReckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime) + 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.reserveEverydayKeyword(title, chtxt, btxt, etxt, deltatime, opt, deltaday) + elif dt < 120 * 60: + recdb.deleteReckey(recdblist.REC_KEYWORD_EVERY_SOME_DAYS, title, chtxt, btime) + bt = bt + dd + et = et + dd + btxt = bt.strftime("%Y-%m-%d %H:%M:%S") + etxt = et.strftime("%Y-%m-%d %H:%M:%S") + if counter>0: + recdb.reserveEverydayKeyword(title, chtxt, btxt, etxt, deltatime, opt, deltaday,counter-1) + elif counter==-1: + recdb.reserveEverydayKeyword(title, chtxt, btxt, etxt, deltatime, opt, deltaday,-1) + recdata = epgdb.searchTime(title, btime, deltatime, chtxt) + if recdata[1] != "": + chtxtt = recdata[0] + titlet = recdata[1] + btimet = recdata[2] + etimet = recdata[3] + exp = recdata[4] + longexp = recdata[5] + category=recdata[6] + bt = datetime.datetime.strptime(btimet, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etimet, "%Y-%m-%d %H:%M:%S") + btimet = bt.strftime("%Y-%m-%d %H:%M:%S") + etimet = et.strftime("%Y-%m-%d %H:%M:%S") + #try: + recdb.reserveKeyword(titlet, chtxt, btimet, etimet, deltatime, opt) + else: + recdb.reserveKeyword(title, chtxt, btime, etime, deltatime, opt) +def type_decode_que(typetxt,chtxt,title,bt,et,opt): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + typetxtnow=typetxt + typetxting="" + typetxtmiss="" + typetxtencque="" + if typetxt== recdblist.REC_TS_DECODE_QUE: + typetxting=recdblist.REC_TS_DECODING + typetxtmiss=recdblist.REC_MISS_DECODE + typetxtencque=recdblist.REC_ENCODE_QUE + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + if dt < 10 * 60: + if status.getB25Decoding() < 2: + pin = recpath + "/" + title + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxting, title, chtxt, btime, etime, opt) + tv2avi.b252ts(pin, chtxt, btime, etime, opt) + recdb.deleteReckey(typetxting, title, chtxt, btime) + if not os.access(recpath + "/" + title + ".ts", os.F_OK): + recdb.deleteReckey(typetxting, title, chtxt, btime) + recdb.reserveReckey(typetxtmiss, title, chtxt, btime, etime, opt) + else: + auto_process.deleteTmpFile(recpath, title, ".ts") + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + dt = et-bt + if not re.search("D", opt): + tnow = datetime.datetime.now() + bt = tnow + datetime.timedelta(seconds=600) + et = bt + dt + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.reserveReckey(typetxtencque, title, chtxt, btime, etime, opt) + else: + try: + try: + shutil.copy(os.path.join(recpath,title+".ts"), os.path.join(movepath,title+".ts")) + except: + "" + try: + os.chmod(os.path.join(movepath,title+".ts"),0777) + except: + "" + recque.writeRecQue(movepath, chtxt, title, opt) + try: + os.chmod(os.path.join(movepath,title+".recq"),0777) + except: + "" + time.sleep(5) + if os.path.getsize(os.path.join(recpath,title+".ts"))==os.path.getsize(os.path.join(movepath,title+".ts")): + os.remove(os.path.join(recpath,title+".ts")) + except Exception, inst: + errtxt1="move ts error.\n" + errtxt2=str(type(inst))+"\n" + errtxt2=errtxt2+str(inst) + recdblist.addCommonlogEX("Error", "type_decode_que(timerec.py)", errtxt1,errtxt2+traceback.format_exc(),log_level=200) + recdb.reserveReckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt) + else: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + bt = bt + datetime.timedelta(seconds=600) + et = et + datetime.timedelta(seconds=600) + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.reserveReckey(typetxtnow, title, chtxt, btime, etime, opt) + sys.exit() + +def type_encode_que(typetxt,chtxt,title,bt,et,opt): + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + tnow = datetime.datetime.now() + dtt = bt-tnow + dt = dtt.days * 24 * 60 * 60 + dtt.seconds + typetxtnow=typetxt + typetxting="" + typetxtfin="" + if typetxt==recdblist.REC_ENCODE_QUE: + typetxting=recdblist.REC_ENCODE_LOCAL + typetxtfin=recdblist.REC_FIN_LOCAL + if dt < 10 * 60: + if status.getEncoding() < int(configreader.getConfEnv("enc_max")): + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + recdb.reserveReckey(typetxting, title, chtxt, btime, etime, opt) + recdblist.printutf8(opt) + pin = recpath + "/" + title + ".ts" + if re.search("d", opt): + pin = recpath + "/" + title + ".m2v" + if not os.path.exists(pin) or os.path.getsize(pin)<100*1000: + paac2 = recpath + "/" + title + "_2.aac" + pmp32 = recpath + "/" + title + "_2.mp3" + if not os.path.exists(paac2) and not os.path.exists(pmp32): + tv2audio.ts2dualaudio_BonTsDemux(os.path.join(recpath, title+".ts"),recdblist.BONTSDEMUX_DELAY,opt) + time.sleep(3) + elif re.search("5", opt): + pin = recpath + "/" + title + ".m2v" + if not os.path.exists(pin) or os.path.getsize(pin)<100*1000: + paac2 = recpath + "/" + title + "_2.aac" + pmp32 = recpath + "/" + title + "_2.mp3" + if not os.path.exists(paac2) and not os.path.exists(pmp32): + tv2audio.ts2pentaaudio_BonTsDemux(os.path.join(recpath, title+".ts"), recdblist.BONTSDEMUX_DELAY, opt) + time.sleep(3) + makeMP4=0 + try: + if configreader.getConfEnv("make_mp4")=="1": + makeMP4=1 + except: + "" + if re.search("m", opt): + makeMP4=0 + if re.search("4", opt): + makeMP4=1 + recdblist.printutf8(pin) + if not re.search("0", opt): + if makeMP4==1: + pout = recpath + "/" + title + ".mp4" + tv2mp4.ts2mp4(pin, pout, opt) + else: + pout = recpath + "/" + title + ".mkv" + tv2mkv.ts2mkv(pin, pout, opt) + if re.search("8", opt) or re.search("9", opt): + optt=opt + poutt = recpath + "/" + "m_"+title + ".mp4" + if re.search("d", opt) or re.search("5", opt): + if os.path.exists(os.path.join(recpath, "m_"+title+".m2v")): + shutil.move(os.path.join(recpath, title+".m2v"),os.path.join(recpath, "m_"+title+".m2v")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_1.aac")): + shutil.move(os.path.join(recpath, title+"_1.aac"),os.path.join(recpath, "m_"+title+"_1.aac")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_1.mp3")): + shutil.move(os.path.join(recpath, title+"_1.mp3"),os.path.join(recpath, "m_"+title+"_1.mp3")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_2.aac")): + shutil.move(os.path.join(recpath, title+"_2.aac"),os.path.join(recpath, "m_"+title+"_2.aac")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_2.mp3")): + shutil.move(os.path.join(recpath, title+"_2.mp3"),os.path.join(recpath, "m_"+title+"_2.mp3")) + shutil.move(os.path.join(recpath, title+".ts"),os.path.join(recpath, "m_"+title+".ts")) + tv2mp4.ts2mp4(os.path.join(recpath, "m_"+title+".ts"), poutt, optt) + shutil.move(os.path.join(recpath, "m_"+title+".ts"),os.path.join(recpath, title+".ts")) + else: + optt=opt + poutt = recpath + "/" + "m_"+title + ".mp4" + shutil.move(os.path.join(recpath, title+".ts"),os.path.join(recpath, "m_"+title+".ts")) + if re.search("d", opt) or re.search("5", opt): + if os.path.exists(os.path.join(recpath, "m_"+title+".m2v")): + shutil.move(os.path.join(recpath, title+".m2v"),os.path.join(recpath, "m_"+title+".m2v")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_1.aac")): + shutil.move(os.path.join(recpath, title+"_1.aac"),os.path.join(recpath, "m_"+title+"_1.aac")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_1.mp3")): + shutil.move(os.path.join(recpath, title+"_1.mp3"),os.path.join(recpath, "m_"+title+"_1.mp3")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_2.aac")): + shutil.move(os.path.join(recpath, title+"_2.aac"),os.path.join(recpath, "m_"+title+"_2.aac")) + if os.path.exists(os.path.join(recpath, "m_"+title+"_2.mp3")): + shutil.move(os.path.join(recpath, title+"_2.mp3"),os.path.join(recpath, "m_"+title+"_2.mp3")) + tv2mp4.ts2mp4(os.path.join(recpath, "m_"+title+".ts"), poutt, optt) + shutil.move(os.path.join(recpath, "m_"+title+".ts"),os.path.join(recpath, title+".ts")) + recdb.deleteReckey(typetxting, title, chtxt, btime) + time.sleep(10) + if re.search("E", opt): + try: + if os.path.exists(os.path.join(recpath,title+".mp4")): + try: + shutil.copy(os.path.join(recpath,title+".mp4"), os.path.join(movepath,title+".mp4")) + except: + "" + try: + os.chmod(os.path.join(movepath,title+".mp4"),0777) + except: + "" + recque.writeRecQue(movepath, chtxt, title, opt) + try: + os.chmod(os.path.join(movepath,title+".recq"),0777) + except: + "" + elif os.path.exists(os.path.join(recpath,title+".mkv")): + try: + shutil.copy(os.path.join(recpath,title+".mkv"), os.path.join(movepath,title+".mkv")) + except: + "" + try: + os.chmod(os.path.join(movepath,title+".mkv"),0777) + except: + "" + recque.writeRecQue(movepath, chtxt, title, opt) + try: + os.chmod(os.path.join(movepath,title+".recq"),0777) + except: + "" + except Exception, inst: + errtxt1="move mkv/mp4 error." + errtxt2=str(type(inst))+"\n" + errtxt2=errtxt2+str(inst) + recdblist.addCommonlogEX("Error", "type_encode_que(timerec.py)", errtxt1,errtxt2+traceback.format_exc(),log_level=200) + recdb.reserveReckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt) + recdb.reserveReckey(typetxtfin, title, chtxt, btime, etime, opt) + sys.exit() + else: + recdb.deleteReckey(typetxtnow, title, chtxt, btime) + bt = bt + datetime.timedelta(seconds=600) + et = et + datetime.timedelta(seconds=600) + btime = bt.strftime("%Y-%m-%d %H:%M:%S") + etime = et.strftime("%Y-%m-%d %H:%M:%S") + recdb.reserveReckey(typetxtnow, title, chtxt, btime, etime, opt) + sys.exit() diff --git a/rec10/trunk/src/ts2epg.py b/rec10/trunk/src/ts2epg.py index cdf65ff..a867290 100644 --- a/rec10/trunk/src/ts2epg.py +++ b/rec10/trunk/src/ts2epg.py @@ -1,47 +1,47 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -#import sys # モジュール属性 argv を取得するため -import os -import re -import time - -import chdb -import configreader -import tv2ts -import recdblist - -def write(pout, ch): - """ - tsを取得してepgの入ったxmlとして書き出す - """ - timet = "90" - if re.search(u'CS', ch): - timet = "180" - elif len(ch)>2: - timet = "240" - writeTime(pout, ch ,timet) -def writeTime(pout, ch ,times): - """ - 指定された時間分tsを取得してepgの入ったxmlとして書き出す - """ - recdblist.addCommonlogEX(u"通常","write_time(ts2epg.py)",u"Ts-EPG XML書き出し処理開始" ,u"CH:"+ch,log_level=500) - timet = times - if re.search(u'CS', ch): - mode = "/CS" - elif len(ch)>2: - mode = "/BS" - else: - mode = str(chdb.searchFromBctype(u'te' + ch)['ch']) - epgdump=configreader.getPathSetting("epgdump") - if os.access(pout + ".ts", os.F_OK): - os.remove(pout + ".ts") - time.sleep(10) - tv2ts.tv2tsmix(pout + ".ts", ch, timet) - exe = "export LANG=ja_JP.UTF-8 && nice -n 15 " + epgdump + " " + mode + " " + pout + ".ts " + pout - recdblist.printutf8(exe) - recdblist.addCommonlogEX(u"通常", "write_time(ts2epg.py)", exe,"",log_level=500) - os.system(exe) - time.sleep(10) - +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +#import sys # モジュール属性 argv を取得するため +import os +import re +import time + +import chdb +import configreader +import tv2ts +import recdblist + +def writeEpgXML(pout, ch): + """ + tsを取得してepgの入ったxmlとして書き出す + """ + timet = "90" + if re.search(u'CS', ch): + timet = "180" + elif len(ch)>2: + timet = "240" + writeEpgXMLTime(pout, ch ,timet) +def writeEpgXMLTime(pout, ch ,times): + """ + 指定された時間分tsを取得してepgの入ったxmlとして書き出す + """ + recdblist.addCommonlogEX(u"通常","write_time(ts2epg.py)",u"Ts-EPG XML書き出し処理開始" ,u"CH:"+ch,log_level=500) + timet = times + if re.search(u'CS', ch): + mode = "/CS" + elif len(ch)>2: + mode = "/BS" + else: + mode = str(chdb.bctypesearch(u'te' + ch)['ch']) + epgdump = configreader.getConfPath("epgdump") + if os.access(pout + ".ts", os.F_OK): + os.remove(pout + ".ts") + time.sleep(10) + tv2ts.tv2tsmix(pout + ".ts", ch, timet) + exe = "export LANG=ja_JP.UTF-8 && nice -n 15 " + epgdump + " " + mode + " " + pout + ".ts " + pout + recdblist.printutf8(exe) + recdblist.addCommonlogEX(u"通常", "write_time(ts2epg.py)", exe,"",log_level=500) + os.system(exe) + time.sleep(10) + diff --git a/rec10/trunk/src/ts2x264.py b/rec10/trunk/src/ts2x264.py index aebf113..c331210 100644 --- a/rec10/trunk/src/ts2x264.py +++ b/rec10/trunk/src/ts2x264.py @@ -1,478 +1,478 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import commands -import configreader -import os -import os.path -import re -import random -import time -import traceback - -import recdblist -def ts2x264(pin, pout, opts):#sizeは"HD"か"SD" - """ - pinで指定されたファイルをpoutにx264でエンコードして書き出す - """ - dualpass = 0 - is24fps=0 - size="HD" - crf=18 - quality=4 - quality=int(configreader.getEnvSetting("x264_preset")) - crf=int(configreader.getEnvSetting("crf")) - deinterlace=1 - if re.search("H", opts): - size = "HD" - if re.search("S", opts): - size = "WVGA" - if re.search("F", opts): - size = "FullHD" - if re.search("W",opts): - size = "WVGA" - if re.search("1",opts): - size = "QVGA_BASE" - crf=crf+4 - if re.search("2", opts): - size = "WVGA_BASE" - crf=crf+2 - if re.search("v", opts): - is24fps=1 - crf=int(configreader.getEnvSetting("animation_crf")) - if re.search("a", opts): - is24fps=1 - crf=int(configreader.getEnvSetting("animation_crf")) - if re.search("I", opts): - deinterlace=0 - if re.search("q",opts): - quality=quality-2 - if re.search("w",opts): - quality=quality-1 - if re.search("e",opts): - quality=quality+1 - if re.search("r",opts): - quality=quality+2 - if re.search("u",opts): - crf=crf+2 - if re.search("i",opts): - crf=crf+1 - if re.search("o",opts): - crf=crf-1 - if re.search("p",opts): - crf=crf-2 - if re.search("d",opts):#二カ国語放送の場合 - tm2v=pin.replace(".ts",".m2v") - encodeFFmpegSar(tm2v,pout,size,is24fps,quality,crf,deinterlace) - elif re.search("5",opts):#5.1chの場合 - encodeFFmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace) - else: - try: - encodeSar(pin, pout,size,is24fps,quality,crf,deinterlace) - except Exception, inst: - recdblist.addCommonlogEX("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) -def encodeSar(pin,pout,size,is24fps,quality,crf,deinterlace=1): - mencoder=configreader.getPathSetting("mencoder") - egetPath - txt="" - encvf="-sws 9 -vf yadif=0,pp=l5" - harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup" - ofps="-ofps 30000/1001" - fps="-fps 30000/1001" - x264fps="30000/1001" - x264streamsize="" - x264preset="" - x264tune="" - x264_bitrate="5000" - tsar=getMoviePAR2(pin) - x264sar=str(tsar[0])+":"+str(tsar[1]) - if is24fps==1: - ofps="-ofps 24000/1001" - fps="-fps 30000/1001" - x264fps="24000/1001" - x264tune="--tune animation" - encvf="-sws 9 -vf pullup,softskip" - harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup" - if size == "HD": - tsize=getParSize(pin,720) - encvf = encvf + ",scale=-3:720::0:3"+harddup - x264streamsize=str(tsize[0])+u"x720" - x264_bitrate="2500" - elif size == "WVGA": - tsize=getParSize(pin,480) - encvf = encvf + ",scale=-3:480::0:3"+harddup - x264streamsize=str(tsize[0])+u"x480" - x264_bitrate="1500" - elif size == "FullHD": - tsize=getParSize(pin,1080) - encvf = encvf + ",scale=-3:1080::0:3"+harddup - x264streamsize=str(tsize[0])+u"x1080" - x264_bitrate="5000" - elif size == "QVGA_BASE": - tsize=getParSize(pin,240) - encvf = encvf + ",scale=-3:240::0:3"+harddup - x264streamsize=str(tsize[0])+u"x240" - x264_bitrate="300" - elif size == "WVGA_BASE": - tsize=getParSize(pin,480) - encvf = encvf + ",scale=-3:480::0:3"+harddup - x264streamsize=str(tsize[0])+u"x480" - x264_bitrate="1500" - else: - tsize=getParSize(pin,720) - encvf = encvf + ",scale=-3:720::0:3"+harddup - x264streamsize=str(tsize[0])+u"x720" - x264_bitrate="2500" - if deinterlace==0: - tsize=getMovieBaseSize2(pin) - ofps="-ofps 30000/1001" - #fps="-fps 30000/1001" - fps="" - x264fps="30000/1001" - x264tune=x264tune+" --tff --nal-hrd vbr" - encvf="-vf hqdn3d=2:1:2" - harddup=",harddup" - encvf=encvf+harddup - x264streamsize=str(tsize[0])+u"x"+str(tsize[1]) - if tsize[0] <= 0 or tsize[1] <= 0: - encvf="-sws 9 -vf yadif=0,pp=l5" - harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup" - ofps="-ofps 30000/1001" - fps="-fps 30000/1001" - x264fps="30000/1001" - tsize=[1280,720] - encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup - x264streamsize=u"1280x720" - x264_bitrate="2500" - if quality==1: - x264preset=u"ultrafast" - elif quality==2: - x264preset=u"veryfast" - elif quality==3: - x264preset=u"fast" - elif quality==4: - x264preset=u"medium" - elif quality==5: - x264preset=u"slow" - elif quality==6: - x264preset=u"slower" - if size == "WVGA_BASE" or size == "QVGA_BASE": - x264profile=" --level 32 --profile baseline " - else: - x264profile=" --level 41 --profile high " - x264crf=str(crf) - os.environ['LANG']="ja_JP.UTF-8" - random.seed(pin) - random.jumpahead(10) - temptime=int(time.time()) - temptime=temptime % 9697 - random.jumpahead(temptime) - streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 99999999))) - os.system(u"mkfifo "+streampath) - encexe=mencoder+u" \""+pin+u"\" -vfm ffmpeg -quiet "+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" & " - encexe=encexe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout, streampath, x264streamsize, crf=x264crf) - #encexe=encexe+u" nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+streampath+" "+x264streamsize - encexe=u"nice -n 19 " +encexe - recdblist.printutf8(encexe) - txt="" - try: - txt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8','ignore') - except: - "" - os.system("rm "+streampath) - recdblist.addCommandLog(pin, u"Mencoder", encexe, txt) -def encodeFFmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=1): - """ - - """ - ffmpeg=configreader.getPathSetting("ffmpeg") - fps=u"-r 29.970030 " - x264fps="30000/1001" - x264streamsize="" - x264preset="" - x264tune="" - x264_bitrate="2500" - x264_thread="auto" - tsar=getMoviePAR2(pin) - filter="-deinterlace" - x264sar=str(tsar[0])+":"+str(tsar[1]) - if size == "HD": - tsize=getParSize(pin,720) - s = "-s "+str(tsize[0])+"x720 " - x264streamsize=str(tsize[0])+u"x720" - x264_bitrate="2500" - elif size == "WVGA": - tsize=getParSize(pin,480) - s = "-s "+str(tsize[0])+"x480 " - x264streamsize=str(tsize[0])+u"x480" - x264_bitrate="1500" - elif size == "FullHD": - tsize=getParSize(pin,1080) - s = "-s "+str(tsize[0])+"x1080 " - x264streamsize=str(tsize[0])+u"x1080" - x264_bitrate="5000" - elif size == "SD": - tsize=getParSize(pin,480) - s = "-s "+str(tsize[0])+"x480 " - x264streamsize=str(tsize[0])+u"x480" - x264_bitrate="1250" - elif size == "QVGA_BASE": - tsize=getParSize(pin,240) - s = "-s "+str(tsize[0])+"x240 " - x264streamsize=str(tsize[0])+u"x240" - x264_bitrate="300" - elif size == "WVGA_BASE": - tsize=getParSize(pin,480) - s = "-s "+str(tsize[0])+"x480 " - x264streamsize=str(tsize[0])+u"x480" - x264_bitrate="1500" - else: - tsize=getParSize(pin,720) - s = "-s "+str(tsize[0])+"x720 " - x264streamsize=str(tsize[0])+u"x720" - x264_bitrate="2500" - if deinterlace==0: - tsize=getMovieBaseSize2(pin) - fps="" - s = "-s "+str(tsize[0])+"x"+str(tsize[1])+" " - x264fps="30000/1001" - x264tune=x264tune+" --tff --nal-hrd vbr" - filter="" - x264streamsize=str(tsize[0])+u"x"+str(tsize[1]) - if quality==1: - x264preset=u"ultrafast" - elif quality==2: - x264preset=u"veryfast" - elif quality==3: - x264preset=u"fast" - elif quality==4: - x264preset=u"medium" - elif quality==5: - x264preset=u"slow" - elif quality==6: - x264preset=u"slower" - if size == "WVGA_BASE" or size == "QVGA_BASE": - x264profile=" --level 32 --profile baseline " - else: - x264profile=" --level 41 --profile high " - x264crf=str(crf) - txt="" - os.environ['LANG']="ja_JP.UTF-8" - exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -pix_fmt yuv420p "+s+fps+" "+filter+" -an -f rawvideo - | " - exe=exe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout,"-", x264streamsize, crf=x264crf) - exe = "nice -n 19 " + exe - txt="" - recdblist.printutf8(exe) - try: - txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') - except: - "" - recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt) -def getMovieBaseSize(pin): - ffmpeg=configreader.getPathSetting("ffmpeg") - os.environ['LANG']="ja_JP.UTF-8" - exe=ffmpeg+u" -i \""+pin+"\" 2>&1" - txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') - rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z") - sizeMaxX=0 - sizeMaxY=0 - txtls=txts.split("\n") - for t in txtls: - rM=rT.match(t) - if rM: - sizetxt=rM.group(1) - partxt=rM.group(2) - tX=int(sizetxt.split("x")[0]) - tY=int(sizetxt.split("x")[1]) - tEX=int(partxt.split(":")[0]) - tEY=int(partxt.split(":")[1]) - if sizeMaxX&1" - txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') - rT=re.compile(u"Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z") - sizeMaxX=0 - sizeMaxY=0 - txtls=txts.split("\n") - for t in txtls: - rM=rT.search(t) - if rM: - sizetxt=rM.group(1) - partxt=rM.group(2) - tX=int(sizetxt.split("x")[0]) - tY=int(sizetxt.split("x")[1]) - tEX=int(partxt.split(":")[0]) - tEY=int(partxt.split(":")[1]) - if sizeMaxX&1" - txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') - rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z") - sizeMaxX=0 - parx=0 - pary=0 - txtls=txts.split("\n") - for t in txtls: - rM=rT.match(t) - if rM: - sizetxt=rM.group(1) - dartxt=rM.group(2) - tX=int(sizetxt.split("x")[0]) - tY=int(sizetxt.split("x")[1]) - tEX=int(dartxt.split(":")[0]) - tEY=int(dartxt.split(":")[1]) - if sizeMaxX&1" - txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') - rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z") - sizeMaxX=0 - parx=0 - pary=0 - txtls=txts.split("\n") - for t in txtls: - rM=rT.match(t) - if rM: - sizetxt=rM.group(1) - dartxt=rM.group(2) - tX=int(sizetxt.split("x")[0]) - tY=int(sizetxt.split("x")[1]) - tEX=int(dartxt.split(":")[0]) - tEY=int(dartxt.split(":")[1]) - if sizeMaxX&1" - txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') - rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z") - sizeMaxX=0 - darx=0 - dary=0 - txtls=txts.split("\n") - for t in txtls: - rM=rT.match(t) - if rM: - sizetxt=rM.group(1) - dartxt=rM.group(2) - tX=int(sizetxt.split("x")[0]) - tY=int(sizetxt.split("x")[1]) - tEX=int(dartxt.split(":")[0]) - tEY=int(dartxt.split(":")[1]) - if sizeMaxX&1" - txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') - rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z") - sizeMaxX=0 - darx=0 - dary=0 - txtls=txts.split("\n") - for t in txtls: - rM=rT.match(t) - if rM: - sizetxt=rM.group(1) - dartxt=rM.group(2) - tX=int(sizetxt.split("x")[0]) - tY=int(sizetxt.split("x")[1]) - tEX=int(dartxt.split(":")[0]) - tEY=int(dartxt.split(":")[1]) - if sizeMaxXint(tX/10)*10: - tX=tX/10+1 - else: - tX=tX/10 - else: - tX=-1 - tY=-1 - return [tX,tY] -def getX264CoreVersion(): - x264=configreader.getPathSetting("x264") - t1=commands.getoutput(x264+" --help|grep core") - rT=re.compile(u"x264 core:(\d*)[\d]*.*\Z") - rM=rT.match(t1) - v=-1 - if rM: - v=int(rM.group(1)) - return v -def getX264Commandline(preset,sar,fps,x264profile,x264tune,pout,pin,x264streamsize,crf=-1,bitrate=0): - x264=configreader.getPathSetting("x264") - os.environ['LANG']="ja_JP.UTF-8" - x264_sar="--sar "+sar - x264preset=u"--preset "+preset - x264fps="--fps "+fps - if crf==-1: - x264bitrate=u"--bitrate "+str(bitrate) - else: - x264crf=u"--crf "+str(crf) - x264_addline=configreader.getEnvSetting("x264_addline") - x264_thread="auto" - try: - xtt=configreader.getEnvSetting("x264_thread") - xtt=int(xtt) - if xtt>0: - x264_thread=str(xtt) - except: - x264_thread="auto" - x264_addline=configreader.getEnvSetting("x264_addline") - if getX264CoreVersion()>103: - x264res=u"--input-res "+x264streamsize - exe=u"nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" "+x264res+" -o \""+pout+"\" "+pin - else: - exe=u"nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+pin+" "+x264streamsize - return exe \ No newline at end of file +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import commands +import configreader +import os +import os.path +import re +import random +import time +import traceback + +import recdblist +def ts2x264(pin, pout, opts):#sizeは"HD"か"SD" + """ + pinで指定されたファイルをpoutにx264でエンコードして書き出す + """ + dualpass = 0 + is24fps=0 + size="HD" + crf=18 + quality=4 + quality=int(configreader.getConfEnv("x264_preset")) + crf=int(configreader.getConfEnv("crf")) + deinterlace=1 + if re.search("H", opts): + size = "HD" + if re.search("S", opts): + size = "WVGA" + if re.search("F", opts): + size = "FullHD" + if re.search("W",opts): + size = "WVGA" + if re.search("1",opts): + size = "QVGA_BASE" + crf=crf+4 + if re.search("2", opts): + size = "WVGA_BASE" + crf=crf+2 + if re.search("v", opts): + is24fps=1 + crf=int(configreader.getConfEnv("animation_crf")) + if re.search("a", opts): + is24fps=1 + crf=int(configreader.getConfEnv("animation_crf")) + if re.search("I", opts): + deinterlace=0 + if re.search("q",opts): + quality=quality-2 + if re.search("w",opts): + quality=quality-1 + if re.search("e",opts): + quality=quality+1 + if re.search("r",opts): + quality=quality+2 + if re.search("u",opts): + crf=crf+2 + if re.search("i",opts): + crf=crf+1 + if re.search("o",opts): + crf=crf-1 + if re.search("p",opts): + crf=crf-2 + if re.search("d",opts):#二カ国語放送の場合 + tm2v=pin.replace(".ts",".m2v") + encodeFfmpegSar(tm2v,pout,size,is24fps,quality,crf,deinterlace) + elif re.search("5",opts):#5.1chの場合 + encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace) + else: + try: + encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace) + except Exception, inst: + recdblist.Commonlogex("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) +def encodeMencoderSar(pin,pout,size,is24fps,quality,crf,deinterlace=1): + mencoder=configreader.getpath("mencoder") + encvf="" + txt="" + encvf="-sws 9 -vf yadif=0,pp=l5" + harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup" + ofps="-ofps 30000/1001" + fps="-fps 30000/1001" + x264fps="30000/1001" + x264streamsize="" + x264preset="" + x264tune="" + x264_bitrate="5000" + tsar=getMoviePAR2(pin) + x264sar=str(tsar[0])+":"+str(tsar[1]) + if is24fps==1: + ofps="-ofps 24000/1001" + fps="-fps 30000/1001" + x264fps="24000/1001" + x264tune="--tune animation" + encvf="-sws 9 -vf pullup,softskip" + harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup" + if size == "HD": + tsize=getParSize(pin,720) + encvf = encvf + ",scale=-3:720::0:3"+harddup + x264streamsize=str(tsize[0])+u"x720" + x264_bitrate="2500" + elif size == "WVGA": + tsize=getParSize(pin,480) + encvf = encvf + ",scale=-3:480::0:3"+harddup + x264streamsize=str(tsize[0])+u"x480" + x264_bitrate="1500" + elif size == "FullHD": + tsize=getParSize(pin,1080) + encvf = encvf + ",scale=-3:1080::0:3"+harddup + x264streamsize=str(tsize[0])+u"x1080" + x264_bitrate="5000" + elif size == "QVGA_BASE": + tsize=getParSize(pin,240) + encvf = encvf + ",scale=-3:240::0:3"+harddup + x264streamsize=str(tsize[0])+u"x240" + x264_bitrate="300" + elif size == "WVGA_BASE": + tsize=getParSize(pin,480) + encvf = encvf + ",scale=-3:480::0:3"+harddup + x264streamsize=str(tsize[0])+u"x480" + x264_bitrate="1500" + else: + tsize=getParSize(pin,720) + encvf = encvf + ",scale=-3:720::0:3"+harddup + x264streamsize=str(tsize[0])+u"x720" + x264_bitrate="2500" + if deinterlace==0: + tsize=getMovieBaseSize2(pin) + ofps="-ofps 30000/1001" + #fps="-fps 30000/1001" + fps="" + x264fps="30000/1001" + x264tune=x264tune+" --tff --nal-hrd vbr" + encvf="-vf hqdn3d=2:1:2" + harddup=",harddup" + encvf=encvf+harddup + x264streamsize=str(tsize[0])+u"x"+str(tsize[1]) + if tsize[0] <= 0 or tsize[1] <= 0: + encvf="-sws 9 -vf yadif=0,pp=l5" + harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup" + ofps="-ofps 30000/1001" + fps="-fps 30000/1001" + x264fps="30000/1001" + tsize=[1280,720] + encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup + x264streamsize=u"1280x720" + x264_bitrate="2500" + if quality==1: + x264preset=u"ultrafast" + elif quality==2: + x264preset=u"veryfast" + elif quality==3: + x264preset=u"fast" + elif quality==4: + x264preset=u"medium" + elif quality==5: + x264preset=u"slow" + elif quality==6: + x264preset=u"slower" + if size == "WVGA_BASE" or size == "QVGA_BASE": + x264profile=" --level 32 --profile baseline " + else: + x264profile=" --level 41 --profile high " + x264crf=str(crf) + os.environ['LANG']="ja_JP.UTF-8" + random.seed(pin) + random.jumpahead(10) + temptime=int(time.time()) + temptime=temptime % 9697 + random.jumpahead(temptime) + streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 99999999))) + os.system(u"mkfifo "+streampath) + encexe=mencoder+u" \""+pin+u"\" -vfm ffmpeg -quiet "+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" & " + encexe=encexe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout, streampath, x264streamsize, crf=x264crf) + #encexe=encexe+u" nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+streampath+" "+x264streamsize + encexe=u"nice -n 19 " +encexe + recdblist.printutf8(encexe) + txt="" + try: + txt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8','ignore') + except: + "" + os.system("rm "+streampath) + recdblist.addCommandLog(pin, u"Mencoder", encexe, txt) +def encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=1): + """ + + """ + ffmpeg=configreader.getPathSetting("ffmpeg") + fps=u"-r 29.970030 " + x264fps="30000/1001" + x264streamsize="" + x264preset="" + x264tune="" + x264_bitrate="2500" + x264_thread="auto" + tsar=getMoviePAR2(pin) + filter="-deinterlace" + x264sar=str(tsar[0])+":"+str(tsar[1]) + if size == "HD": + tsize=getParSize(pin,720) + s = "-s "+str(tsize[0])+"x720 " + x264streamsize=str(tsize[0])+u"x720" + x264_bitrate="2500" + elif size == "WVGA": + tsize=getParSize(pin,480) + s = "-s "+str(tsize[0])+"x480 " + x264streamsize=str(tsize[0])+u"x480" + x264_bitrate="1500" + elif size == "FullHD": + tsize=getParSize(pin,1080) + s = "-s "+str(tsize[0])+"x1080 " + x264streamsize=str(tsize[0])+u"x1080" + x264_bitrate="5000" + elif size == "SD": + tsize=getParSize(pin,480) + s = "-s "+str(tsize[0])+"x480 " + x264streamsize=str(tsize[0])+u"x480" + x264_bitrate="1250" + elif size == "QVGA_BASE": + tsize=getParSize(pin,240) + s = "-s "+str(tsize[0])+"x240 " + x264streamsize=str(tsize[0])+u"x240" + x264_bitrate="300" + elif size == "WVGA_BASE": + tsize=getParSize(pin,480) + s = "-s "+str(tsize[0])+"x480 " + x264streamsize=str(tsize[0])+u"x480" + x264_bitrate="1500" + else: + tsize=getParSize(pin,720) + s = "-s "+str(tsize[0])+"x720 " + x264streamsize=str(tsize[0])+u"x720" + x264_bitrate="2500" + if deinterlace==0: + tsize=getMovieBaseSize2(pin) + fps="" + s = "-s "+str(tsize[0])+"x"+str(tsize[1])+" " + x264fps="30000/1001" + x264tune=x264tune+" --tff --nal-hrd vbr" + filter="" + x264streamsize=str(tsize[0])+u"x"+str(tsize[1]) + if quality==1: + x264preset=u"ultrafast" + elif quality==2: + x264preset=u"veryfast" + elif quality==3: + x264preset=u"fast" + elif quality==4: + x264preset=u"medium" + elif quality==5: + x264preset=u"slow" + elif quality==6: + x264preset=u"slower" + if size == "WVGA_BASE" or size == "QVGA_BASE": + x264profile=" --level 32 --profile baseline " + else: + x264profile=" --level 41 --profile high " + x264crf=str(crf) + txt="" + os.environ['LANG']="ja_JP.UTF-8" + exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -pix_fmt yuv420p "+s+fps+" "+filter+" -an -f rawvideo - | " + exe=exe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout,"-", x264streamsize, crf=x264crf) + exe = "nice -n 19 " + exe + txt="" + recdblist.printutf8(exe) + try: + txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') + except: + "" + recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt) +def getMovieBaseSize(pin): + ffmpeg=configreader.getPathSetting("ffmpeg") + os.environ['LANG']="ja_JP.UTF-8" + exe=ffmpeg+u" -i \""+pin+"\" 2>&1" + txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') + rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z") + sizeMaxX=0 + sizeMaxY=0 + txtls=txts.split("\n") + for t in txtls: + rM=rT.match(t) + if rM: + sizetxt=rM.group(1) + partxt=rM.group(2) + tX=int(sizetxt.split("x")[0]) + tY=int(sizetxt.split("x")[1]) + tEX=int(partxt.split(":")[0]) + tEY=int(partxt.split(":")[1]) + if sizeMaxX&1" + txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') + rT=re.compile(u"Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z") + sizeMaxX=0 + sizeMaxY=0 + txtls=txts.split("\n") + for t in txtls: + rM=rT.search(t) + if rM: + sizetxt=rM.group(1) + partxt=rM.group(2) + tX=int(sizetxt.split("x")[0]) + tY=int(sizetxt.split("x")[1]) + tEX=int(partxt.split(":")[0]) + tEY=int(partxt.split(":")[1]) + if sizeMaxX&1" + txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') + rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z") + sizeMaxX=0 + parx=0 + pary=0 + txtls=txts.split("\n") + for t in txtls: + rM=rT.match(t) + if rM: + sizetxt=rM.group(1) + dartxt=rM.group(2) + tX=int(sizetxt.split("x")[0]) + tY=int(sizetxt.split("x")[1]) + tEX=int(dartxt.split(":")[0]) + tEY=int(dartxt.split(":")[1]) + if sizeMaxX&1" + txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') + rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z") + sizeMaxX=0 + parx=0 + pary=0 + txtls=txts.split("\n") + for t in txtls: + rM=rT.match(t) + if rM: + sizetxt=rM.group(1) + dartxt=rM.group(2) + tX=int(sizetxt.split("x")[0]) + tY=int(sizetxt.split("x")[1]) + tEX=int(dartxt.split(":")[0]) + tEY=int(dartxt.split(":")[1]) + if sizeMaxX&1" + txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') + rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z") + sizeMaxX=0 + darx=0 + dary=0 + txtls=txts.split("\n") + for t in txtls: + rM=rT.match(t) + if rM: + sizetxt=rM.group(1) + dartxt=rM.group(2) + tX=int(sizetxt.split("x")[0]) + tY=int(sizetxt.split("x")[1]) + tEX=int(dartxt.split(":")[0]) + tEY=int(dartxt.split(":")[1]) + if sizeMaxX&1" + txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') + rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z") + sizeMaxX=0 + darx=0 + dary=0 + txtls=txts.split("\n") + for t in txtls: + rM=rT.match(t) + if rM: + sizetxt=rM.group(1) + dartxt=rM.group(2) + tX=int(sizetxt.split("x")[0]) + tY=int(sizetxt.split("x")[1]) + tEX=int(dartxt.split(":")[0]) + tEY=int(dartxt.split(":")[1]) + if sizeMaxXint(tX/10)*10: + tX=tX/10+1 + else: + tX=tX/10 + else: + tX=-1 + tY=-1 + return [tX,tY] +def getX264CoreVersion(): + x264=configreader.getPathSetting("x264") + t1=commands.getoutput(x264+" --help|grep core") + rT=re.compile(u"x264 core:(\d*)[\d]*.*\Z") + rM=rT.match(t1) + v=-1 + if rM: + v=int(rM.group(1)) + return v +def getX264Commandline(preset,sar,fps,x264profile,x264tune,pout,pin,x264streamsize,crf=-1,bitrate=0): + x264=configreader.getPathSetting("x264") + os.environ['LANG']="ja_JP.UTF-8" + x264_sar="--sar "+sar + x264preset=u"--preset "+preset + x264fps="--fps "+fps + if crf==-1: + x264bitrate=u"--bitrate "+str(bitrate) + else: + x264crf=u"--crf "+str(crf) + x264_addline=configreader.getConfEnv("x264_addline") + x264_thread="auto" + try: + xtt=configreader.getConfEnv("x264_thread") + xtt=int(xtt) + if xtt>0: + x264_thread=str(xtt) + except: + x264_thread="auto" + x264_addline=configreader.getConfEnv("x264_addline") + if get_x264core_version()>103: + x264res=u"--input-res "+x264streamsize + exe=u"nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" "+x264res+" -o \""+pout+"\" "+pin + else: + exe=u"nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+pin+" "+x264streamsize + return exe diff --git a/rec10/trunk/src/tv2audio.py b/rec10/trunk/src/tv2audio.py index 55be78d..fc5335c 100644 --- a/rec10/trunk/src/tv2audio.py +++ b/rec10/trunk/src/tv2audio.py @@ -1,270 +1,270 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import os -import re -import commands -import os -import re -import shutil -import time -import os.path -import subprocess -import signal - -import configreader -import recdblist - -def wav2aac_nero(pin,pout): - os.environ['LANG']="ja_JP.UTF-8" - neroaac=configreader.getPathSetting('NeroAAC') - exe=neroaac+" -br 128000 -2pass -if \""+pin+"\" -of \""+pout+"\"" - try: - txt=commands.getoutput(exe.encode('utf-8')) - recdblist.addLog(pin, exe, u"Wav2aac_Neroログ-コマンド") - recdblist.addLog(pin, txt, u"Wav2aac_Neroログ-詳細") - except: - if not os.path.exists(pout): - lame="lame" - exe=lame+" -b 128 \""+pin+"\" \""+pout+"\"" - txt=commands.getoutput(exe.encode('utf-8')) - recdblist.addLog(pin, exe, u"Wav2aac_Lameログ-コマンド") - recdblist.addLog(pin, txt, u"Wav2aac_Lameログ-詳細") -def wav2mp3_lame(pin,pout): - os.environ['LANG']="ja_JP.UTF-8" - lame="lame" - exe=lame+" -b 128 \""+pin+"\" \""+pout+"\"" - try: - txt=commands.getoutput(exe.encode('utf-8')) - except: - "" - recdblist.addLog(pin, exe, u"Wav2aac_Lameログ-コマンド") - recdblist.addLog(pin, txt, u"Wav2aac_Lameログ-詳細") -def ts2single_audio(pts,opts): - paac=pts.replace(".ts",".aac") - ffmpeg=configreader.getPathSetting("ffmpeg") - e0=ffmpeg+" -i \""+pts+"\" -y -vn -f aac -acodec copy \""+paac+"\"" - p0=subprocess.Popen(e0,shell=True) - os.waitpid(p0.pid, 0) - if p0.poll==None:#実行中 - if os.path.exists(paac): - if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了 - try: - logt=unicode(p0.communicate()[0], "UTF-8") - recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") - recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") - except: - "" - recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200) - os.kill(p0.pid,signal.SIGKILL) - os.remove(paac) - ts2single_mp3_ffmpeg(pts) - if not os.path.exists(pts.replace(".ts",".mp3")): - ts2single_fp_BonTsDemux(pts,opts) - else: - logt=unicode(p0.communicate()[0], "UTF-8") - recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") - recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") - else: - try: - logt=unicode(p0.communicate()[0], "UTF-8") - recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") - recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") - except: - "" - recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200) - try: - os.kill(p0.pid,signal.SIGKILL) - except: - "" - ts2single_mp3_ffmpeg(pts) - if not os.path.exists(pts.replace(".ts",".mp3")): - ts2single_fp_BonTsDemux(pts,opts) - else: - if os.path.exists(paac): - if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了 - try: - logt=unicode(p0.communicate()[0], "UTF-8") - recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") - recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") - except: - "" - recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200) - os.remove(paac) - ts2single_mp3_ffmpeg(pts) - if not os.path.exists(pts.replace(".ts",".mp3")): - ts2single_fp_BonTsDemux(pts,opts) - else: - try: - logt=unicode(p0.communicate()[0], "UTF-8") - recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") - recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") - except: - "" - else: - try: - logt=unicode(p0.communicate()[0], "UTF-8") - recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") - recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") - except: - "" - recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200) - ts2single_mp3_ffmpeg(pts) - if not os.path.exists(pts.replace(".ts",".mp3")): - ts2single_fp_BonTsDemux(pts,opts) -def ts2singlewav(pts,opts): - bontsdemux = configreader.getPathSetting('bontsdemux') - bonpin = "Z:\\" + pts[1:] - outf = os.path.splitext(pts)[0] - bonpout = "Z:\\" + outf[1:] - delayt="" - exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" "+delayt+" -nd -sound 0 -o \"" + bonpout + "\"" - #recdblist.printutf8(exe) - recdblist.printutf8(exe) - p=subprocess.Popen(exe.encode('utf-8'),shell=True) - os.waitpid(p.pid, 0) - logt=unicode(p.communicate()[0], "UTF-8") - recdblist.addCommandLog(ots, u"BonTsDemux 音声取り出し", exe, logt) -def ts2single_mp3_ffmpeg(pts): - pmp3=pts.replace(".ts",".mp3") - ffmpeg=configreader.getPathSetting("ffmpeg") - e0=ffmpeg+" -i \""+pts+"\" -y -vn -ab 128k \""+pmp3+"\"" - p0=subprocess.Popen(e0,shell=True) - os.waitpid(p0.pid, 0) - try: - logt=unicode(p0.communicate()[0], "UTF-8") - recdblist.addLog(pts,e0, "FFmpeg_mp3音声取り出しログ-コマンド") - recdblist.addLog(pts,logt, "FFmpeg_mp3音声取り出しログ-詳細") - except: - "" -def ts2single_fp_BonTsDemux(pts,opts): - useNero=0 - try: - if configreader.getPathSetting("useNeroAAC")=="1" and os.path.exists(configreader.getPathSetting("NeroAAC")): - useNero=1 - except: - useNero=0 - if useNero==1: - ts2single_aac_BonTsDemux_Nero(pts,opts) - else: - ts2single_mp3_BonTsDemux(pts,opts) -def ts2single_aac_BonTsDemux_Nero(pts,opts): - ts2singlewav(pts,opts) - aout=pts.replace(".ts",".aac") - ain=pts.replace(".ts",".wav") - wav2aac_nero(ain,aout) -def ts2single_mp3_BonTsDemux(pts,opts): - ts2singlewav(pts,opts) - aout=pts.replace(".ts",".mp3") - ain=pts.replace(".ts",".wav") - wav2mp3_lame(ain,aout) -def ts2dualaudio_BonTsDemux(pin, delay,opts): - """ - delay is string - """ - bontsdemux = configreader.getPathSetting('bontsdemux') - wine = configreader.getPathSetting('wine') - bonpin = "Z:\\" + pin[1:] - outf = os.path.splitext(pin)[0] - bonpout = "Z:\\" + outf[1:] - exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 1 -o \"" + bonpout + "\"" - recdblist.printutf8(exe) - txt=commands.getoutput(exe.encode('utf-8')) - try: - recdblist.addCommandLog(pin, u"BonTsDemux 第一音声取り出し", exe, txt) - except: - "" - ffpin = pin.replace(".ts", "") - ffpin1 = pin.replace("ts", "wav") - ffpin2 = pin.replace("ts", "m2v") - ffpout1 = ffpin + "_1.wav" - ffpout2 = ffpin + "_2.wav" - ffpout3 = ffpin + ".m2v" - shutil.move(ffpin1, ffpout1) - exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 2 -encode Demux\(wav\) -o \"" + bonpout + "\"" - recdblist.printutf8(exe) - txt=commands.getoutput(exe.encode('utf-8')) - try: - recdblist.addCommandLog(pin, u"BonTsDemux 第二音声取り出し", exe, txt) - except: - "" - #os.system(exe) - shutil.move(ffpin1, ffpout2) - shutil.move(ffpin2, ffpout3) - ffpout21=ffpout1.replace(".wav",".mp3") - ffpout22=ffpout2.replace(".wav",".mp3") - useNero=0 - try: - if configreader.getPathSetting("useNeroAAC")=="1" and os.path.exists(configreader.getPathSetting("NeroAAC")): - useNero=1 - except: - useNero=0 - if useNero==1: - ffpout21=ffpout1.replace(".wav",".aac") - ffpout22=ffpout2.replace(".wav",".aac") - wav2aac_nero(ffpout1, ffpout21) - wav2aac_nero(ffpout2, ffpout22) - else: - wav2mp3_lame(ffpout1, ffpout21) - wav2mp3_lame(ffpout2, ffpout22) - time.sleep(3) - os.remove(ffpout1) - os.remove(ffpout2) -def ts2pentaaudio_BonTsDemux(pin, delay,opts): - bontsdemux = configreader.getPathSetting('bontsdemux') - wine = configreader.getPathSetting('wine') - bonpin = "Z:\\" + pin[1:] - outf = os.path.splitext(pin)[0] - bonpout = "Z:\\" + outf[1:] - exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay "+delay+" -nd -sound 3 -o \"" + bonpout + "\"" - recdblist.printutf8(exe) - txt=commands.getoutput(exe.encode('utf-8')) - try: - recdblist.addCommandLog(pin, u"BonTsDemux5.1ch 第一音声取り出し", exe, txt) - except: - "" - ffpin = pin.replace(".ts", "") - ffpin1 = pin.replace("ts", "wav") - ffpin2 = pin.replace("ts", "m2v") - ffpout1 = ffpin + "_1.wav" - ffpout2 = ffpin + "_2.aac" - shutil.move(ffpin1, ffpout1) - exe = "ffmpeg -i '"+pin+"' -vn -f aac -acodec copy '"+ffpout2+"'" - recdblist.printutf8(exe) - txt=commands.getoutput(exe.encode('utf-8')) - try: - recdblist.addCommandLog(pin, u"FFmpeg 5.1ch 第二音声(raw AAC)取り出し", exe, txt) - except: - "" - ffpout21=ffpout1.replace(".wav",".mp3") - useNero=0 - try: - if configreader.getPathSetting("useNeroAAC")=="1" and os.path.exists(configreader.getPathSetting("NeroAAC")): - useNero=1 - except: - useNero=0 - if useNero==1: - ffpout21=ffpout1.replace(".wav",".aac") - wav2aac_nero(ffpout1, ffpout21) - else: - wav2mp3_lame(ffpout1, ffpout21) - if not os.path.exists(ffpout21): - exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay "+delay+" -nd -sound 0 -o \"" + bonpout + "\"" - recdblist.printutf8(exe) - txt=commands.getoutput(exe.encode('utf-8')) - try: - recdblist.addCommandLog(pin, u"BonTsDemux 修正版第二音声(2chDownmix)取り出し", exe, txt) - except: - "" - shutil.move(ffpin1, ffpout1) - if useNero==1: - ffpout21=ffpout1.replace(".wav",".aac") - wav2aac_nero(ffpout1, ffpout21) - else: - wav2mp3_lame(ffpout1, ffpout21) - time.sleep(3) - ffpout21=ffpout1.replace(".wav",".aac") - if os.path.exists(ffpout21): - if os.path.getsize(ffpout21)>10*1000*1000: - os.remove(ffpout1) +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import os +import re +import commands +import os +import re +import shutil +import time +import os.path +import subprocess +import signal + +import configreader +import recdblist + +def wav2aac_nero(pin,pout): + os.environ['LANG']="ja_JP.UTF-8" + neroaac=configreader.getConfPath('NeroAAC') + exe=neroaac+" -br 128000 -2pass -if \""+pin+"\" -of \""+pout+"\"" + try: + txt=commands.getoutput(exe.encode('utf-8')) + recdblist.addLog(pin, exe, u"Wav2aac_Neroログ-コマンド") + recdblist.addLog(pin, txt, u"Wav2aac_Neroログ-詳細") + except: + if not os.path.exists(pout): + lame="lame" + exe=lame+" -b 128 \""+pin+"\" \""+pout+"\"" + txt=commands.getoutput(exe.encode('utf-8')) + recdblist.addLog(pin, exe, u"Wav2aac_Lameログ-コマンド") + recdblist.addLog(pin, txt, u"Wav2aac_Lameログ-詳細") +def wav2mp3_lame(pin,pout): + os.environ['LANG']="ja_JP.UTF-8" + lame="lame" + exe=lame+" -b 128 \""+pin+"\" \""+pout+"\"" + try: + txt=commands.getoutput(exe.encode('utf-8')) + except: + "" + recdblist.addLog(pin, exe, u"Wav2aac_Lameログ-コマンド") + recdblist.addLog(pin, txt, u"Wav2aac_Lameログ-詳細") +def ts2single_audio(pts,opts): + paac=pts.replace(".ts",".aac") + ffmpeg=configreader.getPathSetting("ffmpeg") + e0=ffmpeg+" -i \""+pts+"\" -y -vn -f aac -acodec copy \""+paac+"\"" + p0=subprocess.Popen(e0,shell=True) + os.waitpid(p0.pid, 0) + if p0.poll==None:#実行中 + if os.path.exists(paac): + if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了 + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") + except: + "" + recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200) + os.kill(p0.pid,signal.SIGKILL) + os.remove(paac) + ts2single_mp3_ffmpeg(pts) + if not os.path.exists(pts.replace(".ts",".mp3")): + ts2single_fp_BonTsDemux(pts,opts) + else: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") + else: + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") + except: + "" + recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200) + try: + os.kill(p0.pid,signal.SIGKILL) + except: + "" + ts2single_mp3_ffmpeg(pts) + if not os.path.exists(pts.replace(".ts",".mp3")): + ts2single_fp_BonTsDemux(pts,opts) + else: + if os.path.exists(paac): + if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了 + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") + except: + "" + recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200) + os.remove(paac) + ts2single_mp3_ffmpeg(pts) + if not os.path.exists(pts.replace(".ts",".mp3")): + ts2single_fp_BonTsDemux(pts,opts) + else: + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") + except: + "" + else: + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細") + except: + "" + recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200) + ts2single_mp3_ffmpeg(pts) + if not os.path.exists(pts.replace(".ts",".mp3")): + ts2single_fp_BonTsDemux(pts,opts) +def ts2singlewav(pts,opts): + bontsdemux = configreader.getPathSetting('bontsdemux') + bonpin = "Z:\\" + pts[1:] + outf = os.path.splitext(pts)[0] + bonpout = "Z:\\" + outf[1:] + delayt="" + exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" "+delayt+" -nd -sound 0 -o \"" + bonpout + "\"" + #recdblist.printutf8(exe) + recdblist.printutf8(exe) + p=subprocess.Popen(exe.encode('utf-8'),shell=True) + os.waitpid(p.pid, 0) + logt=unicode(p.communicate()[0], "UTF-8") + recdblist.addCommandLog(ots, u"BonTsDemux 音声取り出し", exe, logt) +def ts2single_mp3_ffmpeg(pts): + pmp3=pts.replace(".ts",".mp3") + ffmpeg=configreader.getPathSetting("ffmpeg") + e0=ffmpeg+" -i \""+pts+"\" -y -vn -ab 128k \""+pmp3+"\"" + p0=subprocess.Popen(e0,shell=True) + os.waitpid(p0.pid, 0) + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg_mp3音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg_mp3音声取り出しログ-詳細") + except: + "" +def ts2single_fp_BonTsDemux(pts,opts): + useNero=0 + try: + if configreader.getPathSetting("useNeroAAC")=="1" and os.path.exists(configreader.getPathSetting("NeroAAC")): + useNero=1 + except: + useNero=0 + if useNero==1: + ts2single_aac_BonTsDemux_Nero(pts,opts) + else: + ts2single_mp3_BonTsDemux(pts,opts) +def ts2single_aac_BonTsDemux_Nero(pts,opts): + ts2singlewav(pts,opts) + aout=pts.replace(".ts",".aac") + ain=pts.replace(".ts",".wav") + wav2aac_nero(ain,aout) +def ts2single_mp3_BonTsDemux(pts,opts): + ts2singlewav(pts,opts) + aout=pts.replace(".ts",".mp3") + ain=pts.replace(".ts",".wav") + wav2mp3_lame(ain,aout) +def ts2dualaudio_BonTsDemux(pin, delay,opts): + """ + delay is string + """ + bontsdemux = configreader.getPathSetting('bontsdemux') + wine = configreader.getPathSetting('wine') + bonpin = "Z:\\" + pin[1:] + outf = os.path.splitext(pin)[0] + bonpout = "Z:\\" + outf[1:] + exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 1 -o \"" + bonpout + "\"" + recdblist.printutf8(exe) + txt=commands.getoutput(exe.encode('utf-8')) + try: + recdblist.addCommandLog(pin, u"BonTsDemux 第一音声取り出し", exe, txt) + except: + "" + ffpin = pin.replace(".ts", "") + ffpin1 = pin.replace("ts", "wav") + ffpin2 = pin.replace("ts", "m2v") + ffpout1 = ffpin + "_1.wav" + ffpout2 = ffpin + "_2.wav" + ffpout3 = ffpin + ".m2v" + shutil.move(ffpin1, ffpout1) + exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 2 -encode Demux\(wav\) -o \"" + bonpout + "\"" + recdblist.printutf8(exe) + txt=commands.getoutput(exe.encode('utf-8')) + try: + recdblist.addCommandLog(pin, u"BonTsDemux 第二音声取り出し", exe, txt) + except: + "" + #os.system(exe) + shutil.move(ffpin1, ffpout2) + shutil.move(ffpin2, ffpout3) + ffpout21=ffpout1.replace(".wav",".mp3") + ffpout22=ffpout2.replace(".wav",".mp3") + useNero=0 + try: + if configreader.getPathSetting("useNeroAAC")=="1" and os.path.exists(configreader.getPathSetting("NeroAAC")): + useNero=1 + except: + useNero=0 + if useNero==1: + ffpout21=ffpout1.replace(".wav",".aac") + ffpout22=ffpout2.replace(".wav",".aac") + wav2aac_nero(ffpout1, ffpout21) + wav2aac_nero(ffpout2, ffpout22) + else: + wav2mp3_lame(ffpout1, ffpout21) + wav2mp3_lame(ffpout2, ffpout22) + time.sleep(3) + os.remove(ffpout1) + os.remove(ffpout2) +def ts2pentaaudio_BonTsDemux(pin, delay,opts): + bontsdemux = configreader.getPathSetting('bontsdemux') + wine = configreader.getPathSetting('wine') + bonpin = "Z:\\" + pin[1:] + outf = os.path.splitext(pin)[0] + bonpout = "Z:\\" + outf[1:] + exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay "+delay+" -nd -sound 3 -o \"" + bonpout + "\"" + recdblist.printutf8(exe) + txt=commands.getoutput(exe.encode('utf-8')) + try: + recdblist.addCommandLog(pin, u"BonTsDemux5.1ch 第一音声取り出し", exe, txt) + except: + "" + ffpin = pin.replace(".ts", "") + ffpin1 = pin.replace("ts", "wav") + ffpin2 = pin.replace("ts", "m2v") + ffpout1 = ffpin + "_1.wav" + ffpout2 = ffpin + "_2.aac" + shutil.move(ffpin1, ffpout1) + exe = "ffmpeg -i '"+pin+"' -vn -f aac -acodec copy '"+ffpout2+"'" + recdblist.printutf8(exe) + txt=commands.getoutput(exe.encode('utf-8')) + try: + recdblist.addCommandLog(pin, u"FFmpeg 5.1ch 第二音声(raw AAC)取り出し", exe, txt) + except: + "" + ffpout21=ffpout1.replace(".wav",".mp3") + useNero=0 + try: + if configreader.getPathSetting("useNeroAAC")=="1" and os.path.exists(configreader.getPathSetting("NeroAAC")): + useNero=1 + except: + useNero=0 + if useNero==1: + ffpout21=ffpout1.replace(".wav",".aac") + wav2aac_nero(ffpout1, ffpout21) + else: + wav2mp3_lame(ffpout1, ffpout21) + if not os.path.exists(ffpout21): + exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay "+delay+" -nd -sound 0 -o \"" + bonpout + "\"" + recdblist.printutf8(exe) + txt=commands.getoutput(exe.encode('utf-8')) + try: + recdblist.addCommandLog(pin, u"BonTsDemux 修正版第二音声(2chDownmix)取り出し", exe, txt) + except: + "" + shutil.move(ffpin1, ffpout1) + if useNero==1: + ffpout21=ffpout1.replace(".wav",".aac") + wav2aac_nero(ffpout1, ffpout21) + else: + wav2mp3_lame(ffpout1, ffpout21) + time.sleep(3) + ffpout21=ffpout1.replace(".wav",".aac") + if os.path.exists(ffpout21): + if os.path.getsize(ffpout21)>10*1000*1000: + os.remove(ffpout1) diff --git a/rec10/trunk/src/tv2avi.py b/rec10/trunk/src/tv2avi.py index 05811cf..82357b4 100644 --- a/rec10/trunk/src/tv2avi.py +++ b/rec10/trunk/src/tv2avi.py @@ -1,105 +1,105 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import commands -import datetime -import os -import re -import shutil -import time -import os.path -import traceback - -import chdb -import configreader -import status -import ts2x264 -import tv2ts -import recdblist -import tv2audio - - -global Bitrate_SD -global Bitrate_HD -global Bitrate_FHD -global Bitrate_Short -global Bitrate_LowHD -Bitrate_SD = 1250 -Bitrate_HD = 3750 -Bitrate_LowHD = 2500 -Bitrate_FHD = 5000 -Bitrate_Short = 1250 -def timetv2b25(pout, chtxt, btime, etime, opt): - """ - poutはタイトル - """ - bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") - et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") - extt = os.path.splitext(pout) - tsout = extt[0] - tnow = datetime.datetime.now() - wt = bt-tnow - waitt = wt.seconds - if waitt>0: - time.sleep(waitt) - tnow = datetime.datetime.now() - dt = et-tnow - rectime = dt.seconds-5 - rectime = str(rectime) - tv2ts.tv2b25ts(tsout + ".ts.b25", chdb.getChCSchFromCHtxt(chtxt)['ch'], rectime) -def b252ts(pout, chtxt, btime, etime, opt): - """ - poutはタイトル(自動的にtitle.b25 title.tsと名前がつきます。) - """ - #status.setB25Decoding(status.getB25Decoding() + 1) - status.changeB25Decoding(1) - try: - try: - ch=chtxt.split("_")[0] - csch=chtxt.split("_")[1] - except: - ch=0 - csch=0 - tv2ts.b252ts(pout + ".ts", ch, csch) - tsout = pout - aviin = pout + ".ts" - dualaudio = 0 - pentaaudio = 0 - singleaudiosplit = 0 - if re.search("5", opt): - pentaaudio = 1 - if re.search("d", opt): - dualaudio = 1 - if re.search(u"\[二\]", pout): - dualaudio = 1 - elif re.search(u'(二)', pout): - dualaudio = 1 - elif re.search(u'\(二\)', pout): - dualaudio = 1 - if dualaudio == 1: - tv2audio.ts2dualaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt) - if pentaaudio == 1: - tv2audio.ts2pentaaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt) - except Exception, inst: - recdblist.addCommonlogEX("Error", "b252ts(tv2avi.py)", str(type(inst))+traceback.format_exc(), str(inst)) - status.changeB25Decoding(-1) -def ts2avi(pin, pout, opt): - status.changeEncoding(1) - try: - ts2x264.ts2x264(pin, pout, opt) - except Exception, inst: - recdblist.printutf8("error occures in tv2avi.py ts2avi") - recdblist.printutf8(str(type(inst))) - recdblist.printutf8(str(inst)+traceback.format_exc()) - status.changeEncoding(-1) -def ts2raw(pin, pout, opt): - status.changeEncoding(1) - try: - ts2x264.ts2x264(pin, pout, opt) - except Exception, inst: - recdblist.printutf8("error occures in tv2avi.py ts2raw") - recdblist.printutf8(str(type(inst))) - recdblist.printutf8(str(inst)+traceback.format_exc()) - status.changeEncoding(-1) - +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import commands +import datetime +import os +import re +import shutil +import time +import os.path +import traceback + +import chdb +import configreader +import status +import ts2x264 +import tv2ts +import recdblist +import tv2audio + + +global Bitrate_SD +global Bitrate_HD +global Bitrate_FHD +global Bitrate_Short +global Bitrate_LowHD +Bitrate_SD = 1250 +Bitrate_HD = 3750 +Bitrate_LowHD = 2500 +Bitrate_FHD = 5000 +Bitrate_Short = 1250 +def timetv2b25(pout, chtxt, btime, etime, opt): + """ + poutはタイトル + """ + bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S") + et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S") + extt = os.path.splitext(pout) + tsout = extt[0] + tnow = datetime.datetime.now() + wt = bt-tnow + waitt = wt.seconds + if waitt>0: + time.sleep(waitt) + tnow = datetime.datetime.now() + dt = et-tnow + rectime = dt.seconds-5 + rectime = str(rectime) + tv2ts.tv2b25ts(tsout + ".ts.b25", chdb.searchCHFromChtxt(chtxt)['ch'], rectime) +def b252ts(pout, chtxt, btime, etime, opt): + """ + poutはタイトル(自動的にtitle.b25 title.tsと名前がつきます。) + """ + #status.setB25Decoding(status.getB25Decoding() + 1) + status.changeB25Decoding(1) + try: + try: + ch=chtxt.split("_")[0] + csch=chtxt.split("_")[1] + except: + ch=0 + csch=0 + tv2ts.b252ts(pout + ".ts", ch, csch) + tsout = pout + aviin = pout + ".ts" + dualaudio = 0 + pentaaudio = 0 + singleaudiosplit = 0 + if re.search("5", opt): + pentaaudio = 1 + if re.search("d", opt): + dualaudio = 1 + if re.search(u"\[二\]", pout): + dualaudio = 1 + elif re.search(u'(二)', pout): + dualaudio = 1 + elif re.search(u'\(二\)', pout): + dualaudio = 1 + if dualaudio == 1: + tv2audio.ts2dualaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt) + if pentaaudio == 1: + tv2audio.ts2pentaaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt) + except Exception, inst: + recdblist.addCommonlogEX("Error", "b252ts(tv2avi.py)", str(type(inst))+traceback.format_exc(), str(inst)) + status.changeB25Decoding(-1) +def ts2avi(pin, pout, opt): + status.changeEncoding(1) + try: + ts2x264.ts2x264(pin, pout, opt) + except Exception, inst: + recdblist.printutf8("error occures in tv2avi.py ts2avi") + recdblist.printutf8(str(type(inst))) + recdblist.printutf8(str(inst)+traceback.format_exc()) + status.changeEncoding(-1) +def ts2raw(pin, pout, opt): + status.changeEncoding(1) + try: + ts2x264.ts2x264(pin, pout, opt) + except Exception, inst: + recdblist.printutf8("error occures in tv2avi.py ts2raw") + recdblist.printutf8(str(type(inst))) + recdblist.printutf8(str(inst)+traceback.format_exc()) + status.changeEncoding(-1) + diff --git a/rec10/trunk/src/tv2mkv.py b/rec10/trunk/src/tv2mkv.py index 0bcc9b2..8cc7abd 100644 --- a/rec10/trunk/src/tv2mkv.py +++ b/rec10/trunk/src/tv2mkv.py @@ -1,21 +1,21 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze -import os -import os.path -import tv2mp4 -import configreader -import subprocess -import auto_process -def ts2mkv(pin, pout, opt): - tpout=pout.replace(".mkv",".mp4") - tv2mp4.ts2mp4(pin, tpout, opt) - mp42mkv(pout, tpout) - if os.path.exists(pout) and os.path.getsize(pout)>os.path.getsize(tpout)*0.9: - os.remove(tpout) -def mp42mkv(pmkv,pmp4): - exe = configreader.getPathSetting("mkvmerge") - e1=exe +" -o \""+pmkv+u"\" \""+pmp4+"\"" - p=subprocess.Popen(e1,shell=True) - os.waitpid(p.pid, 0) +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze +import os +import os.path +import tv2mp4 +import configreader +import subprocess +import auto_process +def ts2mkv(pin, pout, opt): + tpout=pout.replace(".mkv",".mp4") + tv2mp4.ts2mp4(pin, tpout, opt) + mp42mkv(pout, tpout) + if os.path.exists(pout) and os.path.getsize(pout)>os.path.getsize(tpout)*0.9: + os.remove(tpout) +def mp42mkv(pmkv,pmp4): + exe = configreader.getConfPath("mkvmerge") + e1=exe +" -o \""+pmkv+u"\" \""+pmp4+"\"" + p=subprocess.Popen(e1,shell=True) + os.waitpid(p.pid, 0) diff --git a/rec10/trunk/src/tv2mp4.py b/rec10/trunk/src/tv2mp4.py index 4b231f8..f83f224 100644 --- a/rec10/trunk/src/tv2mp4.py +++ b/rec10/trunk/src/tv2mp4.py @@ -51,7 +51,7 @@ def raw2mp4(pin,pout,opt): duration="-fps 29.970030 "##ffmpegが24fpsに対応していないための措置 if re.search("I",opt): duration="-fps 29.970030 " - exe = configreader.getPathSetting("mp4box") + exe = configreader.getConfPath("mp4box") txt="" os.environ['LANG']="ja_JP.UTF-8" pints=pin.replace(".264",".ts") @@ -64,14 +64,14 @@ def raw2mp4(pin,pout,opt): if status.getSettings_auto_del_tmp()==1: if os.path.exists(pout): if re.search(opt,"1") or re.search(opt,"2"): - auto_process.deltmpfile(dir, title, ".mp4") + auto_process.deleteTmpFile(dir, title, ".mp4") else: - auto_process.deltmpfile(dir, title, ".mp4") + auto_process.deleteTmpFile(dir, title, ".mp4") def mkv2mp4(pin,pout): - exeb = configreader.getPathSetting(u"mkvextract") - exe = configreader.getPath(u"mp4Box") - #dtsedit=configreader.getPath("DtsEdit") - wineexe=configreader.getPathSetting("wine") + exeb = configreader.getConfPath(u"mkvextract") + exe = configreader.getConfPath(u"mp4Box") + #dtsedit=configreader.getpath("DtsEdit") + wineexe=configreader.getConfPath("wine") dir=os.path.split(pin)[0] title=os.path.split(pin)[1] title=os.path.splitext(title)[0] @@ -98,12 +98,12 @@ def mkv2mp4(pin,pout): time.sleep(10) if status.getSettings_auto_del_tmp()==1: if os.path.exists(pout): - auto_process.deltmpfile(dir, title, ".mp4") + auto_process.deleteTmpFile(dir, title, ".mp4") def addCaption(pts,pmp4):##字幕の追加を試みる。 - wineexe=configreader.getPathSetting("wine") + wineexe=configreader.getConfPath("wine") pincap=pts.replace(".ts",".srt") try: - cap2ass=configreader.getPathSetting("caption2ass") + cap2ass=configreader.getConfPath("caption2ass") except: cap2ass="" if os.path.isfile(cap2ass): @@ -121,11 +121,11 @@ def addCaption(pts,pmp4):##字幕の追加を試みる。 recdblist.addlog(pts,logt, u"Captionログ-詳細") if os.path.exists(pincap): if os.path.getsize(pincap)>1000: - exe = configreader.getPathSetting("mp4box") + exe = configreader.getConfPath("mp4box") e1s=exe +u" -add \""+pincap+"\" \""+pmp4+"\"" addmp4(pincap,pmp4,e1s) def addAudio(pts,pmp4,opts):#オプションに応じた音声の追加を行う - exe = configreader.getPathSetting("mp4box") + exe = configreader.getConfPath("mp4box") if re.search("d",opts) or re.search("5",opts):#二カ国語放送/5.1ch放送の場合 paac1=pts.replace(".ts","_1.aac") paac2=pts.replace(".ts","_2.aac") @@ -220,4 +220,4 @@ def execcomd(cmd): txt=txt+unicode(txt2,"utf-8")+"\n" except: "" - return txt \ No newline at end of file + return txt diff --git a/rec10/trunk/src/xml2db_dom.py b/rec10/trunk/src/xml2db_dom.py index d7872b9..5b090e2 100644 --- a/rec10/trunk/src/xml2db_dom.py +++ b/rec10/trunk/src/xml2db_dom.py @@ -1,123 +1,123 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze - -import xml.dom.minidom -import datetime -import re -import traceback - -import zenhan -import chdb -import auto_rec -import recdb -import rec10d -import n_gram -import recdblist -import epgdb -import status -def getText(elm): - nodelist = elm.childNodes - rc = "" - # 全てのノードに対して - for node in nodelist: - # テキストノードなら値を取得 - if node.nodeType == node.TEXT_NODE: - rc = rc + node.data - return rc -def getText_item(obj): - rc="" - for o in obj: - rc=rc+getText(o) - return rc -def writeMultiTVDB(bctype,tvlists): - 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(chlists): - for chtxt,dn in chlists: - rec10d.rec10db.update_chname_by_chtxt_epg_ch(chtxt,dn) -def xml2db_dom(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る - dtb=datetime.datetime.now() - dom=xml.dom.minidom.parse(file(xmlpath)) - chlist=[] - tvlist=[] - bayes={} - rHisch=re.compile(u"『([^『]+)』(.+)\Z")##History CHのタイトル#01 exp:「#01説明」をタイトルに含める - for ch in dom.getElementsByTagName('channel'): - chtxtt=ch.getAttribute("id") - chname=ch.getElementsByTagName("display-name").item(0).childNodes[0].data - chlist.append([chtxtt,chname]) - for tv in dom.getElementsByTagName('programme'): - channel=zenhan.toHankaku_ABC123(tv.getAttribute("channel")) - start=tv.getAttribute("start").replace(" +0900", "") - stop=tv.getAttribute("stop").replace(" +0900", "") - title=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("title"))).replace(",", "_") - desc=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("desc"))) - longdesc=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("longdesc"))) - category=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("category"))) - title=addTitle_Subtitle(rHisch,1,title,desc) - tch=chdb.searchFromCHtxt(channel) - if tch!=None: - 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.calcKey(tch['chtxt'], title,desc+" "+longdesc) - if p>2000: - 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_bychtxt_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<350: - if status.getSettings_auto_bayes()==1: - if p2<200: - maxnum=0 - if len(ch['ch'])>2: - maxnum=epgdb.count_schedule_timeline(bttime, ettime)[1] - maxnum=int(configreader.getEnvSetting("bscs_max"))-maxnum - else: - maxnum=epgdb.count_schedule_timeline(bttime, ettime)[0] - maxnum=int(configreader.getEnvSetting("te_max"))-maxnum - if maxnum>0: - topt=status.getSettings_auto_opt() - recdb.recreserv(title,tch['chtxt'], bttime, ettime,topt) - else: - recdb.add_auto_bayes(tch['chtxt'],title,start,stop,p) - - dom.unlink() - if len(chlist) > 0: - writeMultiCHDB(chlist) - chlist = [] - if len(tvlist) > 0: - writeMultiTVDB(bctype,tvlist) - tvlist = [] - for ct,list in bayes.items(): - auto_rec.updateRecall(ct,list[0],list[1],list[2]) - auto_rec.updateRecall("ALL",list[0],list[1],list[2]) - dtb=datetime.datetime.now()-dtb - recdblist.printutf8(bctype + u" epg取り出し終了") - recdblist.printutf8(str(dtb.days * 24 * 60 * 60 + dtb.seconds)+u"seconds taken for updating bayes-auto DB .") -def addTitle_Subtitle(recompiled,num,title,exp): - try: - tST=recompiled.match(exp) - newtitle=u"" - if tST: - newtitle=title+u"『"+tST.group(num)+u"』" - else: - newtitle=title - except Exception, inst: - recdblist.addCommonlogEX("Error", "addTitle_Subtitle(xml2db_dob.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) - newtitle=title - return newtitle \ No newline at end of file +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2010 Yukikaze + +import xml.dom.minidom +import datetime +import re +import traceback + +import zenhan +import chdb +import auto_rec +import recdb +import rec10d +import n_gram +import recdblist +import epgdb +import status +def getText(elm): + nodelist = elm.childNodes + rc = "" + # 全てのノードに対して + for node in nodelist: + # テキストノードなら値を取得 + if node.nodeType == node.TEXT_NODE: + rc = rc + node.data + return rc +def getText_item(obj): + rc="" + for o in obj: + rc=rc+getText(o) + return rc +def writeMultiTVDB(bctype,tvlists): + 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(chlists): + for chtxt,dn in chlists: + rec10d.rec10db.update_chname_by_chtxt_epg_ch(chtxt,dn) +def xml2db_dom(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る + dtb=datetime.datetime.now() + dom=xml.dom.minidom.parse(file(xmlpath)) + chlist=[] + tvlist=[] + bayes={} + rHisch=re.compile(u"『([^『]+)』(.+)\Z")##History CHのタイトル#01 exp:「#01説明」をタイトルに含める + for ch in dom.getElementsByTagName('channel'): + chtxtt=ch.getAttribute("id") + chname=ch.getElementsByTagName("display-name").item(0).childNodes[0].data + chlist.append([chtxtt,chname]) + for tv in dom.getElementsByTagName('programme'): + channel=zenhan.toHankaku_ABC123(tv.getAttribute("channel")) + start=tv.getAttribute("start").replace(" +0900", "") + stop=tv.getAttribute("stop").replace(" +0900", "") + title=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("title"))).replace(",", "_") + desc=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("desc"))) + longdesc=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("longdesc"))) + category=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("category"))) + title=addTitle_Subtitle(rHisch,1,title,desc) + tch=chdb.searchFromCHtxt(channel) + if tch!=None: + 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.calcKey(tch['chtxt'], title,desc+" "+longdesc) + if p>2000: + 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_bychtxt_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<350: + if status.getSettings_auto_bayes()==1: + if p2<200: + maxnum=0 + if len(ch['ch'])>2: + maxnum=epgdb.count_schedule_timeline(bttime, ettime)[1] + maxnum=int(configreader.getConfEnv("bscs_max"))-maxnum + else: + maxnum=epgdb.count_schedule_timeline(bttime, ettime)[0] + maxnum=int(configreader.getConfEnv("te_max"))-maxnum + if maxnum>0: + topt=status.getSettings_auto_opt() + recdb.reserveReckey(recdblist.REC_RESERVE,title,tch['chtxt'], bttime, ettime,topt) + else: + recdb.addAutoBayesKeyword(tch['chtxt'],title,start,stop,p) + + dom.unlink() + if len(chlist) > 0: + writeMultiCHDB(chlist) + chlist = [] + if len(tvlist) > 0: + writeMultiTVDB(bctype,tvlist) + tvlist = [] + for ct,list in bayes.items(): + auto_rec.updateRecall(ct,list[0],list[1],list[2]) + auto_rec.updateRecall("ALL",list[0],list[1],list[2]) + dtb=datetime.datetime.now()-dtb + recdblist.printutf8(bctype + u" epg取り出し終了") + recdblist.printutf8(str(dtb.days * 24 * 60 * 60 + dtb.seconds)+u"seconds taken for updating bayes-auto DB .") +def addTitle_Subtitle(recompiled,num,title,exp): + try: + tST=recompiled.match(exp) + newtitle=u"" + if tST: + newtitle=title+u"『"+tST.group(num)+u"』" + else: + newtitle=title + except Exception, inst: + recdblist.addCommonlogEX("Error", "addTitle_Subtitle(xml2db_dob.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200) + newtitle=title + return newtitle -- 2.11.0