From 457582814be566efb4e3ee88bd54dcf6f6ee641f Mon Sep 17 00:00:00 2001 From: longinus Date: Fri, 4 Jan 2013 16:14:24 +0000 Subject: [PATCH] convert CRLF to LF git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@952 4e526526-5e11-4fc0-8910-f8fd03428081 --- rec10/trunk/src/auto_move.py | 300 +++++------ rec10/trunk/src/auto_process.py | 570 ++++++++++---------- rec10/trunk/src/auto_test.py | 86 +-- rec10/trunk/src/chdata.py | 74 +-- rec10/trunk/src/chdb.py | 202 +++---- rec10/trunk/src/classify.py | 314 +++++------ rec10/trunk/src/configreader.py | 66 +-- rec10/trunk/src/configwriter.py | 64 +-- rec10/trunk/src/epgdb.py | 554 +++++++++---------- rec10/trunk/src/install.py | 616 +++++++++++----------- rec10/trunk/src/rec10d.py | 68 +-- rec10/trunk/src/recdb.py | 190 +++---- rec10/trunk/src/recdblist.py | 418 +++++++-------- rec10/trunk/src/recque.py | 160 +++--- rec10/trunk/src/status.py | 82 +-- rec10/trunk/src/ts2epg.py | 134 ++--- rec10/trunk/src/ts2x264.py | 1112 +++++++++++++++++++-------------------- rec10/trunk/src/tv2audio.py | 572 ++++++++++---------- rec10/trunk/src/tv2avi.py | 222 ++++---- rec10/trunk/src/tv2mkv.py | 42 +- rec10/trunk/src/tv2mp4.py | 478 ++++++++--------- rec10/trunk/src/xml2db_dom.py | 296 +++++------ rec10/trunk/src/zenhan.py | 2 +- 23 files changed, 3311 insertions(+), 3311 deletions(-) diff --git a/rec10/trunk/src/auto_move.py b/rec10/trunk/src/auto_move.py index 9f7f95e..195b1b8 100644 --- a/rec10/trunk/src/auto_move.py +++ b/rec10/trunk/src/auto_move.py @@ -1,154 +1,154 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2011 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")) - delpath.append(os.path.join(temppath,title+".log.zip")) - 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) +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 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")) + delpath.append(os.path.join(temppath,title+".log.zip")) + 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) # patched. orig: searchFolder(title, recpath) - sf=guess.searchFolder(title, recpath,200) - 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: + sf=guess.searchFolder(title, recpath,200) + 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: "" else: recdblist.printutf8("sf not fonud @ execMove",verbose_level=100) - -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) + +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 5523768..fabee05 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-2011 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',errors='replace') - 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],ret[6]) - 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],ret[6]) - 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: - m2vpath=unicode(fn.replace(".264",".m2v"),'utf-8') - x264path=os.path.split(fn)[1] - folderpath=unicode(os.path.split(fn)[0],'utf-8') - x264path=re.sub("\\[","[",x264path) - x264path=re.sub("\[","\\\[",x264path) - x264path=re.sub("\\]","]",x264path) - x264path=re.sub("]","\\]",x264path) - tspath=unicode(x264path.replace(".264",".ts"),'utf-8') - m2vpath=unicode(x264path.replace(".264",".m2v"),'utf-8') - x264path=unicode(x264path,'utf-8') - os.environ['LANG']="ja_JP.UTF-8" - ktmp=[] - ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+x264path+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep x264 | awk '{print $2}'") - ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+tspath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'") - ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+m2vpath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep ffmpeg | awk '{print $2}'") - recdblist.printutf8(u"エンコード処理異常終了タスク終了") - for istr in ktmp: - recdblist.printutf8(istr) - ktmt=commands.getoutput(istr.encode('utf-8')) - #print ktmt - #print len(ktmt) - if len(ktmt)>0: - #print ktmt - if len(ktmt[0])>0: - ktmt=ktmt[0] - #print ktmt - try: - if int(ktmt)>0: - ktmp=u"kill -9 `"+istr+u"`" - recdblist.printutf8(ktmp) - #print ktmp - os.system(ktmp.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: - "" +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 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',errors='replace') + 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],ret[6]) + 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],ret[6]) + 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: + m2vpath=unicode(fn.replace(".264",".m2v"),'utf-8') + x264path=os.path.split(fn)[1] + folderpath=unicode(os.path.split(fn)[0],'utf-8') + x264path=re.sub("\\[","[",x264path) + x264path=re.sub("\[","\\\[",x264path) + x264path=re.sub("\\]","]",x264path) + x264path=re.sub("]","\\]",x264path) + tspath=unicode(x264path.replace(".264",".ts"),'utf-8') + m2vpath=unicode(x264path.replace(".264",".m2v"),'utf-8') + x264path=unicode(x264path,'utf-8') + os.environ['LANG']="ja_JP.UTF-8" + ktmp=[] + ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+x264path+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep x264 | awk '{print $2}'") + ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+tspath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'") + ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+m2vpath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep ffmpeg | awk '{print $2}'") + recdblist.printutf8(u"エンコード処理異常終了タスク終了") + for istr in ktmp: + recdblist.printutf8(istr) + ktmt=commands.getoutput(istr.encode('utf-8')) + #print ktmt + #print len(ktmt) + if len(ktmt)>0: + #print ktmt + if len(ktmt[0])>0: + ktmt=ktmt[0] + #print ktmt + try: + if int(ktmt)>0: + ktmp=u"kill -9 `"+istr+u"`" + recdblist.printutf8(ktmp) + #print ktmp + os.system(ktmp.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 4c6db07..74fd961 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-2011 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,t['tsid']) - 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") +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 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,t['tsid']) + 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 47a2ace..0b2120a 100644 --- a/rec10/trunk/src/chdata.py +++ b/rec10/trunk/src/chdata.py @@ -1,37 +1,37 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2012 Yukikaze -import os.path -import configreader -import xml.dom.minidom -import scan_ch -import datetime - -import rec10d - -path = str(os.path.dirname(os.path.abspath(__file__))) + "/" - -def chAdd(bctype, chtxt, ch, csch,tsid="0"):#すべて文字列 - tnow=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") - rec10d.rec10db.add_epg_ch(bctype,chtxt, ch, csch,tsid, u"2010-01-01 00:00:00",u"2010-01-01 00:00:00",tnow) -def addCHlist(cl): - if len(cl)>0: - for c in cl: - chAdd(c[0],c[1],c[2],c[3]) -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 -def deleteChListALL(): - rec10d.rec10db.new_epg_ch() -if __name__ == "__main__": - deleteChListALL() - scan_ch.searchCh() +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2012 Yukikaze +import os.path +import configreader +import xml.dom.minidom +import scan_ch +import datetime + +import rec10d + +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" + +def chAdd(bctype, chtxt, ch, csch,tsid="0"):#すべて文字列 + tnow=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + rec10d.rec10db.add_epg_ch(bctype,chtxt, ch, csch,tsid, u"2010-01-01 00:00:00",u"2010-01-01 00:00:00",tnow) +def addCHlist(cl): + if len(cl)>0: + for c in cl: + chAdd(c[0],c[1],c[2],c[3]) +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 +def deleteChListALL(): + rec10d.rec10db.new_epg_ch() +if __name__ == "__main__": + deleteChListALL() + scan_ch.searchCh() diff --git a/rec10/trunk/src/chdb.py b/rec10/trunk/src/chdb.py index a4aff06..9763b53 100644 --- a/rec10/trunk/src/chdb.py +++ b/rec10/trunk/src/chdb.py @@ -1,101 +1,101 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2012 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],'tsid':datum[4],'update':datum[5], 'chname':datum[6], 'visible':datum[8]} - 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],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} - 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],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} - ret.append(rett) - if len(ret) == 0: - ret.append(None) - return ret[0] -def searchCHFromCsch(cschin): - ret = [] - for datum in rec10d.rec10db.select_by_csch_epg_ch(cschin): - rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} - ret.append(rett) - if len(ret) == 0: - ret.append(None) - return ret[0] -def searchAllCHFromCh(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],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} - ret.append(rett) - if len(ret) == 0: - ret.append(None) - return ret -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],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} - ret.append(rett) - if len(ret) == 0: - ret.append(None) - return ret -def update(): - ret = [] - CSupdate = 0 - CS2update = 0 - BSupdate = 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 -def changeCHShow(chtxt,isshow): - rec10d.rec10db.change_visible_epg_ch(chtxt, isshow) -def updateLogo(): - ret=[] - BSCSUpdate=0 - for datum in rec10d.rec10db.select_get_updatelogo_epg_ch("720"): - bctype=datum[0] - if bctype == "cs1" or bctype == u"cs1": - if BSCSUpdate==0: - ret.append(u"bs") - BSCSUpdate=1 - elif bctype == "cs2" or bctype == u"cs2": - if BSCSUpdate==0: - ret.append(u"bs") - BSCSUpdate=1 - elif bctype == "bs" or bctype == u"bs": - if BSCSUpdate==0: - ret.append(u"bs") - BSCSUpdate=1 - else: - ret.append(bctype) - return ret +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2012 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],'tsid':datum[4],'update':datum[5], 'chname':datum[6], 'visible':datum[8]} + 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],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} + 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],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret[0] +def searchCHFromCsch(cschin): + ret = [] + for datum in rec10d.rec10db.select_by_csch_epg_ch(cschin): + rett = {'bctype':datum[0], 'chtxt':datum[1], 'ch':datum[2], 'csch':datum[3],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret[0] +def searchAllCHFromCh(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],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret +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],'tsid':datum[4], 'update':datum[5], 'chname':datum[6], 'visible':datum[8]} + ret.append(rett) + if len(ret) == 0: + ret.append(None) + return ret +def update(): + ret = [] + CSupdate = 0 + CS2update = 0 + BSupdate = 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 +def changeCHShow(chtxt,isshow): + rec10d.rec10db.change_visible_epg_ch(chtxt, isshow) +def updateLogo(): + ret=[] + BSCSUpdate=0 + for datum in rec10d.rec10db.select_get_updatelogo_epg_ch("720"): + bctype=datum[0] + if bctype == "cs1" or bctype == u"cs1": + if BSCSUpdate==0: + ret.append(u"bs") + BSCSUpdate=1 + elif bctype == "cs2" or bctype == u"cs2": + if BSCSUpdate==0: + ret.append(u"bs") + BSCSUpdate=1 + elif bctype == "bs" or bctype == u"bs": + if BSCSUpdate==0: + ret.append(u"bs") + BSCSUpdate=1 + else: + ret.append(bctype) + return ret diff --git a/rec10/trunk/src/classify.py b/rec10/trunk/src/classify.py index 9d0ca14..a496f1b 100644 --- a/rec10/trunk/src/classify.py +++ b/rec10/trunk/src/classify.py @@ -1,162 +1,162 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2011 Yukikaze - -import os -import os.path -import optparse -import sys - -import configreader -import recdblist -import auto_move -import guess -recordedpath=unicode(configreader.getConfPath("recorded"),'utf-8') -recpath=unicode(configreader.getConfPath("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("-m","--manual",action="store_true",dest="manual",default=False,help="manual classifying mode asking for y/n(not a test)") - #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.getMoveDestpath(ltitle,recpath,sf,".mkv")+".mkv"),verbose_level=100) - print "\n" - print "###MP4###" - recdblist.printutf8(os.path.join(sf, auto_move.getMoveDestpath(ltitle,recpath,sf,".mp4")+".mp4"),verbose_level=100) - print "\n" - elif opts.auto:##-A の場合 - sa=auto_move.searchFile(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.getMoveDestpath(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,200) - if sf!="": - recdblist.printutf8(u"移動先",verbose_level=100) - recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.getMoveDestpath(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.manual:##-m の場合 +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze + +import os +import os.path +import optparse +import sys + +import configreader +import recdblist +import auto_move +import guess +recordedpath=unicode(configreader.getConfPath("recorded"),'utf-8') +recpath=unicode(configreader.getConfPath("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("-m","--manual",action="store_true",dest="manual",default=False,help="manual classifying mode asking for y/n(not a test)") + #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.getMoveDestpath(ltitle,recpath,sf,".mkv")+".mkv"),verbose_level=100) + print "\n" + print "###MP4###" + recdblist.printutf8(os.path.join(sf, auto_move.getMoveDestpath(ltitle,recpath,sf,".mp4")+".mp4"),verbose_level=100) + print "\n" + elif opts.auto:##-A の場合 + sa=auto_move.searchFile(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.getMoveDestpath(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,200) + if sf!="": + recdblist.printutf8(u"移動先",verbose_level=100) + recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.getMoveDestpath(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.manual:##-m の場合 # mkv無視します - sa=auto_move.searchFile(recpath, recordedpath, ".mp4") - for t in sa: - sf=guess.searchFolder(t,recordedpath,200) - if sf!="": + sa=auto_move.searchFile(recpath, recordedpath, ".mp4") + for t in sa: + sf=guess.searchFolder(t,recordedpath,200) + if sf!="": recdblist.printutf8(u"○候補:"+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mp4")+".mp4"),verbose_level=100) ans = raw_input("移動しますか? (y/n/h)") if ans == 'y': - recdblist.printutf8(u"移動を実行します",verbose_level=100) + recdblist.printutf8(u"移動を実行します",verbose_level=100) auto_move.execMove(t, recpath, recordedpath,".mp4",1) - elif ans == 'n': - recdblist.printutf8(u"移動を中止します",verbose_level=100) - elif ans == 'h': - recdblist.printutf8(u"移動のヒント",verbose_level=100) - recdblist.printutf8(u"FIXME:not implemented",verbose_level=100) - else: - recdblist.printutf8(u"×不明:"+t,verbose_level=100) - elif opts.delete:##-Dの場合 - sa=auto_move.searchFile(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.searchFile(recpath, recordedpath,".mkv") - for t in sa: - sf=guess.searchFolder(t,recordedpath) - if sf!="": - recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.getMoveDestpath(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.getMoveDestpath(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.getConfPath("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.getMoveDestpath(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.getConfPath("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(u"移動先",verbose_level=100) - recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.getMoveDestpath(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.searchFile(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.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 updateLogo_bc(bctype): - bctypel = chdb.searchCHFromBctype(bctype) - #print bctype - try: - ts2epg.writeLogoEpgXML(tmppath + bctype + "logo.xml", chdb.searchCHFromBctype(bctype)['ch']) - xml2db_dom.xml2db_dom_logo(tmppath + bctype + "logo.xml", bctype) - shutil.copyfile(tmppath + bctype + "logo.xml", tmppath + bctype + "logo.bak.xml") - time.sleep(5) - rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"1") - 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 + "logo.bak.xml", bctype) - rec10d.rec10db.update_logostatus_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 +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 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 +if not os.path.exists(tmppath): + os.mkdir(tmppath) +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 updateLogo_bc(bctype): + bctypel = chdb.searchCHFromBctype(bctype) + #print bctype + try: + ts2epg.writeLogoEpgXML(tmppath + bctype + "logo.xml", chdb.searchCHFromBctype(bctype)['ch']) + xml2db_dom.xml2db_dom_logo(tmppath + bctype + "logo.xml", bctype) + shutil.copyfile(tmppath + bctype + "logo.xml", tmppath + bctype + "logo.bak.xml") + time.sleep(5) + rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"1") + 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 + "logo.bak.xml", bctype) + rec10d.rec10db.update_logostatus_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 17eefaa..f25f4f1 100644 --- a/rec10/trunk/src/install.py +++ b/rec10/trunk/src/install.py @@ -1,308 +1,308 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2011 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_installed_in_status(100) - recdblist.printutf8(u"おめでとうございます 初期設定は完了しました。",verbose_level=100) - recdblist.printutf8(u"rec10を実行するユーザーのcrontabに"+os.path.join(path,"rec10")+u"を追加してください(5分周期が目安)",verbose_level=100) - sys.exit(1) -def getLocalPath(cmd,exit=1): - printutf8(cmd+u"の場所を確認中") - txt=commands.getoutput(u"which "+cmd) - if len(txt.split(" "))>3: - if exit==1: - printutf8(cmd+u"の場所を確認できませんでした。終了します") - sys.exit(1) - else: - return "" - 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", getLocalPath(u"wine")) - configwriter.setTempConfPath(u"recpt1", getLocalPath(u"recpt1",exit=0)) - #configwriter.setpath(u"x264", getLocalPath(u"x264")) - configwriter.setTempConfPath(u"mp4box", getLocalPath(u"MP4Box",exit=0)) - configwriter.setTempConfPath(u"mencoder", getLocalPath(u"mencoder")) - configwriter.setTempConfPath(u"ffmpeg", getLocalPath(u"ffmpeg")) - configwriter.setTempConfPath(u"mkvmerge", getLocalPath(u"mkvmerge",exit=0)) - configwriter.setTempConfPath(u"lame", getLocalPath(u"lame",exit=0)) - configwriter.setTempConfPath(u"b25", getLocalPath(u"b25")) - configwriter.setTempConfPath(u"tee", getLocalPath(u"tee")) - configwriter.setTempConfPath(u"java", getLocalPath(u"java")) - - try: - configwriter.setTempConfPath(u"lame", getLocalPath(u"lame")) - except: - printutf8(u"lameが見つかりません(NeroAacEncを導入する場合は問題ありません)") - 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"BS/CSの設定に入ります") - printutf8(u"BS/CS(110度CS,スカパーe2)を受信しますか(4/"+str(maxn)+")") - useBSCS=raw_input("[Y/n]:") - if useBSCS=="N" or useBSCS=="n" or useBSCS=="no" or useBSCS=="NO": - useBSCS="0" - else: - useBSCS="1" - printutf8(u"ドライバの設定に入ります") - printutf8(u"DVB版のドライバを使用しますか(earth_pt1など。chardev版を使う場合はNo)(5/"+str(maxn)+")") - useDVB=raw_input("[y/N]:") - if useDVB=="Y" or useDVB=="y" or useDVB=="yes" or useDVB=="YES": - useDVB="1" - else: - useDVB="0" - configwriter.setTempConfDVB("useDVB", useDVB) - if useDVB=="1": - printutf8(u"DVBの設定に入ります") - printutf8(u"DVBAdapterの場所を設定して下さい") - printutf8(u"/dev/dvb/adapterなどdvr0の上のフォルダ(番号の前まで)を指定して下さい。") - getConf(useB,"/etc/rec10.conf","dvb","DVBadapter","/dev/dvb/adapter") - printutf8(u"地デジを受信可能なアダプタ番号を入力して下さい(1,3のように','で区切って下さい)") - getConf(useB,"/etc/rec10.conf","dvb","DVBTE","1,3") - if useBSCS=="1": - printutf8(u"BS/CSを受信可能なアダプタ番号を入力して下さい(0,2のように','で区切って下さい)") - getConf(useB,"/etc/rec10.conf","dvb","DVBBSCS","0,2") - else: - configwriter.setTempConfDVB("DVBBSCS","") - printutf8(u"同時録画可能数の設定に入ります") - printutf8(u"TE(地デジ)録画可能数(PT*だと2 白Friioだと1)(6/"+str(maxn)+")") - te_max=str(int(getConf(useB,"/etc/rec10.conf","env","te_max","te_max : "))) - configwriter.setTempConfEnv("te_max", te_max) - if useBSCS=="1": - printutf8(u"BS/CS110録画可能数(PT*だと2 黒Friioだと1)(7/"+str(maxn)+")") - bscs_max=str(int(getConf(useB,"/etc/rec10.conf","env","bscs_max","bscs_max : "))) - configwriter.setTempConfEnv("bscs_max", bscs_max) - else: - configwriter.setTempConfEnv("bscs_max", "0") - printutf8(u"同時エンコード最大数を設定してください(8/"+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 (9/"+str(maxn)+")") - audioenc=raw_input("[y/N]: ") - if audioenc=="y" or audioenc=="Y": - configwriter.setTempConfPath("useNeroAAC", "1") - aacpath=getLocalPath(u"neroAacEnc",exit=0) - if len(aacpath)<2: - 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") - aacpath="/usr/local/bin/neroAacEnc" - configwriter.setTempConfPath("NeroAAC",aacpath) - printutf8(u"lameを使用します。") - printutf8(u"x264のパスを指定してください(10/"+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.setTempConfPath("x264",x264path) - printutf8(u"保存する画質を教えてください(11/"+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"アニメーションを保存する画質を教えてください(12/"+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の圧縮率を設定してください(13/"+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"保存するコンテナの設定(14/"+str(maxn)+")") - printutf8(u"MP4を標準にしますか(もしくはMKVが使えます)") - useMP4=raw_input("[Y/n]:") - if useMP4=="N" or useMP4 == "n" : - useMP4="0" - else: - useMP4="1" - configwriter.setTempConfEnv("make_mp4", useMP4) - printutf8(u"TSファイルの自動削除(15/"+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"自機識別オプション(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() - elif version==100: - rec10d.rec10db.update_db_100to101() - elif version==101: - rec10d.rec10db.update_db_100to102() -if __name__ == "__main__": - move() +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 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_installed_in_status(100) + recdblist.printutf8(u"おめでとうございます 初期設定は完了しました。",verbose_level=100) + recdblist.printutf8(u"rec10を実行するユーザーのcrontabに"+os.path.join(path,"rec10")+u"を追加してください(5分周期が目安)",verbose_level=100) + sys.exit(1) +def getLocalPath(cmd,exit=1): + printutf8(cmd+u"の場所を確認中") + txt=commands.getoutput(u"which "+cmd) + if len(txt.split(" "))>3: + if exit==1: + printutf8(cmd+u"の場所を確認できませんでした。終了します") + sys.exit(1) + else: + return "" + 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", getLocalPath(u"wine")) + configwriter.setTempConfPath(u"recpt1", getLocalPath(u"recpt1",exit=0)) + #configwriter.setpath(u"x264", getLocalPath(u"x264")) + configwriter.setTempConfPath(u"mp4box", getLocalPath(u"MP4Box",exit=0)) + configwriter.setTempConfPath(u"mencoder", getLocalPath(u"mencoder")) + configwriter.setTempConfPath(u"ffmpeg", getLocalPath(u"ffmpeg")) + configwriter.setTempConfPath(u"mkvmerge", getLocalPath(u"mkvmerge",exit=0)) + configwriter.setTempConfPath(u"lame", getLocalPath(u"lame",exit=0)) + configwriter.setTempConfPath(u"b25", getLocalPath(u"b25")) + configwriter.setTempConfPath(u"tee", getLocalPath(u"tee")) + configwriter.setTempConfPath(u"java", getLocalPath(u"java")) + + try: + configwriter.setTempConfPath(u"lame", getLocalPath(u"lame")) + except: + printutf8(u"lameが見つかりません(NeroAacEncを導入する場合は問題ありません)") + 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"BS/CSの設定に入ります") + printutf8(u"BS/CS(110度CS,スカパーe2)を受信しますか(4/"+str(maxn)+")") + useBSCS=raw_input("[Y/n]:") + if useBSCS=="N" or useBSCS=="n" or useBSCS=="no" or useBSCS=="NO": + useBSCS="0" + else: + useBSCS="1" + printutf8(u"ドライバの設定に入ります") + printutf8(u"DVB版のドライバを使用しますか(earth_pt1など。chardev版を使う場合はNo)(5/"+str(maxn)+")") + useDVB=raw_input("[y/N]:") + if useDVB=="Y" or useDVB=="y" or useDVB=="yes" or useDVB=="YES": + useDVB="1" + else: + useDVB="0" + configwriter.setTempConfDVB("useDVB", useDVB) + if useDVB=="1": + printutf8(u"DVBの設定に入ります") + printutf8(u"DVBAdapterの場所を設定して下さい") + printutf8(u"/dev/dvb/adapterなどdvr0の上のフォルダ(番号の前まで)を指定して下さい。") + getConf(useB,"/etc/rec10.conf","dvb","DVBadapter","/dev/dvb/adapter") + printutf8(u"地デジを受信可能なアダプタ番号を入力して下さい(1,3のように','で区切って下さい)") + getConf(useB,"/etc/rec10.conf","dvb","DVBTE","1,3") + if useBSCS=="1": + printutf8(u"BS/CSを受信可能なアダプタ番号を入力して下さい(0,2のように','で区切って下さい)") + getConf(useB,"/etc/rec10.conf","dvb","DVBBSCS","0,2") + else: + configwriter.setTempConfDVB("DVBBSCS","") + printutf8(u"同時録画可能数の設定に入ります") + printutf8(u"TE(地デジ)録画可能数(PT*だと2 白Friioだと1)(6/"+str(maxn)+")") + te_max=str(int(getConf(useB,"/etc/rec10.conf","env","te_max","te_max : "))) + configwriter.setTempConfEnv("te_max", te_max) + if useBSCS=="1": + printutf8(u"BS/CS110録画可能数(PT*だと2 黒Friioだと1)(7/"+str(maxn)+")") + bscs_max=str(int(getConf(useB,"/etc/rec10.conf","env","bscs_max","bscs_max : "))) + configwriter.setTempConfEnv("bscs_max", bscs_max) + else: + configwriter.setTempConfEnv("bscs_max", "0") + printutf8(u"同時エンコード最大数を設定してください(8/"+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 (9/"+str(maxn)+")") + audioenc=raw_input("[y/N]: ") + if audioenc=="y" or audioenc=="Y": + configwriter.setTempConfPath("useNeroAAC", "1") + aacpath=getLocalPath(u"neroAacEnc",exit=0) + if len(aacpath)<2: + 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") + aacpath="/usr/local/bin/neroAacEnc" + configwriter.setTempConfPath("NeroAAC",aacpath) + printutf8(u"lameを使用します。") + printutf8(u"x264のパスを指定してください(10/"+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.setTempConfPath("x264",x264path) + printutf8(u"保存する画質を教えてください(11/"+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"アニメーションを保存する画質を教えてください(12/"+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の圧縮率を設定してください(13/"+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"保存するコンテナの設定(14/"+str(maxn)+")") + printutf8(u"MP4を標準にしますか(もしくはMKVが使えます)") + useMP4=raw_input("[Y/n]:") + if useMP4=="N" or useMP4 == "n" : + useMP4="0" + else: + useMP4="1" + configwriter.setTempConfEnv("make_mp4", useMP4) + printutf8(u"TSファイルの自動削除(15/"+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"自機識別オプション(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() + elif version==100: + rec10d.rec10db.update_db_100to101() + elif version==101: + rec10d.rec10db.update_db_100to102() +if __name__ == "__main__": + move() diff --git a/rec10/trunk/src/rec10d.py b/rec10/trunk/src/rec10d.py index b0ce3af..637ac1e 100644 --- a/rec10/trunk/src/rec10d.py +++ b/rec10/trunk/src/rec10d.py @@ -1,34 +1,34 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2011 Yukikaze -import os -import os.path -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__))) + "/" -tmppath = configreader.getConfPath("tmp")+"/" -if tmppath=="/": - tmppath=path -if not os.path.exists(tmppath): - os.makedirs(tmppath) -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() - +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import os +import os.path +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__))) + "/" +tmppath = configreader.getConfPath("tmp")+"/" +if tmppath=="/": + tmppath=path +if not os.path.exists(tmppath): + os.makedirs(tmppath) +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 b080755..8f3b41b 100644 --- a/rec10/trunk/src/recdb.py +++ b/rec10/trunk/src/recdb.py @@ -1,95 +1,95 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2011 Yukikaze -import chdb -import n_gram -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): - tcount=count - if tcount<0: - tcount=-1 - 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=tcount) -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=rec10d.rec10db.select_byepgtime_all_timeline(epgbtime,epgetime) - nel=rec10d.rec10db.select_bytime_all_timeline(epgbtime, epgetime) - dup=0 - for t in tl: - if t["title"]==title and t["chtxt"]==chtxt: - dup=1 - elif n_gram.trigram(t["title"],title)> 500 and t["chtxt"]==chtxt: - dup=1 - for t in nel: - if t["title"]==title and t["chtxt"]==chtxt: - dup=1 - elif n_gram.trigram(t["title"],title)> 500 and t["chtxt"]==chtxt: - dup=1 - return dup +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import chdb +import n_gram +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): + tcount=count + if tcount<0: + tcount=-1 + 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=tcount) +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=rec10d.rec10db.select_byepgtime_all_timeline(epgbtime,epgetime) + nel=rec10d.rec10db.select_bytime_all_timeline(epgbtime, epgetime) + dup=0 + for t in tl: + if t["title"]==title and t["chtxt"]==chtxt: + dup=1 + elif n_gram.trigram(t["title"],title)> 500 and t["chtxt"]==chtxt: + dup=1 + for t in nel: + if t["title"]==title and t["chtxt"]==chtxt: + dup=1 + elif n_gram.trigram(t["title"],title)> 500 and t["chtxt"]==chtxt: + dup=1 + return dup diff --git a/rec10/trunk/src/recdblist.py b/rec10/trunk/src/recdblist.py index 0626b50..8bb5edf 100644 --- a/rec10/trunk/src/recdblist.py +++ b/rec10/trunk/src/recdblist.py @@ -1,209 +1,209 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2011 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 = 102 -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 - -os.environ['LANG'] = "ja_JP.UTF-8" -my_env = os.environ -my_env['LANG'] = "ja_JP.UTF-8" - -def getEnv(): - return my_env -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 printutf8ex(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 printutf8_Important(unicode): - printutf8ex(unicode,100,100) -def printutf8_Normal(unicode): - printutf8ex(unicode,300,300) -def printutf8_Detailed(unicode): - printutf8ex(unicode,600,600) -def addCommonlogEX(type,place,inst,txt,verbose_level=500,log_level=500): - lt=unicode(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))+u":" - if txt=="": - lt=lt+u"["+type+u"] "+place+u" "+inst - else: - try: - lt=lt+u"["+type+u"] "+place+u" "+inst+u"\n"+txt - except: - print [type,place,inst,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 addCommandLogZip(tspath,log_title,log_filename_add,cmd,cmd_log=""): - logtitle=getLogTitle(tspath) - logo=logtitle+"."+log_filename_add+".log" - logzip=logtitle+".log.zip" - addLogAll(tspath,cmd+"\n\n"+cmd_log,log_title,logo) - import zip - zip.addFile2FileZip(logo,logzip) - os.remove(logo) -def addCommandSelfLog(tspath,command): - logpath=getLogTitle(tspath)+".command.log" - f="" - if os.path.exists(logpath): - f=open(logpath,'a') - else: - f=open(logpath,'w') - tc=command+u"\n\n" - tc=unicode(tc) - f.write(tc.encode("utf-8")) - #f.write(tc.encode('utf-8','ignore')) - f.close() -def getLogTitle(tspath): - 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(".264",".ts") - logo=logo.replace(".ts","") - return logo -def addLog(tspath,txt,log_title,maxtextlength=1500): - logo=getLogTitle(tspath)+".log" - f=open(logo,'a') - s=len(txt) - stxt="" - if s>maxtextlength*2 and maxtextlength>0: - stxt=txt[0:maxtextlength]+"\n\n(ry..)\n" - st=txt[s-maxtextlength:].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() -def addLogAll(tspath,txt,log_title,logpath): - logo=logpath - f=open(logo,'a') - 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-2011 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 = 102 +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 + +os.environ['LANG'] = "ja_JP.UTF-8" +my_env = os.environ +my_env['LANG'] = "ja_JP.UTF-8" + +def getEnv(): + return my_env +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 printutf8ex(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 printutf8_Important(unicode): + printutf8ex(unicode,100,100) +def printutf8_Normal(unicode): + printutf8ex(unicode,300,300) +def printutf8_Detailed(unicode): + printutf8ex(unicode,600,600) +def addCommonlogEX(type,place,inst,txt,verbose_level=500,log_level=500): + lt=unicode(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))+u":" + if txt=="": + lt=lt+u"["+type+u"] "+place+u" "+inst + else: + try: + lt=lt+u"["+type+u"] "+place+u" "+inst+u"\n"+txt + except: + print [type,place,inst,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 addCommandLogZip(tspath,log_title,log_filename_add,cmd,cmd_log=""): + logtitle=getLogTitle(tspath) + logo=logtitle+"."+log_filename_add+".log" + logzip=logtitle+".log.zip" + addLogAll(tspath,cmd+"\n\n"+cmd_log,log_title,logo) + import zip + zip.addFile2FileZip(logo,logzip) + os.remove(logo) +def addCommandSelfLog(tspath,command): + logpath=getLogTitle(tspath)+".command.log" + f="" + if os.path.exists(logpath): + f=open(logpath,'a') + else: + f=open(logpath,'w') + tc=command+u"\n\n" + tc=unicode(tc) + f.write(tc.encode("utf-8")) + #f.write(tc.encode('utf-8','ignore')) + f.close() +def getLogTitle(tspath): + 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(".264",".ts") + logo=logo.replace(".ts","") + return logo +def addLog(tspath,txt,log_title,maxtextlength=1500): + logo=getLogTitle(tspath)+".log" + f=open(logo,'a') + s=len(txt) + stxt="" + if s>maxtextlength*2 and maxtextlength>0: + stxt=txt[0:maxtextlength]+"\n\n(ry..)\n" + st=txt[s-maxtextlength:].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() +def addLogAll(tspath,txt,log_title,logpath): + logo=logpath + f=open(logo,'a') + 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 219756a..739a41e 100644 --- a/rec10/trunk/src/recque.py +++ b/rec10/trunk/src/recque.py @@ -1,80 +1,80 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2012 Yukikaze -import datetime -import os -import os.path -import glob -import time -import traceback - -import configreader -import recdblist -import recdb -tmppath = configreader.getConfPath("tmp")+"/" -if not os.path.exists(tmppath): - os.mkdir(tmppath) -def writeRecQue(parentpath,chtxt,title,opts): - outputpath=os.path.join(parentpath,title+".recq") - tmpoppath=os.path.join(tmppath,title+".recq") - f=open(outputpath,"w") - optt=opts - 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() - if not os.path.exists(outputpath): - if os.path.exists(tmpoppath): - os.remove(tmpoppath) - f2=open(tmpoppath,"w") - f2.write(str.encode('utf-8')) - f2.close() - try: - os.chmod(tmpoppath) - except: - "" - shutil.copy(tmpoppath,outputpath) - os.remove(tmpoppath) -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("R")>-1: - dbkey=recdblist.REC_TS_DECODE_QUE - opts=opts.replace("R","") - elif opts.find("D")>-1: - dbkey=recdblist.REC_ENCODE_QUE - opts=opts.replace("D","") - elif opts.find("E")>-1: - dbkey="" - opts=opts.replace("E","") - - 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) - +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2012 Yukikaze +import datetime +import os +import os.path +import glob +import time +import traceback + +import configreader +import recdblist +import recdb +tmppath = configreader.getConfPath("tmp")+"/" +if not os.path.exists(tmppath): + os.mkdir(tmppath) +def writeRecQue(parentpath,chtxt,title,opts): + outputpath=os.path.join(parentpath,title+".recq") + tmpoppath=os.path.join(tmppath,title+".recq") + f=open(outputpath,"w") + optt=opts + 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() + if not os.path.exists(outputpath): + if os.path.exists(tmpoppath): + os.remove(tmpoppath) + f2=open(tmpoppath,"w") + f2.write(str.encode('utf-8')) + f2.close() + try: + os.chmod(tmpoppath) + except: + "" + shutil.copy(tmpoppath,outputpath) + os.remove(tmpoppath) +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("R")>-1: + dbkey=recdblist.REC_TS_DECODE_QUE + opts=opts.replace("R","") + elif opts.find("D")>-1: + dbkey=recdblist.REC_ENCODE_QUE + opts=opts.replace("D","") + elif opts.find("E")>-1: + dbkey="" + opts=opts.replace("E","") + + 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/status.py b/rec10/trunk/src/status.py index 09383e8..9353900 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-2011 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"))] +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 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/ts2epg.py b/rec10/trunk/src/ts2epg.py index 00d18ea..ac01b9b 100644 --- a/rec10/trunk/src/ts2epg.py +++ b/rec10/trunk/src/ts2epg.py @@ -1,67 +1,67 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2011 Yukikaze -#import sys # モジュール属性 argv を取得するため -import os -import re -import time -import commands - -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 writeLogoEpgXML(pout, ch): - """ - tsを取得してepgの入ったxmlとして書き出す - """ - timet = "600" - if re.search(u'CS', ch): - timet = "10" - elif len(ch)>2: - timet = "1200" - writeEpgXMLTime(pout, ch ,timet,islogo=1) -def writeEpgXMLTime(pout, ch ,times,islogo=0): - """ - 指定された時間分tsを取得してepgの入ったxmlとして書き出す - """ - if islogo==0: - recdblist.addCommonlogEX(u"通常","write_time(ts2epg.py)",u"Ts-EPG XML書き出し処理開始" ,u"CH:"+ch,log_level=500) - elif islogo==1: - recdblist.addCommonlogEX(u"通常","write_time(ts2epg.py)",u"Ts-EPG LOGO : 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.searchCHFromBctype(u'te' + ch)['ch']) - epgdump = configreader.getConfPath("epgdump") - if os.access(pout + ".ts", os.F_OK): - os.remove(pout + ".ts") - time.sleep(10) - tv2ts.tv2b25ts(pout+ ".ts", ch, times,"0") - logoopt="" - if islogo==1: - logoopt="/LOGO " - os.chmod(pout+".ts",0755) - exe = "export LANG=ja_JP.UTF-8 && nice -n 15 " + epgdump + " " +logoopt+ mode + " " + pout + ".ts " + pout - recdblist.printutf8(exe) - recdblist.addCommonlogEX(u"通常", "write_time(ts2epg.py) "+str(ch), exe,"",log_level=500) - unicode(commands.getoutput(exe),'utf-8','ignore') - time.sleep(10) - if os.path.exists(pout+".ts"): - os.remove(pout+ ".ts") - +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +#import sys # モジュール属性 argv を取得するため +import os +import re +import time +import commands + +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 writeLogoEpgXML(pout, ch): + """ + tsを取得してepgの入ったxmlとして書き出す + """ + timet = "600" + if re.search(u'CS', ch): + timet = "10" + elif len(ch)>2: + timet = "1200" + writeEpgXMLTime(pout, ch ,timet,islogo=1) +def writeEpgXMLTime(pout, ch ,times,islogo=0): + """ + 指定された時間分tsを取得してepgの入ったxmlとして書き出す + """ + if islogo==0: + recdblist.addCommonlogEX(u"通常","write_time(ts2epg.py)",u"Ts-EPG XML書き出し処理開始" ,u"CH:"+ch,log_level=500) + elif islogo==1: + recdblist.addCommonlogEX(u"通常","write_time(ts2epg.py)",u"Ts-EPG LOGO : 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.searchCHFromBctype(u'te' + ch)['ch']) + epgdump = configreader.getConfPath("epgdump") + if os.access(pout + ".ts", os.F_OK): + os.remove(pout + ".ts") + time.sleep(10) + tv2ts.tv2b25ts(pout+ ".ts", ch, times,"0") + logoopt="" + if islogo==1: + logoopt="/LOGO " + os.chmod(pout+".ts",0755) + exe = "export LANG=ja_JP.UTF-8 && nice -n 15 " + epgdump + " " +logoopt+ mode + " " + pout + ".ts " + pout + recdblist.printutf8(exe) + recdblist.addCommonlogEX(u"通常", "write_time(ts2epg.py) "+str(ch), exe,"",log_level=500) + unicode(commands.getoutput(exe),'utf-8','ignore') + time.sleep(10) + if os.path.exists(pout+".ts"): + os.remove(pout+ ".ts") + diff --git a/rec10/trunk/src/ts2x264.py b/rec10/trunk/src/ts2x264.py index e836b9c..d47e9aa 100644 --- a/rec10/trunk/src/ts2x264.py +++ b/rec10/trunk/src/ts2x264.py @@ -1,556 +1,556 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2011 Yukikaze -import commands -import configreader -import os -import os.path -import sys -import re -import random -import time -import traceback -import zip - -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 - bluray=0 - sar=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("MW1",opts): - size = "QVGA_BASE" - crf=crf+4 - sar=0 - if re.search("MW2", opts): - size = "WVGA_BASE" - crf=crf+2 - sar=0 - 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("B", opts): - bluray=1 - sar=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=deinterlace,usebluray=bluray,usesar=sar) - elif re.search("5",opts):#5.1chの場合 - encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar) - elif re.search("b",opts):#BonTsDemuxを使いたい場合 - tm2v=pin.replace(".ts",".m2v") - encodeFfmpegSar(tm2v,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar) - else: - try: - encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=1,usebluray=bluray,usesar=sar) - if os.path.exists(pout): - if not os.path.getsize(pout)>1*1000: - recdblist.addCommonlogEX("Warning", "Old mencoder option used.","","",log_level=200) - try: - encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=0,usebluray=bluray,usesar=sar) - except Exception, inst: - recdblist.addCommonlogEX("Error", "ts2x264_mencoder_old(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) - else: - recdblist.addCommonlogEX("Warning", "Old mencoder option used.","","",log_level=200) - try: - encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=0,usebluray=bluray,usesar=sar) - except Exception, inst: - recdblist.addCommonlogEX("Error", "ts2x264_mencoder_old(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) - except Exception, inst: - recdblist.addCommonlogEX("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,uselavf=0,usebluray=0,usesar=1): - mencoder=configreader.getConfPath("mencoder") - tee=configreader.getConfPath("tee") - 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 --keyint 30" - x264streamsize="" - x264preset="" - x264tune="" - x264_bitrate="5000" - x264interlaced=0 - x264sar="1:1" - tsar=getMoviePAR2(pin) - if usesar==1: - x264sar=str(tsar[0])+u":"+str(tsar[1]) - lavft="" - if is24fps==1: - ofps="-ofps 24000/1001" - fps="-fps 30000/1001" - x264fps="24000/1001 --keyint 24" - 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) - if usesar==1: - encvf = encvf + ",scale=-3:720::0:3"+harddup - x264streamsize=str(tsize[0])+u"x720" - else: - encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup - x264streamsize=u"1280x720" - x264_bitrate="2500" - elif size == "WVGA": - tsize=getParSize(pin,480) - if usesar==1: - encvf = encvf + ",scale=-3:480::0:3"+harddup - x264streamsize=str(tsize[0])+u"x480" - else: - encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup - x264streamsize=u"854x480" - x264_bitrate="1500" - elif size == "FullHD": - tsize=getParSize(pin,1080) - if usesar==1: - encvf = encvf + ",scale=-3:1080::0:3"+harddup - x264streamsize=str(tsize[0])+u"x1080" - else: - encvf = encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup - x264streamsize=u"1920x1080" - x264_bitrate="5000" - elif size == "QVGA_BASE": - tsize=getParSize(pin,240) - if usesar==1: - encvf = encvf + ",scale=-3:240::0:3"+harddup - x264streamsize=str(tsize[0])+u"x240" - else: - encvf = encvf + ",scale=320:-2::0:3,expand=320:240"+harddup - x264streamsize=u"320x240" - x264_bitrate="300" - elif size == "WVGA_BASE": - tsize=getParSize(pin,480) - if usesar==1: - encvf = encvf + ",scale=-3:480::0:3"+harddup - x264streamsize=str(tsize[0])+u"x480" - else: - encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup - x264streamsize=u"854x480" - x264_bitrate="1500" - else: - tsize=getParSize(pin,720) - if usesar==1: - encvf = encvf + ",scale=-3:720::0:3"+harddup - x264streamsize=str(tsize[0])+u"x720" - else: - encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup - x264streamsize=u"1280x720" - x264_bitrate="2500" - if deinterlace==0: - tsize=getMovieBaseSize2(pin) - ofps="-ofps 30000/1001" - #fps="-fps 30000/1001" - fps="" - x264fps="30000/1001 --keyint 30" - x264interlaced=1 - encvf="-vf hqdn3d=2:1:2" - harddup=",harddup" - encvf=encvf+harddup - x264streamsize=str(tsize[0])+u"x"+str(tsize[1]) - if usebluray==1: - encvf = u"-sws 9 "+encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup - x264streamsize=u"1920x1080" - 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 --keyint 30" - 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" - else: - x264preset=u"medium" - if size == "WVGA_BASE" or size == "QVGA_BASE": - x264profile=" --level 32 --profile baseline " - else: - x264profile=" --level 41 --profile high " - if uselavf==1: - lavft="-demuxer lavf " - 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))) - unicode(commands.getoutput(u"mkfifo "+streampath),'utf-8','ignore') - logmencoder=recdblist.getLogTitle(pin)+".mencoder.log" - logx264=recdblist.getLogTitle(pin)+".x264.log" - encexe=mencoder+u" \""+pin+u"\" -quiet -vfm ffmpeg "+lavft+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" 2>&1 | "+tee+" \""+logmencoder+"\" & " - encexe=encexe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout, streampath, x264streamsize, crf=x264crf,interlaced=x264interlaced,bluray=usebluray) - #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+" 2>&1 | "+tee+" \""+logx264+"\"" - try: - recdblist.addCommandSelfLog(pin, encexe) - except Exception, inst: - print type(inst) - print str(inst) - print traceback.print_exc(file=sys.stdout) - recdblist.printutf8(encexe) - txt="" - try: - txt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8','ignore') - except: - "" - os.remove(streampath) - zip.addFile2FileZip(logmencoder, recdblist.getLogTitle(pin)+".log.zip") - zip.addFile2FileZip(logx264, recdblist.getLogTitle(pin)+".log.zip") - os.remove(logmencoder) - os.remove(logx264) - recdblist.addCommandLog(pin, u"Mencoder", encexe, txt) -# recdblist.addCommandLogTar(pin,u"Mencoder","mencoder", encexe,txt) -def encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=1,usebluray=0,usesar=1): - """ - - """ - ffmpeg=configreader.getConfPath("ffmpeg") - tee=configreader.getConfPath("tee") - fps=u"-r 29.970030 " - x264fps="30000/1001 --keyint 30" - x264streamsize="" - x264preset="" - x264tune="" - x264_bitrate="2500" - x264_thread="auto" - x264interlaced=0 - tsar=getMoviePAR2(pin) - filter="-deinterlace" - x264sar=str(tsar[0])+":"+str(tsar[1]) - if is24fps==1: - fps=u"-r 23.976023 " - x264fps="24000/1001 --keyint 24" - x264tune="--tune animation" - 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 --keyint 30" - x264interlaced=1 - 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" - else: - x264preset=u"medium" - 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" - log_ffmpeg=recdblist.getLogTitle(pin)+".ffmpeg.log" - log_x264=recdblist.getLogTitle(pin)+".x264.log" - exe=ffmpeg+u" -y -i \""+pin+"\" -vcodec rawvideo -pix_fmt yuv420p "+s+fps+" "+filter+" -an -f rawvideo - 2> \""+log_ffmpeg+"\" | " - exe=exe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout,"-", x264streamsize, crf=x264crf,interlaced=x264interlaced,bluray=usebluray) - exe = "nice -n 19 " + exe+" 2>&1 | "+tee+" \""+log_x264+"\"" - txt="" - #recdblist.addCommandSelfLog(log_ffmpeg,recdblist.getLogTitle(pin)+".log.zip") - #recdblist.addCommandSelfLog(log_x264,recdblist.getLogTitle(pin)+".log.zip") - recdblist.printutf8(exe) - recdblist.addCommandSelfLog(pin,exe) - try: - txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') - except: - "" - recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt) - zip.addFile2FileZip(log_ffmpeg, recdblist.getLogTitle(pin+".log.zip")) - zip.addFile2FileZip(log_x264, recdblist.getLogTitle(pin+".log.zip")) - os.remove(log_ffmpeg) - os.remove(log_x264) -def getMovieBaseSize2(pin):##動画開始後すぐに解像度が変更されたときに対処 - ffmpeg=configreader.getConfPath("ffmpeg") - os.environ['LANG']="ja_JP.UTF-8" - exe=ffmpeg+u" -ss 5 -fs 1 -t 10 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1" - try: - recdblist.addCommandSelfLog(pin, exe) - except Exception, inst: - print type(inst) - print str(inst) - print traceback.print_exc(file=sys.stdout) - 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") - rT2=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+SAR\D+(\d+:\d+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z") - sizeMaxX=0 - sizeMaxY=0 - txtls=txts.split("\n") - for t in txtls: - rM=rT.search(t) - rM2=rT2.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" - try: - recdblist.addCommandSelfLog(pin, exe) - except Exception, inst: - print type(inst) - print str(inst) - print traceback.print_exc(file=sys.stdout) - 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") - rT2 = re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+SAR\D+(\d+:\d+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z") - sizeMaxX = 0 - parx = 0 - pary = 0 - txtls = txts.split("\n") - for t in txtls: - rM = rT.match(t) - rM2 = rT2.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 < tX: - sizeMaxX = tX - if tX == 1920 and tY == 1080: - parx = 1 - pary = 1 - else: - parx = tEX - pary = tEY - rM = rT.match(t) - if rM2: - sizetxt = rM2.group(1) - sartxt = rM2.group(2) - dartxt = rM2.group(3) - tX = int(sizetxt.split("x")[0]) - tY = int(sizetxt.split("x")[1]) - tEX = int(dartxt.split(":")[0]) - tEY = int(dartxt.split(":")[1])##dar=sarxpar - tSX = int(sartxt.split(":")[0]) - tSY = int(sartxt.split(":")[1])##par=dar/sar= darx*pary*sary=dary*parx*sarx - if sizeMaxX < tX: - sizeMaxX = tX - if tX == 1920 and tY == 1080: - parx = 1 - pary = 1 - else: - if tEX * tSY == tEY * tSX: - parx = 1 - pary = 1 - elif tEX * tSY * 3 == tEY * tSX * 4: - parx = 4 - pary = 3 - elif tEX * tSY * 4 == tEY * tSX * 3: - parx = 3 - pary = 4 - elif tEX * tSY * 9 == tEY * tSX * 16: - parx = 16 - pary = 9 - elif tEX * tSY * 16 == tEY * tSX * 9: - parx = 9 - pary = 16 - os.remove(pin+".size.ts") - return [parx,pary] -def getParSize(pin,y): - tSize=getMovieBaseSize2(pin) - if tSize[1] != 0 : - tX=tSize[0]*10*y/tSize[1] - tY=y - if tX>int(tX/10)*10: - tX=tX/10+1 - else: - tX=tX/10 - else: - tX=-1 - tY=-1 - return [tX,tY] -def getX264CoreVersion(): - x264=configreader.getConfPath("x264") - #print x264 - t1=commands.getoutput(x264+" --help|grep core") - #print t1 - 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,interlaced=0,bluray=0): - x264=configreader.getConfPath("x264") - os.environ['LANG']="ja_JP.UTF-8" - x264_sar="--sar "+sar - x264preset=u"--preset "+preset - x264fps="--fps "+fps - x264interlaced="" - x264bluray="" - x264_addline=configreader.getConfEnv("x264_addline") - if crf==-1: - x264bitrate=u"--bitrate "+str(bitrate) - else: - x264crf=u"--crf "+str(crf) - if interlaced==1: - x264interlaced="--tff --nal-hrd vbr" - if bluray==1: - if getX264CoreVersion()<115: - x264bluray=" --weightp 1 --nal-hrd vbr --bframes 3 --b-pyramid none --open-gop bluray --slices 4 --aud --colorprim bt709 --transfer bt709 " - x264_addline="" - if fps=="24000/1001 --keyint 24" or fps =="24000/1001": - if x264streamsize=="1280x720": - x264bluray=u"--ref 6 "+x264bluray - if x264streamsize=="1920x1080": - x264bluray=u"--ref 4 "+x264bluray - elif fps=="30000/1001 --keyint 30" or fps =="30000/1001": - if x264streamsize=="1280x720": - x264bluray=u"--ref 6 --pulldown double "+x264bluray - if x264streamsize=="1920x1080": - if interlaced==0: - x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray - else: - x264bluray=u"--ref 4 "+x264bluray - elif getX264CoreVersion()>=115: - x264bluray=" --slices 4 --bluray-compat --nal-hrd vbr --bframes 3 --b-pyramid strict --aud --colorprim bt709 --transfer bt709 " - x264_addline="" - if fps=="24000/1001 --keyint 24" or fps =="24000/1001": - if x264streamsize=="1280x720": - x264bluray=u"--ref 6 "+x264bluray - if x264streamsize=="1920x1080": - x264bluray=u"--ref 4 "+x264bluray - elif fps=="30000/1001 --keyint 30" or fps =="30000/1001": - if x264streamsize=="1280x720": - x264bluray=u"--ref 6 --pulldown double "+x264bluray - if x264streamsize=="1920x1080": - if interlaced==0: - x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray - else: - x264bluray=u"--ref 4 "+x264bluray - 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 getX264CoreVersion()>103: - x264res=u"--input-res "+x264streamsize - exe=u"nice -n 19 "+x264+" --demuxer raw --vbv-maxrate 30000 --vbv-bufsize 25000 "+x264_sar+" "+x264crf+u" "+x264bluray+u" "+x264interlaced+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" "+x264res+" -o \""+pout+"\" "+pin - else: - exe=u"nice -n 19 "+x264+" --demuxer raw --vbv-maxrate 30000 --vbv-bufsize 25000 "+x264_sar+" "+x264crf+u" "+x264bluray+u" "+x264interlaced+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+pin+" "+x264streamsize - return exe +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import commands +import configreader +import os +import os.path +import sys +import re +import random +import time +import traceback +import zip + +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 + bluray=0 + sar=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("MW1",opts): + size = "QVGA_BASE" + crf=crf+4 + sar=0 + if re.search("MW2", opts): + size = "WVGA_BASE" + crf=crf+2 + sar=0 + 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("B", opts): + bluray=1 + sar=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=deinterlace,usebluray=bluray,usesar=sar) + elif re.search("5",opts):#5.1chの場合 + encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar) + elif re.search("b",opts):#BonTsDemuxを使いたい場合 + tm2v=pin.replace(".ts",".m2v") + encodeFfmpegSar(tm2v,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar) + else: + try: + encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=1,usebluray=bluray,usesar=sar) + if os.path.exists(pout): + if not os.path.getsize(pout)>1*1000: + recdblist.addCommonlogEX("Warning", "Old mencoder option used.","","",log_level=200) + try: + encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=0,usebluray=bluray,usesar=sar) + except Exception, inst: + recdblist.addCommonlogEX("Error", "ts2x264_mencoder_old(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) + else: + recdblist.addCommonlogEX("Warning", "Old mencoder option used.","","",log_level=200) + try: + encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=0,usebluray=bluray,usesar=sar) + except Exception, inst: + recdblist.addCommonlogEX("Error", "ts2x264_mencoder_old(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200) + except Exception, inst: + recdblist.addCommonlogEX("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,uselavf=0,usebluray=0,usesar=1): + mencoder=configreader.getConfPath("mencoder") + tee=configreader.getConfPath("tee") + 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 --keyint 30" + x264streamsize="" + x264preset="" + x264tune="" + x264_bitrate="5000" + x264interlaced=0 + x264sar="1:1" + tsar=getMoviePAR2(pin) + if usesar==1: + x264sar=str(tsar[0])+u":"+str(tsar[1]) + lavft="" + if is24fps==1: + ofps="-ofps 24000/1001" + fps="-fps 30000/1001" + x264fps="24000/1001 --keyint 24" + 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) + if usesar==1: + encvf = encvf + ",scale=-3:720::0:3"+harddup + x264streamsize=str(tsize[0])+u"x720" + else: + encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup + x264streamsize=u"1280x720" + x264_bitrate="2500" + elif size == "WVGA": + tsize=getParSize(pin,480) + if usesar==1: + encvf = encvf + ",scale=-3:480::0:3"+harddup + x264streamsize=str(tsize[0])+u"x480" + else: + encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup + x264streamsize=u"854x480" + x264_bitrate="1500" + elif size == "FullHD": + tsize=getParSize(pin,1080) + if usesar==1: + encvf = encvf + ",scale=-3:1080::0:3"+harddup + x264streamsize=str(tsize[0])+u"x1080" + else: + encvf = encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup + x264streamsize=u"1920x1080" + x264_bitrate="5000" + elif size == "QVGA_BASE": + tsize=getParSize(pin,240) + if usesar==1: + encvf = encvf + ",scale=-3:240::0:3"+harddup + x264streamsize=str(tsize[0])+u"x240" + else: + encvf = encvf + ",scale=320:-2::0:3,expand=320:240"+harddup + x264streamsize=u"320x240" + x264_bitrate="300" + elif size == "WVGA_BASE": + tsize=getParSize(pin,480) + if usesar==1: + encvf = encvf + ",scale=-3:480::0:3"+harddup + x264streamsize=str(tsize[0])+u"x480" + else: + encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup + x264streamsize=u"854x480" + x264_bitrate="1500" + else: + tsize=getParSize(pin,720) + if usesar==1: + encvf = encvf + ",scale=-3:720::0:3"+harddup + x264streamsize=str(tsize[0])+u"x720" + else: + encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup + x264streamsize=u"1280x720" + x264_bitrate="2500" + if deinterlace==0: + tsize=getMovieBaseSize2(pin) + ofps="-ofps 30000/1001" + #fps="-fps 30000/1001" + fps="" + x264fps="30000/1001 --keyint 30" + x264interlaced=1 + encvf="-vf hqdn3d=2:1:2" + harddup=",harddup" + encvf=encvf+harddup + x264streamsize=str(tsize[0])+u"x"+str(tsize[1]) + if usebluray==1: + encvf = u"-sws 9 "+encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup + x264streamsize=u"1920x1080" + 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 --keyint 30" + 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" + else: + x264preset=u"medium" + if size == "WVGA_BASE" or size == "QVGA_BASE": + x264profile=" --level 32 --profile baseline " + else: + x264profile=" --level 41 --profile high " + if uselavf==1: + lavft="-demuxer lavf " + 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))) + unicode(commands.getoutput(u"mkfifo "+streampath),'utf-8','ignore') + logmencoder=recdblist.getLogTitle(pin)+".mencoder.log" + logx264=recdblist.getLogTitle(pin)+".x264.log" + encexe=mencoder+u" \""+pin+u"\" -quiet -vfm ffmpeg "+lavft+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" 2>&1 | "+tee+" \""+logmencoder+"\" & " + encexe=encexe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout, streampath, x264streamsize, crf=x264crf,interlaced=x264interlaced,bluray=usebluray) + #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+" 2>&1 | "+tee+" \""+logx264+"\"" + try: + recdblist.addCommandSelfLog(pin, encexe) + except Exception, inst: + print type(inst) + print str(inst) + print traceback.print_exc(file=sys.stdout) + recdblist.printutf8(encexe) + txt="" + try: + txt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8','ignore') + except: + "" + os.remove(streampath) + zip.addFile2FileZip(logmencoder, recdblist.getLogTitle(pin)+".log.zip") + zip.addFile2FileZip(logx264, recdblist.getLogTitle(pin)+".log.zip") + os.remove(logmencoder) + os.remove(logx264) + recdblist.addCommandLog(pin, u"Mencoder", encexe, txt) +# recdblist.addCommandLogTar(pin,u"Mencoder","mencoder", encexe,txt) +def encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=1,usebluray=0,usesar=1): + """ + + """ + ffmpeg=configreader.getConfPath("ffmpeg") + tee=configreader.getConfPath("tee") + fps=u"-r 29.970030 " + x264fps="30000/1001 --keyint 30" + x264streamsize="" + x264preset="" + x264tune="" + x264_bitrate="2500" + x264_thread="auto" + x264interlaced=0 + tsar=getMoviePAR2(pin) + filter="-deinterlace" + x264sar=str(tsar[0])+":"+str(tsar[1]) + if is24fps==1: + fps=u"-r 23.976023 " + x264fps="24000/1001 --keyint 24" + x264tune="--tune animation" + 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 --keyint 30" + x264interlaced=1 + 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" + else: + x264preset=u"medium" + 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" + log_ffmpeg=recdblist.getLogTitle(pin)+".ffmpeg.log" + log_x264=recdblist.getLogTitle(pin)+".x264.log" + exe=ffmpeg+u" -y -i \""+pin+"\" -vcodec rawvideo -pix_fmt yuv420p "+s+fps+" "+filter+" -an -f rawvideo - 2> \""+log_ffmpeg+"\" | " + exe=exe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout,"-", x264streamsize, crf=x264crf,interlaced=x264interlaced,bluray=usebluray) + exe = "nice -n 19 " + exe+" 2>&1 | "+tee+" \""+log_x264+"\"" + txt="" + #recdblist.addCommandSelfLog(log_ffmpeg,recdblist.getLogTitle(pin)+".log.zip") + #recdblist.addCommandSelfLog(log_x264,recdblist.getLogTitle(pin)+".log.zip") + recdblist.printutf8(exe) + recdblist.addCommandSelfLog(pin,exe) + try: + txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore') + except: + "" + recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt) + zip.addFile2FileZip(log_ffmpeg, recdblist.getLogTitle(pin+".log.zip")) + zip.addFile2FileZip(log_x264, recdblist.getLogTitle(pin+".log.zip")) + os.remove(log_ffmpeg) + os.remove(log_x264) +def getMovieBaseSize2(pin):##動画開始後すぐに解像度が変更されたときに対処 + ffmpeg=configreader.getConfPath("ffmpeg") + os.environ['LANG']="ja_JP.UTF-8" + exe=ffmpeg+u" -ss 5 -fs 1 -t 10 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1" + try: + recdblist.addCommandSelfLog(pin, exe) + except Exception, inst: + print type(inst) + print str(inst) + print traceback.print_exc(file=sys.stdout) + 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") + rT2=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+SAR\D+(\d+:\d+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z") + sizeMaxX=0 + sizeMaxY=0 + txtls=txts.split("\n") + for t in txtls: + rM=rT.search(t) + rM2=rT2.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" + try: + recdblist.addCommandSelfLog(pin, exe) + except Exception, inst: + print type(inst) + print str(inst) + print traceback.print_exc(file=sys.stdout) + 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") + rT2 = re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+SAR\D+(\d+:\d+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z") + sizeMaxX = 0 + parx = 0 + pary = 0 + txtls = txts.split("\n") + for t in txtls: + rM = rT.match(t) + rM2 = rT2.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 < tX: + sizeMaxX = tX + if tX == 1920 and tY == 1080: + parx = 1 + pary = 1 + else: + parx = tEX + pary = tEY + rM = rT.match(t) + if rM2: + sizetxt = rM2.group(1) + sartxt = rM2.group(2) + dartxt = rM2.group(3) + tX = int(sizetxt.split("x")[0]) + tY = int(sizetxt.split("x")[1]) + tEX = int(dartxt.split(":")[0]) + tEY = int(dartxt.split(":")[1])##dar=sarxpar + tSX = int(sartxt.split(":")[0]) + tSY = int(sartxt.split(":")[1])##par=dar/sar= darx*pary*sary=dary*parx*sarx + if sizeMaxX < tX: + sizeMaxX = tX + if tX == 1920 and tY == 1080: + parx = 1 + pary = 1 + else: + if tEX * tSY == tEY * tSX: + parx = 1 + pary = 1 + elif tEX * tSY * 3 == tEY * tSX * 4: + parx = 4 + pary = 3 + elif tEX * tSY * 4 == tEY * tSX * 3: + parx = 3 + pary = 4 + elif tEX * tSY * 9 == tEY * tSX * 16: + parx = 16 + pary = 9 + elif tEX * tSY * 16 == tEY * tSX * 9: + parx = 9 + pary = 16 + os.remove(pin+".size.ts") + return [parx,pary] +def getParSize(pin,y): + tSize=getMovieBaseSize2(pin) + if tSize[1] != 0 : + tX=tSize[0]*10*y/tSize[1] + tY=y + if tX>int(tX/10)*10: + tX=tX/10+1 + else: + tX=tX/10 + else: + tX=-1 + tY=-1 + return [tX,tY] +def getX264CoreVersion(): + x264=configreader.getConfPath("x264") + #print x264 + t1=commands.getoutput(x264+" --help|grep core") + #print t1 + 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,interlaced=0,bluray=0): + x264=configreader.getConfPath("x264") + os.environ['LANG']="ja_JP.UTF-8" + x264_sar="--sar "+sar + x264preset=u"--preset "+preset + x264fps="--fps "+fps + x264interlaced="" + x264bluray="" + x264_addline=configreader.getConfEnv("x264_addline") + if crf==-1: + x264bitrate=u"--bitrate "+str(bitrate) + else: + x264crf=u"--crf "+str(crf) + if interlaced==1: + x264interlaced="--tff --nal-hrd vbr" + if bluray==1: + if getX264CoreVersion()<115: + x264bluray=" --weightp 1 --nal-hrd vbr --bframes 3 --b-pyramid none --open-gop bluray --slices 4 --aud --colorprim bt709 --transfer bt709 " + x264_addline="" + if fps=="24000/1001 --keyint 24" or fps =="24000/1001": + if x264streamsize=="1280x720": + x264bluray=u"--ref 6 "+x264bluray + if x264streamsize=="1920x1080": + x264bluray=u"--ref 4 "+x264bluray + elif fps=="30000/1001 --keyint 30" or fps =="30000/1001": + if x264streamsize=="1280x720": + x264bluray=u"--ref 6 --pulldown double "+x264bluray + if x264streamsize=="1920x1080": + if interlaced==0: + x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray + else: + x264bluray=u"--ref 4 "+x264bluray + elif getX264CoreVersion()>=115: + x264bluray=" --slices 4 --bluray-compat --nal-hrd vbr --bframes 3 --b-pyramid strict --aud --colorprim bt709 --transfer bt709 " + x264_addline="" + if fps=="24000/1001 --keyint 24" or fps =="24000/1001": + if x264streamsize=="1280x720": + x264bluray=u"--ref 6 "+x264bluray + if x264streamsize=="1920x1080": + x264bluray=u"--ref 4 "+x264bluray + elif fps=="30000/1001 --keyint 30" or fps =="30000/1001": + if x264streamsize=="1280x720": + x264bluray=u"--ref 6 --pulldown double "+x264bluray + if x264streamsize=="1920x1080": + if interlaced==0: + x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray + else: + x264bluray=u"--ref 4 "+x264bluray + 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 getX264CoreVersion()>103: + x264res=u"--input-res "+x264streamsize + exe=u"nice -n 19 "+x264+" --demuxer raw --vbv-maxrate 30000 --vbv-bufsize 25000 "+x264_sar+" "+x264crf+u" "+x264bluray+u" "+x264interlaced+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" "+x264res+" -o \""+pout+"\" "+pin + else: + exe=u"nice -n 19 "+x264+" --demuxer raw --vbv-maxrate 30000 --vbv-bufsize 25000 "+x264_sar+" "+x264crf+u" "+x264bluray+u" "+x264interlaced+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 e0b859a..a554451 100644 --- a/rec10/trunk/src/tv2audio.py +++ b/rec10/trunk/src/tv2audio.py @@ -1,286 +1,286 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2011 Yukikaze - -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=configreader.getConfPath('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.getConfPath("ffmpeg") - e0=ffmpeg+" -i \""+pts+"\" -y -vn -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.getConfPath('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) - txt=commands.getoutput(exe.encode('utf-8')) - recdblist.addCommandLog(pts, u"BonTsDemux 音声取り出し", exe, txt) -def ts2single_mp3_ffmpeg(pts): - pmp3=pts.replace(".ts",".mp3") - ffmpeg=configreader.getConfPath("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_aac_ffmpeg(pts): - ts2singlewav(pts,opts) - aout=pts.replace(".ts",".aac") - ain=pts.replace(".ts",".wav") - wav2aac_ffmpeg(ain,aout) -def wav2aac_ffmpeg(pin,pout): - paac=pts.replace(".ts",".aac") - ffmpeg=configreader.getConfPath("ffmpeg") - e0=ffmpeg+" -i \""+pin+"\" -y \""+pout+"\"" - p0=subprocess.Popen(e0,shell=True) - os.waitpid(p0.pid, 0) - try: - logt=unicode(p0.communicate()[0], "UTF-8") - recdblist.addLog(pts,e0, "FFmpeg_wav2aac音声取り出しログ-コマンド") - recdblist.addLog(pts,logt, "FFmpeg_wav2aac音声取り出しログ-詳細") - except: - "" -def ts2single_fp_BonTsDemux(pts,opts): - useNero=0 - try: - if configreader.getConfPath("useNeroAAC")=="1" and os.path.exists(configreader.getConfPath("NeroAAC")): - useNero=1 - except: - useNero=0 - if useNero==1: - ts2single_aac_BonTsDemux_Nero(pts,opts) - else: - ts2single_aac_ffmpeg(pts) - if not os.path.exists(pts.replace(".ts",".aac")): - 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.getConfPath('bontsdemux') - wine = configreader.getConfPath('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 os.path.exists(configreader.getConfPath("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.getConfPath('bontsdemux') - wine = configreader.getConfPath('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 os.path.exists(configreader.getConfPath("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-2011 Yukikaze + +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=configreader.getConfPath('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.getConfPath("ffmpeg") + e0=ffmpeg+" -i \""+pts+"\" -y -vn -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.getConfPath('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) + txt=commands.getoutput(exe.encode('utf-8')) + recdblist.addCommandLog(pts, u"BonTsDemux 音声取り出し", exe, txt) +def ts2single_mp3_ffmpeg(pts): + pmp3=pts.replace(".ts",".mp3") + ffmpeg=configreader.getConfPath("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_aac_ffmpeg(pts): + ts2singlewav(pts,opts) + aout=pts.replace(".ts",".aac") + ain=pts.replace(".ts",".wav") + wav2aac_ffmpeg(ain,aout) +def wav2aac_ffmpeg(pin,pout): + paac=pts.replace(".ts",".aac") + ffmpeg=configreader.getConfPath("ffmpeg") + e0=ffmpeg+" -i \""+pin+"\" -y \""+pout+"\"" + p0=subprocess.Popen(e0,shell=True) + os.waitpid(p0.pid, 0) + try: + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, "FFmpeg_wav2aac音声取り出しログ-コマンド") + recdblist.addLog(pts,logt, "FFmpeg_wav2aac音声取り出しログ-詳細") + except: + "" +def ts2single_fp_BonTsDemux(pts,opts): + useNero=0 + try: + if configreader.getConfPath("useNeroAAC")=="1" and os.path.exists(configreader.getConfPath("NeroAAC")): + useNero=1 + except: + useNero=0 + if useNero==1: + ts2single_aac_BonTsDemux_Nero(pts,opts) + else: + ts2single_aac_ffmpeg(pts) + if not os.path.exists(pts.replace(".ts",".aac")): + 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.getConfPath('bontsdemux') + wine = configreader.getConfPath('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 os.path.exists(configreader.getConfPath("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.getConfPath('bontsdemux') + wine = configreader.getConfPath('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 os.path.exists(configreader.getConfPath("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 831c248..f441bee 100644 --- a/rec10/trunk/src/tv2avi.py +++ b/rec10/trunk/src/tv2avi.py @@ -1,111 +1,111 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2011 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,chdb.searchCHFromChtxt(chtxt)['tsid']) -def b252ts(pout, chtxt, btime, etime, opt): - """ - poutはタイトル(自動的にtitle.b25 title.tsと名前がつきます。) - """ - #status.setB25Decoding(status.getB25Decoding() + 1) - status.changeB25Decoding(1) - try: - try: - chs=chdb.searchCHFromChtxt(chtxt) - ch=chs['ch'] - csch=chs['csch'] - #print [ch,csch,chtxt] - 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("b", opt): - singleaudiosplit = 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) - if singleaudiosplit == 1: - tv2audio.ts2single_fp_BonTsDemux(aviin, 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-2011 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,chdb.searchCHFromChtxt(chtxt)['tsid']) +def b252ts(pout, chtxt, btime, etime, opt): + """ + poutはタイトル(自動的にtitle.b25 title.tsと名前がつきます。) + """ + #status.setB25Decoding(status.getB25Decoding() + 1) + status.changeB25Decoding(1) + try: + try: + chs=chdb.searchCHFromChtxt(chtxt) + ch=chs['ch'] + csch=chs['csch'] + #print [ch,csch,chtxt] + 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("b", opt): + singleaudiosplit = 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) + if singleaudiosplit == 1: + tv2audio.ts2single_fp_BonTsDemux(aviin, 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 e713f98..1951a8f 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-2011 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) +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 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 e86136a..57864bb 100644 --- a/rec10/trunk/src/tv2mp4.py +++ b/rec10/trunk/src/tv2mp4.py @@ -1,239 +1,239 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2011 Yukikaze -import commands -import shutil -import auto_process -import os -import re -import os.path -import string -import base64 -import time -import subprocess -import traceback -import zip - -import tv2avi -import recdblist -import configreader -import status -import tv2audio -path = str(os.path.dirname(os.path.abspath(__file__))) + "/" -tmppath = configreader.getConfPath("tmp")+"/" -if tmppath=="/": - tmppath=path -if not os.path.exists(tmppath): - os.mkdir(tmppath) -def ts2mp4(pin, pout, opt): - dir=os.path.split(pout)[0] - title=os.path.split(pout)[1] - title=os.path.splitext(title)[0] - tpraw=os.path.join(dir, title+".264") - tpmp4=os.path.join(dir, title+".mp4") - if os.path.isfile(pin) and os.path.getsize(pin)>10*1000: - tv2avi.ts2raw(pin, tpraw, opt) - time.sleep(10) - if os.path.isfile(tpraw) and os.path.getsize(tpraw)>10*1000: - raw2mp4(tpraw, tpmp4, opt) - time.sleep(10) - if os.path.exists(tpraw) and not re.search("B",opt): - os.remove(tpraw) - zip.addFile2FileZip(recdblist.getLogTitle(pin)+".command.log", recdblist.getLogTitle(pin)+".log.zip") - if os.path.exists(recdblist.getLogTitle(pin)+".command.log"): - os.remove(recdblist.getLogTitle(pin)+".command.log") -def raw2mp4(pin,pout,opt): - dir=os.path.split(pout)[0] - title=os.path.split(pout)[1] - title=os.path.splitext(title)[0] - duration="-fps 29.970030 " - if re.search("a",opt): - duration="-fps 23.976023 " - if re.search("I",opt): - duration="-fps 29.970030 " - exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath - txt="" - os.environ['LANG']="ja_JP.UTF-8" - pints=pin.replace(".264",".ts") - e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\"" - execmp4box(pin, pout, e1) - addAudio(pints, pout, opt) - addCaption(pints, pout) - if status.getSettings_auto_del_tmp()==1: - if os.path.exists(pout): - if re.search("t",opt): - auto_process.deleteTmpFile(dir, title, ".264") - elif re.search("k",opt): - ""#削除しない - else: - auto_process.deleteTmpFile(dir, title, ".mp4") -def mkv2mp4(pin,pout): - exeb = configreader.getConfPath(u"mkvextract") - exe = configreader.getConfPath(u"mp4Box") - #dtsedit=configreader.getConfPath("DtsEdit") - wineexe=configreader.getConfPath("wine") - dir=os.path.split(pin)[0] - title=os.path.split(pin)[1] - title=os.path.splitext(title)[0] - etitle=base64.b16encode(title.encode('utf-8')) - audiopath=os.path.join(dir,etitle+u"_audio.aac") - videopath=os.path.join(dir,etitle+u"_video.264") - timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt") - tmpmp4=os.path.join(dir,etitle+u".tmp.mp4") - exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'" - exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'" - exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'" - exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'" - os.environ['LANG']="ja_JP.UTF-8" - txt="" - try: - txt=txt+execcomd(exe0)+"\n" - txt=txt+execcomd(exe1)+"\n" - txt=txt+execcomd(exe2)+"\n" - txt=txt+execcomd(exe3)+"\n" - except: - "" - recdblist.addLog(pin, txt, u"MKV2MP4-log") - txt = "\n####MKV2MP4-log####\n"+txt - time.sleep(10) - if status.getSettings_auto_del_tmp()==1: - if os.path.exists(pout): - auto_process.deleteTmpFile(dir, title, ".mp4") -def addCaption(pts,pmp4):##字幕の追加を試みる。 - wineexe=configreader.getConfPath("wine") - pincap=pts.replace(".ts",".srt") - try: - cap2ass=configreader.getConfPath("caption2ass") - except: - cap2ass="" - if os.path.isfile(cap2ass): - e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pts+"\" \"Z:\\"+pincap+"\"" - recdblist.printutf8(e0) - p0=subprocess.Popen(e0,shell=True,stdout=subprocess.PIPE) - time.sleep(100) - if p0.poll==None:#実行中 - #if os.path.getsize(pincap)<1000:#2mで1kb以下の場合自動で終了 - # os.kill(p0.pid,signal.SIGKILL) - #else: - os.waitpid(p0.pid, 0) - logt=unicode(p0.communicate()[0], "UTF-8") - recdblist.addLog(pts,e0, u"Captionログ-コマンド") - recdblist.addLog(pts,logt, u"Captionログ-詳細") - recdblist.addCommandLogZip(pts, "mp4box_caption", "mp4box_caption", e0, logt) - if os.path.exists(pincap): - if os.path.getsize(pincap)>1000: - exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath - e1s=exe +u" -add \""+pincap+"\" \""+pmp4+"\"" - addmp4(pincap,pmp4,e1s) -def addAudio(pts,pmp4,opts):#オプションに応じた音声の追加を行う - exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath - if re.search("d",opts) or re.search("5",opts):#二カ国語放送/5.1ch放送の場合 - paac1=pts.replace(".ts","_1.aac") - paac2=pts.replace(".ts","_2.aac") - recdblist.printutf8(paac1) - e1a1=exe +u" -add \""+paac1+"\":mpeg4 \""+pmp4+"\"" - e1a2=exe +u" -add \""+paac2+"\":mpeg4 \""+pmp4+"\"" - if not os.path.exists(paac1): - paac1=pts.replace(".ts","_1.mp3") - e1a1=exe +u" -add \""+paac1+"\" \""+pmp4+"\"" - if not os.path.exists(paac2): - paac2=pts.replace(".ts","_2.mp3") - e1a1=exe +u" -add \""+paac2+"\" \""+pmp4+"\"" - if os.path.exists(paac1): - addmp4(paac1, pmp4, e1a1) - if os.path.exists(paac2): - addmp4(paac2, pmp4, e1a2) - elif re.search("b",opts):#BonTsDemuxを使って音声をスプリットした場合 - paac=pts.replace(".ts",".aac") - e1a=exe +u" -add \""+pinaac+"\":mpeg4 \""+pmp4+"\"" - if not os.path.exists(paac): - paac=pts.replace(".ts",".mp3") - e1a1=exe +u" -add \""+paac+"\" \""+pmp4+"\"" - if os.path.exists(paac): - addmp4(paac, pmp4, e1a1) - else: - tv2audio.ts2single_audio(pts,opts) - pinaac=pts.replace(".ts",".aac") - e1a=exe +u" -add \""+pinaac+"\":mpeg4 \""+pmp4+"\"" - if not os.path.exists(pinaac): - pinaac=pinaac.replace(".aac",".mp3") - e1a=exe +u" -add \""+pinaac+"\" \""+pmp4+"\"" - if os.path.exists(pinaac): - addmp4(pinaac, pmp4, e1a) -def execmp4box(pin,pout,cmd): - title=os.path.splitext(os.path.split(pin)[1])[0] - nt=base64.b16encode(title.encode('utf-8')) - if len(nt)>200: - nt=nt[:180] - ptin=os.path.join(os.path.dirname(pin),nt+".264") - recdblist.printutf8(ptin) - shutil.move(pin,ptin) - time.sleep(10) - ptout=os.path.join(os.path.dirname(pout),nt+".mp4") - cmdn=string.replace(cmd,pin,ptin) - cmdn=string.replace(cmdn,pout,ptout) - recdblist.printutf8(cmdn) - recdblist.addCommandSelfLog(pin, cmdn) - txt="" - try: - txt=execcomd(cmdn) - except Exception, inst: - txt= "error occures in execmp4box\n" - txt=txt+ str(type(inst))+"\n" - txt=txt+str(inst) - recdblist.addCommonlogEX("Error", "excecmp4box(tv2mp4.py)", str(type(inst)), str(inst)+traceback.format_exc(),verbose_level=200,log_level=200) - recdblist.addLog(pin, cmdn, u"MP4Boxログ-コマンド") - recdblist.addLog(pin, txt, u"MP4Boxログ-詳細") - recdblist.addCommandLogZip(pin, "MP4Box", "mp4box", cmdn,txt) - time.sleep(5) - shutil.move(ptin,pin) - shutil.move(ptout,pout) - time.sleep(5) -def addmp4(padd,pout,cmd):#without video - title=os.path.splitext(os.path.split(padd)[1])[0] - ext=os.path.splitext(os.path.split(padd)[1])[1] - nt=base64.b16encode(title.encode('utf-8')) - if len(nt)>200: - nt=nt[:180] - ptadd=os.path.join(os.path.dirname(padd),nt+ext) - ptoutb=os.path.join(os.path.dirname(pout),nt+"_b.mp4") - ptout=os.path.join(os.path.dirname(pout),nt+".mp4") - shutil.move(padd,ptadd) - if os.path.isfile(pout): - shutil.move(pout,ptoutb) - time.sleep(5) - cmdn=string.replace(cmd,padd,ptadd) - cmdn=string.replace(cmdn,u"-out \""+pout,u"-add \""+ptoutb+"\" -new \""+ptout) - cmdn=string.replace(cmdn,u"\""+pout,u"-add \""+ptoutb+"\" -new \""+ptout) - cmdn=string.replace(cmdn,pout,ptout) - recdblist.printutf8(cmdn) - txt="" - try: - txt=execcomd(cmdn) - except Exception, inst: - txt= "error occures in addmp4\n" - txt=txt+ str(type(inst))+"\n" - txt=txt+str(inst) - recdblist.addLog(pout, cmdn, u"MP4Box追加ログ-コマンド") - recdblist.addLog(pout, txt, u"MP4Box追加ログ-詳細") - recdblist.addCommandLogZip(pout, "MP4Box_add", "mp4box_add", cmdn, txt) - time.sleep(5) - shutil.move(ptadd,padd) - if os.path.exists(ptout): - shutil.move(ptout,pout) - os.remove(ptoutb) - else: - txtt=padd+u"のインポートエラー" - recdblist.addLog(pout, txtt, u"MP4Box追加ログ-コマンド") - shutil.move(ptoutb,pout) - time.sleep(5) -def execcomd(cmd): - txt="" - try: - txt=u"Cmd : "+cmd+"\n" - txt2=commands.getoutput(cmd.encode('utf-8')) - txt=txt+unicode(txt2,"utf-8")+"\n" - except: - "" - return txt +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 Yukikaze +import commands +import shutil +import auto_process +import os +import re +import os.path +import string +import base64 +import time +import subprocess +import traceback +import zip + +import tv2avi +import recdblist +import configreader +import status +import tv2audio +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" +tmppath = configreader.getConfPath("tmp")+"/" +if tmppath=="/": + tmppath=path +if not os.path.exists(tmppath): + os.mkdir(tmppath) +def ts2mp4(pin, pout, opt): + dir=os.path.split(pout)[0] + title=os.path.split(pout)[1] + title=os.path.splitext(title)[0] + tpraw=os.path.join(dir, title+".264") + tpmp4=os.path.join(dir, title+".mp4") + if os.path.isfile(pin) and os.path.getsize(pin)>10*1000: + tv2avi.ts2raw(pin, tpraw, opt) + time.sleep(10) + if os.path.isfile(tpraw) and os.path.getsize(tpraw)>10*1000: + raw2mp4(tpraw, tpmp4, opt) + time.sleep(10) + if os.path.exists(tpraw) and not re.search("B",opt): + os.remove(tpraw) + zip.addFile2FileZip(recdblist.getLogTitle(pin)+".command.log", recdblist.getLogTitle(pin)+".log.zip") + if os.path.exists(recdblist.getLogTitle(pin)+".command.log"): + os.remove(recdblist.getLogTitle(pin)+".command.log") +def raw2mp4(pin,pout,opt): + dir=os.path.split(pout)[0] + title=os.path.split(pout)[1] + title=os.path.splitext(title)[0] + duration="-fps 29.970030 " + if re.search("a",opt): + duration="-fps 23.976023 " + if re.search("I",opt): + duration="-fps 29.970030 " + exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath + txt="" + os.environ['LANG']="ja_JP.UTF-8" + pints=pin.replace(".264",".ts") + e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\"" + execmp4box(pin, pout, e1) + addAudio(pints, pout, opt) + addCaption(pints, pout) + if status.getSettings_auto_del_tmp()==1: + if os.path.exists(pout): + if re.search("t",opt): + auto_process.deleteTmpFile(dir, title, ".264") + elif re.search("k",opt): + ""#削除しない + else: + auto_process.deleteTmpFile(dir, title, ".mp4") +def mkv2mp4(pin,pout): + exeb = configreader.getConfPath(u"mkvextract") + exe = configreader.getConfPath(u"mp4Box") + #dtsedit=configreader.getConfPath("DtsEdit") + wineexe=configreader.getConfPath("wine") + dir=os.path.split(pin)[0] + title=os.path.split(pin)[1] + title=os.path.splitext(title)[0] + etitle=base64.b16encode(title.encode('utf-8')) + audiopath=os.path.join(dir,etitle+u"_audio.aac") + videopath=os.path.join(dir,etitle+u"_video.264") + timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt") + tmpmp4=os.path.join(dir,etitle+u".tmp.mp4") + exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'" + exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'" + exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'" + exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'" + os.environ['LANG']="ja_JP.UTF-8" + txt="" + try: + txt=txt+execcomd(exe0)+"\n" + txt=txt+execcomd(exe1)+"\n" + txt=txt+execcomd(exe2)+"\n" + txt=txt+execcomd(exe3)+"\n" + except: + "" + recdblist.addLog(pin, txt, u"MKV2MP4-log") + txt = "\n####MKV2MP4-log####\n"+txt + time.sleep(10) + if status.getSettings_auto_del_tmp()==1: + if os.path.exists(pout): + auto_process.deleteTmpFile(dir, title, ".mp4") +def addCaption(pts,pmp4):##字幕の追加を試みる。 + wineexe=configreader.getConfPath("wine") + pincap=pts.replace(".ts",".srt") + try: + cap2ass=configreader.getConfPath("caption2ass") + except: + cap2ass="" + if os.path.isfile(cap2ass): + e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pts+"\" \"Z:\\"+pincap+"\"" + recdblist.printutf8(e0) + p0=subprocess.Popen(e0,shell=True,stdout=subprocess.PIPE) + time.sleep(100) + if p0.poll==None:#実行中 + #if os.path.getsize(pincap)<1000:#2mで1kb以下の場合自動で終了 + # os.kill(p0.pid,signal.SIGKILL) + #else: + os.waitpid(p0.pid, 0) + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addLog(pts,e0, u"Captionログ-コマンド") + recdblist.addLog(pts,logt, u"Captionログ-詳細") + recdblist.addCommandLogZip(pts, "mp4box_caption", "mp4box_caption", e0, logt) + if os.path.exists(pincap): + if os.path.getsize(pincap)>1000: + exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath + e1s=exe +u" -add \""+pincap+"\" \""+pmp4+"\"" + addmp4(pincap,pmp4,e1s) +def addAudio(pts,pmp4,opts):#オプションに応じた音声の追加を行う + exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath + if re.search("d",opts) or re.search("5",opts):#二カ国語放送/5.1ch放送の場合 + paac1=pts.replace(".ts","_1.aac") + paac2=pts.replace(".ts","_2.aac") + recdblist.printutf8(paac1) + e1a1=exe +u" -add \""+paac1+"\":mpeg4 \""+pmp4+"\"" + e1a2=exe +u" -add \""+paac2+"\":mpeg4 \""+pmp4+"\"" + if not os.path.exists(paac1): + paac1=pts.replace(".ts","_1.mp3") + e1a1=exe +u" -add \""+paac1+"\" \""+pmp4+"\"" + if not os.path.exists(paac2): + paac2=pts.replace(".ts","_2.mp3") + e1a1=exe +u" -add \""+paac2+"\" \""+pmp4+"\"" + if os.path.exists(paac1): + addmp4(paac1, pmp4, e1a1) + if os.path.exists(paac2): + addmp4(paac2, pmp4, e1a2) + elif re.search("b",opts):#BonTsDemuxを使って音声をスプリットした場合 + paac=pts.replace(".ts",".aac") + e1a=exe +u" -add \""+pinaac+"\":mpeg4 \""+pmp4+"\"" + if not os.path.exists(paac): + paac=pts.replace(".ts",".mp3") + e1a1=exe +u" -add \""+paac+"\" \""+pmp4+"\"" + if os.path.exists(paac): + addmp4(paac, pmp4, e1a1) + else: + tv2audio.ts2single_audio(pts,opts) + pinaac=pts.replace(".ts",".aac") + e1a=exe +u" -add \""+pinaac+"\":mpeg4 \""+pmp4+"\"" + if not os.path.exists(pinaac): + pinaac=pinaac.replace(".aac",".mp3") + e1a=exe +u" -add \""+pinaac+"\" \""+pmp4+"\"" + if os.path.exists(pinaac): + addmp4(pinaac, pmp4, e1a) +def execmp4box(pin,pout,cmd): + title=os.path.splitext(os.path.split(pin)[1])[0] + nt=base64.b16encode(title.encode('utf-8')) + if len(nt)>200: + nt=nt[:180] + ptin=os.path.join(os.path.dirname(pin),nt+".264") + recdblist.printutf8(ptin) + shutil.move(pin,ptin) + time.sleep(10) + ptout=os.path.join(os.path.dirname(pout),nt+".mp4") + cmdn=string.replace(cmd,pin,ptin) + cmdn=string.replace(cmdn,pout,ptout) + recdblist.printutf8(cmdn) + recdblist.addCommandSelfLog(pin, cmdn) + txt="" + try: + txt=execcomd(cmdn) + except Exception, inst: + txt= "error occures in execmp4box\n" + txt=txt+ str(type(inst))+"\n" + txt=txt+str(inst) + recdblist.addCommonlogEX("Error", "excecmp4box(tv2mp4.py)", str(type(inst)), str(inst)+traceback.format_exc(),verbose_level=200,log_level=200) + recdblist.addLog(pin, cmdn, u"MP4Boxログ-コマンド") + recdblist.addLog(pin, txt, u"MP4Boxログ-詳細") + recdblist.addCommandLogZip(pin, "MP4Box", "mp4box", cmdn,txt) + time.sleep(5) + shutil.move(ptin,pin) + shutil.move(ptout,pout) + time.sleep(5) +def addmp4(padd,pout,cmd):#without video + title=os.path.splitext(os.path.split(padd)[1])[0] + ext=os.path.splitext(os.path.split(padd)[1])[1] + nt=base64.b16encode(title.encode('utf-8')) + if len(nt)>200: + nt=nt[:180] + ptadd=os.path.join(os.path.dirname(padd),nt+ext) + ptoutb=os.path.join(os.path.dirname(pout),nt+"_b.mp4") + ptout=os.path.join(os.path.dirname(pout),nt+".mp4") + shutil.move(padd,ptadd) + if os.path.isfile(pout): + shutil.move(pout,ptoutb) + time.sleep(5) + cmdn=string.replace(cmd,padd,ptadd) + cmdn=string.replace(cmdn,u"-out \""+pout,u"-add \""+ptoutb+"\" -new \""+ptout) + cmdn=string.replace(cmdn,u"\""+pout,u"-add \""+ptoutb+"\" -new \""+ptout) + cmdn=string.replace(cmdn,pout,ptout) + recdblist.printutf8(cmdn) + txt="" + try: + txt=execcomd(cmdn) + except Exception, inst: + txt= "error occures in addmp4\n" + txt=txt+ str(type(inst))+"\n" + txt=txt+str(inst) + recdblist.addLog(pout, cmdn, u"MP4Box追加ログ-コマンド") + recdblist.addLog(pout, txt, u"MP4Box追加ログ-詳細") + recdblist.addCommandLogZip(pout, "MP4Box_add", "mp4box_add", cmdn, txt) + time.sleep(5) + shutil.move(ptadd,padd) + if os.path.exists(ptout): + shutil.move(ptout,pout) + os.remove(ptoutb) + else: + txtt=padd+u"のインポートエラー" + recdblist.addLog(pout, txtt, u"MP4Box追加ログ-コマンド") + shutil.move(ptoutb,pout) + time.sleep(5) +def execcomd(cmd): + txt="" + try: + txt=u"Cmd : "+cmd+"\n" + txt2=commands.getoutput(cmd.encode('utf-8')) + txt=txt+unicode(txt2,"utf-8")+"\n" + except: + "" + return txt diff --git a/rec10/trunk/src/xml2db_dom.py b/rec10/trunk/src/xml2db_dom.py index b65b189..24c1da7 100644 --- a/rec10/trunk/src/xml2db_dom.py +++ b/rec10/trunk/src/xml2db_dom.py @@ -1,148 +1,148 @@ -#!/usr/bin/python -# coding: UTF-8 -# Rec10 TS Recording Tools -# Copyright (C) 2009-2011 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) - if dn==None: - chdb.changeCHShow(chtxt,"0") - else: - if len(dn)<1: - chdb.changeCHShow(chtxt,"0") -def writeMultiLogoDB(logolists): - #[type,sv,pngdata] - for type,sv,pngdata in logolists: - chtxt=chdb.searchCHFromCsch(sv)['chtxt'] - if len(chtxt)>0: - rec10d.rec10db.change_logodata_epg_ch(chtxt,type,pngdata) -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.searchCHFromChtxt(channel) - if tch!=None: - if tch.get('bctype',"")==bctype and not tch['visible']==0: - 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 xml2db_dom_logo(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る - dtb=datetime.datetime.now() - dom=xml.dom.minidom.parse(file(xmlpath)) - logolist=[] - for logo in dom.getElementsByTagName('logo'): - type=int(logo.getAttribute("type")) - sv=logo.getAttribute("sv") - pngdata=logo.childNodes[0].data - logolist.append([type,sv,pngdata]) - dom.unlink() - if len(logolist) > 0: - writeMultiLogoDB(logolist) - 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 logo 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 +#!/usr/bin/python +# coding: UTF-8 +# Rec10 TS Recording Tools +# Copyright (C) 2009-2011 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) + if dn==None: + chdb.changeCHShow(chtxt,"0") + else: + if len(dn)<1: + chdb.changeCHShow(chtxt,"0") +def writeMultiLogoDB(logolists): + #[type,sv,pngdata] + for type,sv,pngdata in logolists: + chtxt=chdb.searchCHFromCsch(sv)['chtxt'] + if len(chtxt)>0: + rec10d.rec10db.change_logodata_epg_ch(chtxt,type,pngdata) +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.searchCHFromChtxt(channel) + if tch!=None: + if tch.get('bctype',"")==bctype and not tch['visible']==0: + 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 xml2db_dom_logo(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る + dtb=datetime.datetime.now() + dom=xml.dom.minidom.parse(file(xmlpath)) + logolist=[] + for logo in dom.getElementsByTagName('logo'): + type=int(logo.getAttribute("type")) + sv=logo.getAttribute("sv") + pngdata=logo.childNodes[0].data + logolist.append([type,sv,pngdata]) + dom.unlink() + if len(logolist) > 0: + writeMultiLogoDB(logolist) + 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 logo 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 diff --git a/rec10/trunk/src/zenhan.py b/rec10/trunk/src/zenhan.py index ff930dd..bb6135e 100644 --- a/rec10/trunk/src/zenhan.py +++ b/rec10/trunk/src/zenhan.py @@ -8,7 +8,7 @@ global z_ascii global h_ascii global z_number global h_number -z_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !”#$%&’()*+,−./:;<=>?@[¥]^_‘{|}〜 〜" +z_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !”#$%&’()*+,−./:;<=>?@[¥]^_‘{|}〜 〜" h_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ -" z_ascii_sp = unichr(0x2212)+unichr(0xff0e) h_ascii_sp = unichr(0x002d)+unichr(0x002e) -- 2.11.0