-#!/usr/bin/python\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-\r
-import glob\r
-import os\r
-import os.path\r
-import re\r
-import time\r
-import shutil\r
-import traceback\r
-import sys\r
-\r
-import recdblist\r
-import guess\r
-def getTitle(title):\r
- rT=re.compile("(.+)_(\d+)\Z")\r
- tT=rT.match(title)\r
- rT2=re.compile("(.+)_(.+)_(\d*)\Z")#_(aichi)_2010-02-06T01:59:00.mkv\r
- tT2=rT2.match(title)\r
- rT3=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+:\d+:\d+\Z")#_(aichi)_2010-02-06T01:59:00.mkv\r
- tT3=rT3.match(title)\r
- rT4=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+-\d+-\d+\Z")#_(aichi)_2010-02-06T01-59-00.mkv\r
- tT4=rT4.match(title)\r
- rT5=re.compile("(.+)_(.+)_(.+)\Z")#_(aichi)_2010-02-06T01-59-00.mkv\r
- tT5=rT5.match(title)\r
- ntitle=title\r
- if tT :\r
- ntitle=tT.group(1)\r
- elif tT2:\r
- ntitle=tT2.group(1)\r
- elif tT3:\r
- ntitle=tT3.group(1)\r
- elif tT4:\r
- ntitle=tT4.group(1)\r
- elif tT5:\r
- ntitle=tT5.group(1)\r
- return ntitle\r
-def searchFile(temppath,recpath,ext):\r
- """\r
- 録画一時フォルダ内ファイルを検索\r
- """\r
- avilist = glob.glob(temppath + "/*"+ext)\r
- ret=[]\r
- for avif in avilist:\r
- ##b25f is title.ts.b25 avi is title.avi\r
- dir = os.path.split(avif)[0]\r
- title = os.path.split(avif)[1]\r
- title = title.replace(ext, "")\r
- avipath = os.path.join(dir, title + ext)\r
- if os.path.exists(avipath):\r
- dtime = time.time()-os.path.getmtime(avipath)\r
- dtime = int(dtime)\r
- if dtime > 300:\r
- if veryfySize(avipath):\r
- ret.append(title)\r
- return ret\r
-def getMoveDestpath(title,temppath,recpath,ext):\r
- dstpath=os.path.join(recpath,title+ext)\r
- srcpath=os.path.join(temppath,title+ext)\r
- if os.path.exists(dstpath):\r
- if not os.path.getsize(dstpath) == os.path.getsize(srcpath):\r
- gmtime=time.gmtime(os.path.getmtime(srcpath))\r
- iff=""\r
- try:\r
- iff=u"("+configreader.getConfEnv("iff")+u")_"\r
- if iff==u"()_":\r
- iff = u""\r
- except:\r
- iff=""\r
- title=title+u"_"+iff+time.strftime("%Y-%m-%dT%H-%M-%S",gmtime)\r
- else:\r
- recdblist.printutf8(u"同サイズのファイルが存在します")\r
-\r
- return title\r
-def getDelpath(temppath,title,addfp=1):\r
- delpath=[os.path.join(temppath,title+".ts")]\r
- delpath.append(os.path.join(temppath,title+".avi"))\r
- if addfp==1:\r
- delpath.append(os.path.join(temppath,title+".mp4"))\r
- delpath.append(os.path.join(temppath,title+".mkv"))\r
- delpath.append(os.path.join(temppath,title+".m2v"))\r
- delpath.append(os.path.join(temppath,title+".120.avi"))\r
- delpath.append(os.path.join(temppath,title+".timecode.txt"))\r
- delpath.append(os.path.join(temppath,title+".aac"))\r
- delpath.append(os.path.join(temppath,title+".ts.b25"))\r
- delpath.append(os.path.join(temppath,title+".ts.tsmix"))\r
- delpath.append(os.path.join(temppath,title+".ts.log"))\r
- delpath.append(os.path.join(temppath,title+".sa.avi"))\r
- delpath.append(os.path.join(temppath,title+".sa.avi.log"))\r
- delpath.append(os.path.join(temppath,title+".log"))\r
- delpath.append(os.path.join(temppath,title+".log.zip"))\r
- return delpath\r
-def veryfySize(path):\r
- #vsize=[297,497,596,1196]#SD 30m 1h 1.5h 2h\r
- vsize=[245,275,295,591,830]\r
- vsize=vsize+[325,449,560,590,602,690,805,860,1014,1138,1237]\r
- vsize=vsize+[261,535,540,616,740]#HD 30m 1h\r
- #vsize=vsize+[381,895,447]\r
- ret = 0\r
- for size in vsize:\r
- if os.path.getsize(path)>(size-10)*1024*1024 and os.path.getsize(path)<(size+10)*1024*1024:\r
- ret=1\r
- if os.path.getsize(path)>270*1024*1024:\r
- ret=1\r
- return ret\r
-def execMove(title,temppath,recpath,ext,autodel):\r
- srcpath=os.path.join(temppath,title+ext)\r
+#!/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)\r
- if sf!="":\r
- destpath=os.path.join(sf,getMoveDestpath(title, temppath, sf, ext)+ext)\r
- if os.path.exists(destpath):\r
- if os.path.getsize(destpath) == os.path.getsize(srcpath):\r
- recdblist.printutf8(u"同名同サイズのファイルが存在します。")\r
- if autodel==1:\r
- recdblist.printutf8(u"関連ファイルを削除します。")\r
- delpath=getDelpath(temppath, title)\r
- for dp in delpath:\r
- try:\r
- os.remove(dp)\r
- ""\r
- except:\r
- ""\r
- else:\r
- recdblist.printutf8("moving now..")\r
- recdblist.printutf8(srcpath+" : "+destpath)\r
- print srcpath\r
- shutil.copy(srcpath, destpath)\r
- #shutil.copy(srcpath, destpath)\r
- if autodel==1:\r
- delpath=getDelpath(temppath, title)\r
- for dp in delpath:\r
- try:\r
- os.remove(dp)\r
- ""\r
- except:\r
+ 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)
-\r
-def execDelete(title,temppath):\r
- delpath=getDelpath(temppath, title,0)\r
- recdblist.printutf8(title+u" 関連の一時ファイルを削除します")\r
- for dp in delpath:\r
- try:\r
- if os.path.exists(dp):\r
- recdblist.printutf8(dp)\r
- os.remove(dp)\r
- except Exception, inst:\r
- print type(inst)\r
- print str(inst)\r
- print traceback.print_exc(file=sys.stdout)\r
+
+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)
-#!/usr/bin/python\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import os\r
-import glob\r
-import time\r
-import datetime\r
-import commands\r
-import re\r
-import os.path\r
-\r
-import chdb\r
-import status\r
-import configreader\r
-import recdblist\r
-import rec10d\r
-import tv2mp4\r
-import epgdb\r
-def updateToMP4(path):\r
- """\r
- !現在未使用!\r
- 録画一時フォルダ内mp4ファイルを検索\r
- """\r
- avilist = glob.glob(path + "/*.avi")\r
- mkvlist = glob.glob(path+"/*.mkv")\r
- avilist=avilist+mkvlist\r
- for avif in avilist:\r
- if avif.rfind("sa.avi")==-1:\r
- dir = os.path.split(avif)[0]\r
- title = os.path.split(avif)[1]\r
- title = title.replace(".avi", "")\r
- title = title.replace(".mkv", "")\r
- avipath = os.path.join(dir, title + ".avi")\r
- mkvpath = os.path.join(dir, title + ".mkv")\r
- mp4path = os.path.join(dir, title + ".mp4")\r
- if not os.path.exists(mp4path):\r
- if os.path.exists(avipath):\r
- avidtime = int(time.time()-os.path.getmtime(avipath))\r
- if avidtime>300:\r
- if os.path.exists(mkvpath):\r
- mkvdtime = int(time.time()-os.path.getmtime(mkvpath))\r
- if mkvdtime>300:\r
- recdblist.printutf8(mkvpath+":"+mp4path)\r
- tv2mp4.mkv2mp4(mkvpath,mp4path)\r
- else:\r
- recdblist.printutf8(avipath+":"+mp4path)\r
- tv2mp4.avi2mp4(avipath,mp4path)\r
- else:\r
- recdblist.printutf8(avipath+":"+mp4path)\r
- tv2mp4.avi2mp4(avipath,mp4path)\r
- else:\r
- if not os.path.exists(avipath):\r
- if os.path.exists(mkvpath):\r
- mkvdtime = int(time.time()-os.path.getmtime(mkvpath))\r
- if mkvdtime>300:\r
- recdblist.printutf8(mkvpath+":"+mp4path)\r
- tv2mp4.mkv2mp4(mkvpath,mp4path)\r
-def autoCheck(path):\r
- avilist = glob.glob(path + "/*.avi")\r
- mkvlist = glob.glob(path+"/*.mkv")\r
- mp4list = glob.glob(path+"/*.mp4")\r
- tslist = glob.glob(path+"/*.ts")\r
- b25list = glob.glob(path+"/*.ts.b25")\r
- filelist=avilist+mkvlist+tslist+b25list+mp4list\r
- add=[]\r
- tbtime=datetime.datetime.now()+datetime.timedelta(seconds=60)\r
- tbtime2=datetime.datetime.now()+datetime.timedelta(seconds=1200)\r
- for fn in filelist:\r
- if os.path.exists(fn):\r
- if fn.rfind("sa.avi")==-1 and fn.rfind(".120.avi")==-1 and os.path.getsize(fn)>1*1000*1000:\r
- dir = os.path.split(fn)[0]\r
- file = os.path.split(fn)[1]\r
- title = os.path.splitext(file)[0]\r
- title = unicode(title,'utf-8',errors='replace')\r
- ext = os.path.splitext(file)[1]\r
- if ext == ".b25":\r
- title=title.replace(".ts","")\r
- dbs=rec10d.rec10db.select_by_name_time_timeline(title,tbtime,tbtime2)\r
- if len(dbs)==0:\r
- proc=checkProcess(dir, title)\r
- chtxtt=rec10d.rec10db.select_chtxt_by_title_timeline_log(title)\r
- nchtxt=""\r
- if chtxtt!=None:\r
- nchtxt=chtxtt\r
- if proc=="b25":\r
- add.append([recdblist.REC_AUTO_SUGGEST_DECODE,title,nchtxt])\r
- elif proc=="ts":\r
- add.append([recdblist.REC_AUTO_SUGGEST_ENCODE,title,nchtxt])\r
- elif proc =="264":\r
- add.append([recdblist.REC_AUTO_SUGGEST_AVI2FP,title,nchtxt])\r
- #elif proc =="mp4":\r
- # add.append([recdblist.REC_AUTO_SUGGEST_AP2FP,title,nchtxt])\r
- #print add\r
- if len(add)>0:\r
- rec10d.rec10db.new_auto_proc()\r
- for a in add:\r
- rec10d.rec10db.add_auto_proc(a[0],a[1],a[2])\r
- time.sleep(1)\r
-"""\r
- 処理がどの段階まで言ったのかを調査し返す。\r
- return\r
- recording\r
- b25\r
- b25decoding\r
- tssplitting\r
- ts\r
- encoding\r
- avi\r
- mp4making\r
- mp4\r
-"""\r
-def checkProcess(path,title):\r
- path1 = os.path.join(path,title+".mkv")\r
- if os.path.exists(path1):\r
- if int(time.time()-os.path.getmtime(path1))>300:\r
- return "mkv"\r
- else:\r
- return "mkvmaking"\r
- elif os.path.exists(os.path.join(path,title+".mp4")):\r
- if int(time.time()-os.path.getmtime(os.path.join(path,title+".mp4")))>300:\r
- return "mp4"\r
- else:\r
- return "mp4making"\r
- elif os.path.exists(os.path.join(path,title+".264")):\r
- if int(time.time()-os.path.getmtime(os.path.join(path,title+".264")))>300:\r
- return "264"\r
- else:\r
- return "encoding"\r
- elif os.path.exists(os.path.join(path,title+".ts.log")):\r
- if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))<300:\r
- return "encoding"\r
- else:\r
- return "ts"\r
- elif os.path.exists(os.path.join(path,title+".ts")):\r
- if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts")))>300:\r
- return "ts"\r
- else:\r
- return "tssplitting"\r
- elif os.path.exists(os.path.join(path,title+".sa.avi")):\r
- if int(time.time()-os.path.getmtime(os.path.join(path,title+".sa.avi")))>300:\r
- return "ts"\r
- else:\r
- return "tssplitting"\r
- elif os.path.exists(os.path.join(path,title+".ts.b25")):\r
- if int(time.time()-os.path.getmtime(os.path.join(path,title+".ts.b25")))>300:\r
- return "b25"\r
- else:\r
- return "recording"\r
-def update_all_timeline_epg():\r
- now=datetime.datetime.now()\r
- et=now+datetime.timedelta(days=7)\r
- update_timeline_epg(now.strftime("%Y-%m-%d %H:%M:%S"), et.strftime("%Y-%m-%d %H:%M:%S"))\r
-def update_timeline_epg(btime,etime):\r
- update_timeline_epg_schedule(btime,etime)\r
- update_timeline_dup(btime,etime)\r
-def update_timeline_epg_schedule(btime,etime):\r
- dbl=rec10d.rec10db.select_bytime_all_timeline(btime, etime)\r
- #print dbl\r
- for db in dbl:\r
- ret=[]\r
- #[chtxtt, title, btime, etime,exp,longexp,category]\r
- if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS:\r
- ret=epgdb.searchTime(db['title'], db['btime'], db['deltatime'], db['chtxt'])\r
- if len(ret)>4 and len(ret[2])>18:\r
- rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4],ret[6])\r
- if not (db['btime'] == ret[2] and db['etime']==ret[3]):\r
- rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")\r
- else:\r
- rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")\r
- else:\r
- rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")\r
- elif db['type']==recdblist.REC_RESERVE or db['type']==recdblist.REC_FINAL_RESERVE :\r
- ret=epgdb.searchTime(db['title'], db['btime'],"5", db['chtxt'])\r
- if len(ret)>4 and len(ret[2])>18:\r
- rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4],ret[6])\r
- if not (db['btime'] == ret[2] and db['etime']==ret[3]):\r
- rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")\r
- else:\r
- rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")\r
- else:\r
- rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")\r
-def update_timeline_dup(epgbtime,epgetime):\r
- dbl=rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime)\r
- for db in dbl:\r
- if db['type']==recdblist.REC_KEYWORD or db['type']==recdblist.REC_KEYWORD_EVERY_SOME_DAYS:\r
- dbn=epgdb.countEpgSchedule(db['epgbtime'], db['epgetime'])\r
- try:\r
- bctypet=chdb.searchCHFromChtxt(db['chtxt'])['bctype']\r
- if bctypet.find("cs") > -1 or bctypet.find("bs") > -1 :\r
- if dbn[1]>status.getRecordingMax()[1]:\r
- rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")\r
- else:\r
- rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")\r
- else:\r
- if dbn[0]>status.getRecordingMax()[0]:\r
- rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")\r
- else:\r
- rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")\r
- except:\r
- ""\r
-def killDeadEncode(path):\r
- rawlist = glob.glob(path + "/*.264")\r
- for fn in rawlist:\r
- if int(time.time()-os.path.getmtime(fn))>3000:\r
- m2vpath=unicode(fn.replace(".264",".m2v"),'utf-8')\r
- x264path=os.path.split(fn)[1]\r
- folderpath=unicode(os.path.split(fn)[0],'utf-8')\r
- x264path=re.sub("\\[","[",x264path)\r
- x264path=re.sub("\[","\\\[",x264path)\r
- x264path=re.sub("\\]","]",x264path)\r
- x264path=re.sub("]","\\]",x264path)\r
- tspath=unicode(x264path.replace(".264",".ts"),'utf-8')\r
- m2vpath=unicode(x264path.replace(".264",".m2v"),'utf-8')\r
- x264path=unicode(x264path,'utf-8')\r
- os.environ['LANG']="ja_JP.UTF-8"\r
- ktmp=[]\r
- ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+x264path+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep x264 | awk '{print $2}'")\r
- ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+tspath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'")\r
- ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+m2vpath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep ffmpeg | awk '{print $2}'")\r
- recdblist.printutf8(u"エンコード処理異常終了タスク終了")\r
- for istr in ktmp:\r
- recdblist.printutf8(istr)\r
- ktmt=commands.getoutput(istr.encode('utf-8'))\r
- #print ktmt\r
- #print len(ktmt)\r
- if len(ktmt)>0:\r
- #print ktmt\r
- if len(ktmt[0])>0:\r
- ktmt=ktmt[0]\r
- #print ktmt\r
- try:\r
- if int(ktmt)>0:\r
- ktmp=u"kill -9 `"+istr+u"`"\r
- recdblist.printutf8(ktmp)\r
- #print ktmp\r
- os.system(ktmp.encode('utf-8'))\r
- except:\r
- ""\r
-def deleteTmpFile(path,title,ext):\r
- level= 0##0:b25 1:ts(del tsmix and ts.b25) 5:x264(del 2 and so on) 10:mp4/mkv\r
- smsize= 0\r
- if re.search(".ts",ext):\r
- level= 1\r
- smsize = 100*1000*1000\r
- elif re.search(".264",ext):\r
- level= 5\r
- smsize = 10*1000*1000\r
- elif re.search(".mp4",ext):\r
- level = 10\r
- smsize = 10*1000*1000\r
- elif re.search(".mkv",ext):\r
- level = 15\r
- smsize = 10*1000*1000\r
- dp=[]\r
- if level > 0 :\r
- if os.path.exists(os.path.join(path,title+".ts")) and os.path.exists(os.path.join(path,title+".ts.b25")):\r
- if os.path.getsize(os.path.join(path,title+".ts"))*12>os.path.getsize(os.path.join(path,title+".ts.b25")):\r
- dp.append(os.path.join(path,title+".ts.b25"))\r
- elif os.path.getsize(os.path.join(path,title+".ts"))>200*1000*1000:\r
- dp.append(os.path.join(path,title+".ts.b25"))\r
- if level > 4 :\r
- if configreader.getConfEnv("remove_ts")=="1":\r
- dp.append(os.path.join(path,title+".ts"))\r
- if level > 9 :\r
- dp.append(os.path.join(path,title+".avi"))\r
- dp.append(os.path.join(path,title+".264"))\r
- dp.append(os.path.join(path,title+".120.avi"))\r
- dp.append(os.path.join(path,title+".noodml.avi"))\r
- dp.append(os.path.join(path,title+".aac"))\r
- dp.append(os.path.join(path,title+".m2v"))\r
- dp.append(os.path.join(path,title+"_1.aac"))\r
- dp.append(os.path.join(path,title+"_2.aac"))\r
- dp.append(os.path.join(path,title+"_1.mp3"))\r
- dp.append(os.path.join(path,title+"_2.mp3"))\r
- dp.append(os.path.join(path,title+".srt"))\r
- if level > 14 :\r
- dp.append(os.path.join(path,title+".mp4"))\r
- if os.path.exists(os.path.join(path,title+ext)):\r
- if os.path.getsize(os.path.join(path,title+ext))>smsize:\r
- for ip in dp:\r
- try:\r
- os.remove(ip)\r
- except:\r
- ""\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import os\r
-import os.path\r
-import time\r
-import optparse\r
-import sys\r
-import datetime\r
-\r
-import configreader\r
-import chdb\r
-import tv2mp4\r
-import tv2ts\r
-def testAllCHEncode(option,stime):\r
- chl=chdb.getAllCH()\r
- print chl\r
- path= configreader.getConfPath("test")\r
- tpath=os.path.join(path, "encode_test")\r
- if not os.path.exists(tpath):\r
- os.mkdir(tpath)\r
- dnowt=datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")+"_"+option+""\r
- tpatht=os.path.join(tpath,dnowt)\r
- if not os.path.exists(tpatht):\r
- os.mkdir(tpatht)\r
- if len(chl)>0:\r
- for t in chl:\r
- print t\r
- pathname=os.path.join(tpatht,t['chtxt'])\r
- print pathname\r
- tv2ts.tv2ts(pathname+".ts",t['ch'],t['csch'], stime,t['tsid'])\r
- tv2mp4.ts2mp4(pathname+".ts", pathname+".mp4", option)\r
- time.sleep(2)\r
-if __name__ == "__main__":\r
- usage="usage: "\r
- version="%prog 0.9.7"\r
- parser=optparse.OptionParser(usage=usage,version=version)\r
- parser.add_option("-e","--Encode",action="store",type="string",dest="encode_option",default="",metavar="TITLE",help="encode test(option)")\r
- (opts,args)=parser.parse_args(sys.argv)\r
- if opts.encode_option != "":##-sの場合\r
- print "test_all_ch_encode"\r
- testAllCHEncode(opts.encode_option, "10")\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2012 Yukikaze\r
-import os.path\r
-import configreader\r
-import xml.dom.minidom\r
-import scan_ch\r
-import datetime\r
-\r
-import rec10d\r
-\r
-path = str(os.path.dirname(os.path.abspath(__file__))) + "/"\r
-\r
-def chAdd(bctype, chtxt, ch, csch,tsid="0"):#すべて文字列\r
- tnow=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")\r
- 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)\r
-def addCHlist(cl):\r
- if len(cl)>0:\r
- for c in cl:\r
- chAdd(c[0],c[1],c[2],c[3])\r
-def getChList(xmlpath):\r
- dom=xml.dom.minidom.parse(file(xmlpath))\r
- chlist=[]\r
- for ch in dom.getElementsByTagName('channel'):\r
- bctype=ch.getAttribute("bctype")\r
- chd=ch.getAttribute("ch")\r
- csch=ch.getAttribute("csch")\r
- chtxt=ch.getAttribute("chtxt")\r
- ontv=ch.getAttribute("ontvcode")\r
- chlist.append([bctype,ontv,chtxt,chd,csch])\r
- return chlist\r
-def deleteChListALL():\r
- rec10d.rec10db.new_epg_ch()\r
-if __name__ == "__main__":\r
- deleteChListALL()\r
- scan_ch.searchCh()\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2012 Yukikaze\r
- # モジュール属性 argv を取得するため\r
-import rec10d\r
-\r
-def searchCHFromChtxt(chtxtin):\r
- chtxtt=chtxtin.replace("_0","_%")\r
- ret = []\r
- for datum in rec10d.rec10db.select_by_chtxt_epg_ch(chtxtt):\r
- 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]}\r
- ret.append(rett)\r
- if len(ret) == 0:\r
- ret.append(None)\r
- return ret[0]\r
-def searchCHFromBctype(bctypein):\r
- ret = []\r
- for datum in rec10d.rec10db.select_by_bctype_epg_ch(bctypein):\r
- 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]}\r
- ret.append(rett)\r
- if len(ret) == 0:\r
- ret.append(None)\r
- return ret[0]\r
-def searchCHFromCh(chin):\r
- ret = []\r
- for datum in rec10d.rec10db.select_by_ch_epg_ch(chin):\r
- 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]}\r
- ret.append(rett)\r
- if len(ret) == 0:\r
- ret.append(None)\r
- return ret[0]\r
-def searchCHFromCsch(cschin):\r
- ret = []\r
- for datum in rec10d.rec10db.select_by_csch_epg_ch(cschin):\r
- 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]}\r
- ret.append(rett)\r
- if len(ret) == 0:\r
- ret.append(None)\r
- return ret[0]\r
-def searchAllCHFromCh(chin):\r
- ret = []\r
- for datum in rec10d.rec10db.select_by_ch_epg_ch(chin):\r
- 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]}\r
- ret.append(rett)\r
- if len(ret) == 0:\r
- ret.append(None)\r
- return ret\r
-def getAllCH():\r
- ret = []\r
- for datum in rec10d.rec10db.select_all_epg_ch():\r
- 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]}\r
- ret.append(rett)\r
- if len(ret) == 0:\r
- ret.append(None)\r
- return ret\r
-def update():\r
- ret = []\r
- CSupdate = 0\r
- CS2update = 0\r
- BSupdate = 0\r
- rec10d.rec10db.set_new_status("8")\r
- for datum in rec10d.rec10db.select_get_update_epg_ch("6"):\r
- bctype = datum[0]\r
- if bctype == "cs1" or bctype == u"cs1":\r
- if CSupdate == 0:\r
- ret.append(u"cs1")\r
- CSupdate = 1\r
- elif bctype == "cs2" or bctype == u"cs2":\r
- if CS2update == 0:\r
- ret.append(u"cs2")\r
- CS2update = 1\r
- elif bctype == "bs" or bctype == u"bs":\r
- if BSupdate == 0:\r
- ret.append(u"bs")\r
- BSupdate = 1\r
- else:\r
- ret.append(bctype)\r
- return ret\r
-def changeCHShow(chtxt,isshow):\r
- rec10d.rec10db.change_visible_epg_ch(chtxt, isshow)\r
-def updateLogo():\r
- ret=[]\r
- BSCSUpdate=0\r
- for datum in rec10d.rec10db.select_get_updatelogo_epg_ch("720"):\r
- bctype=datum[0]\r
- if bctype == "cs1" or bctype == u"cs1":\r
- if BSCSUpdate==0:\r
- ret.append(u"bs")\r
- BSCSUpdate=1\r
- elif bctype == "cs2" or bctype == u"cs2":\r
- if BSCSUpdate==0:\r
- ret.append(u"bs")\r
- BSCSUpdate=1\r
- elif bctype == "bs" or bctype == u"bs":\r
- if BSCSUpdate==0:\r
- ret.append(u"bs")\r
- BSCSUpdate=1\r
- else:\r
- ret.append(bctype)\r
- return ret\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-\r
-import os\r
-import os.path\r
-import optparse\r
-import sys\r
-\r
-import configreader\r
-import recdblist\r
-import auto_move\r
-import guess\r
-recordedpath=unicode(configreader.getConfPath("recorded"),'utf-8')\r
-recpath=unicode(configreader.getConfPath("recpath"),'utf-8')\r
-\r
-if __name__ == "__main__":\r
- usage="usage: %prog read -h"\r
- version="%prog 0.9.4"\r
- parser=optparse.OptionParser(usage=usage,version=version)\r
- 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)")\r
- parser.add_option("-A","--Auto",action="store_true",dest="auto",default=False,help="auto classifying mode(not a test)")\r
- parser.add_option("-D","--Delete",action="store_true",dest="delete",default=False,help="auto delete tempfile mode(not a test)")\r
- parser.add_option("-e","--exec",action="store",type="string",dest="etitle",default="",metavar="TITLE",help="exec move(not a test)")\r
- parser.add_option("-l","--list",action="store_true",dest="list",default=False,help="File listing mode(test for -A)")\r
- parser.add_option("-t","--tssearch",action="store_true",dest="tssearch",default=False,help="Ts move auto search")\r
- parser.add_option("-T","--Tsmove",action="store_true",dest="tsmove",default=False,help="Ts auto move.")\r
- parser.add_option("-S","--SeriesNum",action="store",type="string",dest="seriespath",default="",metavar="TITLE",help="Search Series Number in the path.")\r
- parser.add_option("-m","--manual",action="store_true",dest="manual",default=False,help="manual classifying mode asking for y/n(not a test)")\r
- #parser.add_option("-f","--filenumlist",action="store_true",dest="filenumlist",default=False,help="Guess Program Number.")\r
-\r
- (opts,args)=parser.parse_args(sys.argv)\r
- if opts.ltitle!="":##-sの場合\r
- ltitle=unicode(opts.ltitle,'utf-8')\r
- sf=guess.searchFolder(ltitle, recordedpath)\r
- print "###MKV###"\r
- recdblist.printutf8(os.path.join(sf, auto_move.getMoveDestpath(ltitle,recpath,sf,".mkv")+".mkv"),verbose_level=100)\r
- print "\n"\r
- print "###MP4###"\r
- recdblist.printutf8(os.path.join(sf, auto_move.getMoveDestpath(ltitle,recpath,sf,".mp4")+".mp4"),verbose_level=100)\r
- print "\n"\r
- elif opts.auto:##-A の場合\r
- sa=auto_move.searchFile(recpath, recordedpath, ".mkv")\r
- for t in sa:\r
- recdblist.printutf8(u"自動推測実行中-MKV",verbose_level=100)\r
- sf=guess.searchFolder(t,recordedpath)\r
- if sf!="":\r
- recdblist.printutf8(u"移動先",verbose_level=100)\r
- recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mkv")+".mkv"),verbose_level=100)\r
- recdblist.printutf8(u"実行中",verbose_level=100)\r
- auto_move.execMove(t, recpath, recordedpath,".mkv",1)\r
- else:\r
- recdblist.printutf8(t+" can't find matching folder",verbose_level=100)\r
- sa=auto_move.searchFile(recpath, recordedpath, ".mp4")\r
- for t in sa:\r
- recdblist.printutf8(u"自動推測実行中-MP4",verbose_level=100)\r
- sf=guess.searchFolder(t,recordedpath,200)\r
- if sf!="":\r
- recdblist.printutf8(u"移動先",verbose_level=100)\r
- recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mp4")+".mp4"),verbose_level=100)\r
- recdblist.printutf8(u"実行中",verbose_level=100)\r
- auto_move.execMove(t, recpath, recordedpath,".mp4",1)\r
- else:\r
- recdblist.printutf8(t+" can't find matching folder",verbose_level=100)\r
- elif opts.manual:##-m の場合\r
+#!/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")\r
- for t in sa:\r
- sf=guess.searchFolder(t,recordedpath,200)\r
- if sf!="":\r
+ 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)\r
+ recdblist.printutf8(u"移動を実行します",verbose_level=100)
auto_move.execMove(t, recpath, recordedpath,".mp4",1)
- elif ans == 'n':\r
- recdblist.printutf8(u"移動を中止します",verbose_level=100)\r
- elif ans == 'h':\r
- recdblist.printutf8(u"移動のヒント",verbose_level=100)\r
- recdblist.printutf8(u"FIXME:not implemented",verbose_level=100)\r
- else:\r
- recdblist.printutf8(u"×不明:"+t,verbose_level=100)\r
- elif opts.delete:##-Dの場合\r
- sa=auto_move.searchFile(recpath, recordedpath,".mkv")\r
- for t in sa:\r
- auto_move.execDelete(t, recpath)\r
- sa=auto_move.searchFile(recpath, recordedpath,".mp4")\r
- for t in sa:\r
- auto_move.execDelete(t, recpath)\r
- elif opts.list:##-lの場合\r
- sa=auto_move.searchFile(recpath, recordedpath,".mkv")\r
- for t in sa:\r
- sf=guess.searchFolder(t,recordedpath)\r
- if sf!="":\r
- recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mkv")+".mkv"),verbose_level=100)\r
- sa=auto_move.searchFile(recpath, recordedpath,".mp4")\r
- for t in sa:\r
- sf=guess.searchFolder(t,recordedpath)\r
- if sf!="":\r
- recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mp4")+".mp4"),verbose_level=100)\r
- elif opts.etitle!="":\r
- if os.path.exists(os.path.join(recpath, etitle+".mkv")):\r
- auto_move.execMove(etitle,recpath, recordedpath,".mkv",1)\r
- elif os.path.exists(os.path.join(recpath, etitle+".mp4")):\r
- auto_move.execMove(etitle,recpath, recordedpath,".mp4",1)\r
- elif opts.tssearch:## -tの場合\r
- tsmovepath=""\r
- try:\r
- tsmovepath=unicode(configreader.getConfPath("ts_movepath"),'utf-8')\r
- except:\r
- ""\r
- if tsmovepath!="":\r
- sa=auto_move.searchFile(recpath, tsmovepath,".ts")\r
- for t in sa:\r
- sf=guess.searchFolder(t,tsmovepath,700)\r
- if sf!="":\r
- recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".ts")+".ts"))\r
- print "\n"\r
- sa=auto_move.searchFile(recpath, tsmovepath,".ts")\r
- else:\r
- recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。",verbose_level=100)\r
- elif opts.tsmove:##-Tの場合\r
- tsmovepath=""\r
- try:\r
- tsmovepath=unicode(configreader.getConfPath("ts_movepath"),'utf-8')\r
- except:\r
- ""\r
- if tsmovepath!="":\r
- sa=auto_move.searchFile(recpath, tsmovepath,".ts")\r
- for t in sa:\r
- sf=guess.searchFolder(t,tsmovepath,700)\r
- if sf!="":\r
- recdblist.printutf8(u"移動先",verbose_level=100)\r
- recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".ts")+".ts"),verbose_level=100)\r
- recdblist.printutf8(u"実行中",verbose_level=100)\r
- auto_move.execMove(t, recpath, tsmovepath,".ts",0)\r
- sa=auto_move.searchFile(recpath, tsmovepath,".ts")\r
- else:\r
- recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。",verbose_level=100)\r
- elif opts.seriespath!="":##-Sの場合##与えられたパスにシリーズがそろっているかを調べる。\r
- ss=guess.detSeriesNum(opts.seriespath)\r
- for sstitle, ssv in ss.iteritems():\r
- if len(ssv)>0:\r
- maxt=0\r
- bt=0\r
- alr=[]\r
- for ssi,ssiv in ssv.iteritems():\r
- alr.append(ssi)\r
- if maxt<ssi:\r
- maxt=ssi\r
- alr=list(set(alr))\r
- alr.sort()\r
- alr.reverse()\r
- nuke=""\r
- for i in xrange(1,maxt+1,1):\r
- if alr.count(i)==0:\r
- nuke=nuke+str(i)+","\r
- if len(nuke)==0:\r
- recdblist.printutf8(sstitle+" "+str(maxt))\r
- else:\r
- recdblist.printutf8(u"**"+sstitle+" |"+str(maxt)+"| "+nuke)\r
+ 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 maxt<ssi:
+ maxt=ssi
+ alr=list(set(alr))
+ alr.sort()
+ alr.reverse()
+ nuke=""
+ for i in xrange(1,maxt+1,1):
+ if alr.count(i)==0:
+ nuke=nuke+str(i)+","
+ if len(nuke)==0:
+ recdblist.printutf8(sstitle+" "+str(maxt))
+ else:
+ recdblist.printutf8(u"**"+sstitle+" |"+str(maxt)+"| "+nuke)
-#!/usr/bin/python\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import ConfigParser\r
-import os\r
-import os.path\r
-mypath = str(os.path.dirname(os.path.abspath(__file__)))\r
-confp = ConfigParser.SafeConfigParser()\r
-Conf = 'rec10.conf'\r
-confpath=""\r
-if os.path.exists(os.path.join(mypath,Conf)):\r
- confpath=os.path.join(mypath,Conf)\r
-elif os.path.exists(os.path.join("/etc","rec10.conf")):\r
- confpath=os.path.join("/etc","rec10.conf")\r
-elif os.path.exists(os.path.join("/etc/rec10","rec10.conf")):\r
- confpath=os.path.join("/etc/rec10","rec10.conf")\r
-confp.read(confpath)\r
-def getConfPath(string):\r
- global confp\r
- return confp.get('path', string)\r
-def getConfDB(string):\r
- global confp\r
- return confp.get('db', string)\r
-def getConfEnv(string):\r
- global confp\r
- return confp.get('env', string)\r
-def getConfLog(string):\r
- global confp\r
- return confp.get('log', string)\r
-def getConfDVB(string):\r
- global confp\r
- return confp.get('dvb',string)\r
+#!/usr/bin/python
+# coding: UTF-8
+# Rec10 TS Recording Tools
+# Copyright (C) 2009-2011 Yukikaze
+import ConfigParser
+import os
+import os.path
+mypath = str(os.path.dirname(os.path.abspath(__file__)))
+confp = ConfigParser.SafeConfigParser()
+Conf = 'rec10.conf'
+confpath=""
+if os.path.exists(os.path.join(mypath,Conf)):
+ confpath=os.path.join(mypath,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")
+confp.read(confpath)
+def getConfPath(string):
+ global confp
+ return confp.get('path', string)
+def getConfDB(string):
+ global confp
+ return confp.get('db', string)
+def getConfEnv(string):
+ global confp
+ return confp.get('env', string)
+def getConfLog(string):
+ global confp
+ return confp.get('log', string)
+def getConfDVB(string):
+ global confp
+ return confp.get('dvb',string)
-#!/usr/bin/python\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import ConfigParser\r
-import os\r
-import os.path\r
-mypath = str(os.path.dirname(os.path.abspath(__file__)))\r
-confp = ConfigParser.SafeConfigParser()\r
-Conf = 'rec10.conf'\r
-confpath=os.path.join(mypath,Conf)\r
-confp.read(confpath)\r
-def getTempConfPath(string):\r
- global confp\r
- return confp.get('path', string)\r
-def setTempConfPath(option,value):\r
- global confp\r
- return confp.set('path',option,value)\r
-def setTempConfDB(option,value):\r
- global confp\r
- return confp.set('db',option,value)\r
-def setTempConfEnv(option,value):\r
- global confp\r
- return confp.set('env',option,value)\r
-def setTempConfDVB(option,value):\r
- global confp\r
- return confp.set('dvb',option,value)\r
-def writeTempConf():\r
- global confp\r
- f=open(confpath,"w")\r
- confp.write(f)\r
- f.close\r
+#!/usr/bin/python
+# coding: UTF-8
+# Rec10 TS Recording Tools
+# Copyright (C) 2009-2011 Yukikaze
+import ConfigParser
+import os
+import os.path
+mypath = str(os.path.dirname(os.path.abspath(__file__)))
+confp = ConfigParser.SafeConfigParser()
+Conf = 'rec10.conf'
+confpath=os.path.join(mypath,Conf)
+confp.read(confpath)
+def getTempConfPath(string):
+ global confp
+ return confp.get('path', string)
+def setTempConfPath(option,value):
+ global confp
+ return confp.set('path',option,value)
+def setTempConfDB(option,value):
+ global confp
+ return confp.set('db',option,value)
+def setTempConfEnv(option,value):
+ global confp
+ return confp.set('env',option,value)
+def setTempConfDVB(option,value):
+ global confp
+ return confp.set('dvb',option,value)
+def writeTempConf():
+ global confp
+ f=open(confpath,"w")
+ confp.write(f)
+ f.close
-#!/usr/bin/python\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import datetime\r
-import os\r
-import shutil\r
-import time\r
-import os.path\r
-import traceback\r
-\r
-import chdb\r
-import n_gram\r
-import rec10d\r
-import ts2epg\r
-import xml2db_dom\r
-import configreader\r
-import recdblist\r
-path = str(os.path.dirname(os.path.abspath(__file__))) + "/"\r
-tmppath = configreader.getConfPath("tmp")+"/"\r
-if tmppath=="/":\r
- tmppath=path\r
-if not os.path.exists(tmppath):\r
- os.mkdir(tmppath)\r
-def update(chtxt):\r
- recdblist.printutf8(chtxt)\r
- tnow = datetime.datetime.now()\r
- try:\r
- lastup = datetime.datetime.strptime(chdb.searchCHFromChtxt(chtxt)[0]['update'], "%Y-%m-%d %H:%M:%S")\r
- except:\r
- lastup = datetime.datetime.strptime("2009-04-01 00:00:00", "%Y-%m-%d %H:%M:%S")\r
- dt = tnow-lastup\r
- dt = dt.days * 24 * 60 + dt.seconds\r
- if dt > 2 * 60 * 60:\r
- ts2epg.writeEpgXML(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.searchCHFromChtxt(chtxt)['ch'])\r
- xml2db_dom.xml2db_dom(os.path.join(tmppath, chtxt + "epgdata.xml"), chdb.searchCHFromChtxt(chtxt)['bctype'])\r
-def updatebc(bctype):\r
- bctypel = chdb.searchCHFromBctype(bctype)\r
- #print bctype\r
- try:\r
- ts2epg.writeEpgXML(tmppath + bctype + "epgdata.xml", chdb.searchCHFromBctype(bctype)['ch'])\r
- xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.xml", bctype)\r
- shutil.copyfile(tmppath + bctype + "epgdata.xml", tmppath + bctype + "epgdata.bak.xml")\r
- time.sleep(5)\r
- rec10d.rec10db.update_by_bctype_epg_ch(bctype)\r
- except Exception, inst:\r
- recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200)\r
- xml2db_dom.xml2db_dom(tmppath + bctype + "epgdata.bak.xml", bctype)\r
- rec10d.rec10db.update_status_by_bctype_epg_ch(bctype, "2")\r
-def updateLogo_bc(bctype):\r
- bctypel = chdb.searchCHFromBctype(bctype)\r
- #print bctype\r
- try:\r
- ts2epg.writeLogoEpgXML(tmppath + bctype + "logo.xml", chdb.searchCHFromBctype(bctype)['ch'])\r
- xml2db_dom.xml2db_dom_logo(tmppath + bctype + "logo.xml", bctype)\r
- shutil.copyfile(tmppath + bctype + "logo.xml", tmppath + bctype + "logo.bak.xml")\r
- time.sleep(5)\r
- rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"1")\r
- except Exception, inst:\r
- recdblist.addCommonlogEX("Error","updatebc(epgdb.py)", str(type(inst)), str(inst)+"\n"+traceback.format_exc(),log_level=200)\r
- xml2db_dom.xml2db_dom(tmppath + bctype + "logo.bak.xml", bctype)\r
- rec10d.rec10db.update_logostatus_by_bctype_epg_ch(bctype,"2")\r
-def searchTime(titletxt, timet, deltatime, chtxt):\r
- time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")\r
- ret = []\r
- deltatime = int(deltatime)\r
- beforetime = time.strftime("%Y%m%d%H%M%S")\r
- beforetime = time - datetime.timedelta(hours=deltatime)\r
- aftertime = time + datetime.timedelta(hours=deltatime)\r
- beforetime = beforetime.strftime("%Y%m%d%H%M%S")\r
- aftertime = aftertime.strftime("%Y%m%d%H%M%S")\r
- one = ["", "", "", "","","",""]\r
- tempt = 0\r
- chtxtt=chtxt.replace("_0","_%")\r
- d = rec10d.rec10db.select_by_time_ngram_epg_timeline(beforetime, aftertime, chtxtt)\r
- for chtxtt, title, start, stop ,exp,longexp,category in d:\r
- #recdblist.printutf8(chtxtt+":"+title+":"+start+":"+stop)\r
- p = n_gram.bigram(titletxt, title)\r
- btime = start\r
- btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"\r
- etime = stop\r
- etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"\r
- bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")\r
- dt = bt-time\r
- dt = abs(dt)\r
- dt = 24 * 60 * 60 * dt.days + dt.seconds + 1\r
- p = p * 90\r
- dt = 1000-1000 * dt / (7 * 24 * 60 * 60)\r
- if p > 0:\r
- p = p + dt\r
- if p > tempt:\r
- one = [chtxtt, title, btime, etime,exp,longexp,category]\r
- tempt = p\r
- if p > 0:\r
- #recdblist.printutf8(title + ":" + str(p) + u"点")\r
- ""\r
- ret = one\r
- #print ret\r
- return ret\r
-def searchTimeAuto(keytxt, timet, deltatime):\r
- time = datetime.datetime.strptime(timet, "%Y-%m-%d %H:%M:%S")\r
- ret = []\r
- deltatime = int(deltatime)\r
- beforetime = time.strftime("%Y%m%d%H%M%S")\r
- aftertime = time + datetime.timedelta(hours=deltatime)\r
- aftertime = aftertime.strftime("%Y%m%d%H%M%S")\r
- d = rec10d.rec10db.select_by_time_keyword_auto_suggest_epg_timeline(keytxt,beforetime, aftertime)\r
- for chtxtt, title, start, stop ,exp,longexp,category in d:\r
- btime = start\r
- btime = btime[0:4] + "-" + btime[4:6] + "-" + btime[6:8] + " " + btime[8:10] + ":" + btime[10:12] + ":00"\r
- etime = stop\r
- etime = etime[0:4] + "-" + etime[4:6] + "-" + etime[6:8] + " " + etime[8:10] + ":" + etime[10:12] + ":00"\r
- ret.append([chtxtt, title, btime, etime,exp,longexp,category])\r
- return ret\r
-def countSchedule(btime,etime):\r
- """\r
- return rec num (int return[0]:TE /int return[1]:BS/CS)\r
- """\r
- def cmpare(x, y):\r
- xt = x\r
- yt = y\r
- if xt > yt:\r
- return -1\r
- elif xt == yt:\r
- return 0\r
- else:\r
- return 1\r
- dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime)\r
- times = []\r
- btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")\r
- etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")\r
- for dl in dls:\r
- dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S")\r
- dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S")\r
- if dd1 < btd:\r
- dd1 = btd\r
- if dd2 > etd:\r
- dd2 = etd\r
- times.append(dd1)\r
- times.append(dd2)\r
- times = list(set(times))\r
- times.sort(cmpare)\r
- times.reverse()\r
- retcount = [0, 0]\r
- for i in xrange(0, len(times)-2, 1):\r
- bt1 = times[i]\r
- et1 = times[i + 1]\r
- btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")\r
- etime1 = et1.strftime("%Y-%m-%d %H:%M:%S")\r
- ret1 = rec10d.rec10db.count_schedule_timeline(btime1, etime1)\r
- if retcount[0] < ret1[0]:\r
- retcount[0] = ret1[0]\r
- if retcount[1] < ret1[1]:\r
- retcount[1] = ret1[1]\r
- return retcount\r
-\r
-def searchSchedule(btime,etime):\r
- """\r
- return rec num (int return[0]:TE /int return[1]:BS/CS)\r
- """\r
- def cmpare(x, y):\r
- xt = x\r
- yt = y\r
- if xt > yt:\r
- return -1\r
- elif xt == yt:\r
- return 0\r
- else:\r
- return 1\r
- dls = rec10d.rec10db.select_bytime_all_timeline(btime, etime)\r
- times = []\r
- btd = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")\r
- etd = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")\r
- for dl in dls:\r
- dd1 = datetime.datetime.strptime(dl['btime'], "%Y-%m-%d %H:%M:%S")\r
- dd2 = datetime.datetime.strptime(dl['etime'], "%Y-%m-%d %H:%M:%S")\r
- if dd1 < btd:\r
- dd1 = btd\r
- if dd2 > etd:\r
- dd2 = etd\r
- times.append(dd1)\r
- times.append(dd2)\r
- times = list(set(times))\r
- times.sort(cmpare)\r
- times.reverse()\r
- ret=[]\r
- for i in xrange(0, len(times)-2, 1):\r
- bt1 = times[i]\r
- et1 = times[i + 1]\r
- btime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")\r
- etime1 = et1.strftime("%Y-%m-%d %H:%M:%S")\r
- ret1 = rec10d.rec10db.search_schedule_timeline(btime1, etime1)\r
- ret.append(ret1)\r
- ret = list(set(ret))\r
- return ret\r
-\r
-def countEpgSchedule(epgbtime,epgetime):\r
- """\r
- return rec num (int return[0]:TE /int return[1]:BS/CS)\r
- """\r
- def cmpare(x, y):\r
- xt = x\r
- yt = y\r
- if xt > yt:\r
- return -1\r
- elif xt == yt:\r
- return 0\r
- else:\r
- return 1\r
- dls = rec10d.rec10db.select_byepgtime_over_timeline(epgbtime, epgetime)\r
- #print dls\r
- times = []\r
- btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S")\r
- etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S")\r
- for dl in dls:\r
- dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S")\r
- dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S")\r
- if dd1 < btd:\r
- dd1 = btd\r
- if dd2 > etd:\r
- dd2 = etd\r
- times.append(dd1)\r
- times.append(dd2)\r
- times = list(set(times))\r
- times.sort(cmpare)\r
- times.reverse()\r
- retcount = [0, 0]\r
- for i in xrange(0, len(times)-1, 1):\r
- bt1 = times[i]\r
- et1 = times[i + 1]\r
- epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")\r
- epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S")\r
- ret1 = rec10d.rec10db.count_epgschedule_timeline(epgbtime1, epgetime1)\r
- if retcount[0] < ret1[0]:\r
- retcount[0] = ret1[0]\r
- if retcount[1] < ret1[1]:\r
- retcount[1] = ret1[1]\r
- return retcount\r
-def searchEpgSchedule(epgbtime,epgetime):\r
- """\r
- return rec num (int return[0]:TE /int return[1]:BS/CS)\r
- """\r
- def cmpare(x, y):\r
- xt = x\r
- yt = y\r
- if xt > yt:\r
- return -1\r
- elif xt == yt:\r
- return 0\r
- else:\r
- return 1\r
- dls = rec10d.rec10db.select_byepgtime_all_timeline(epgbtime, epgetime)\r
- times = []\r
- btd = datetime.datetime.strptime(epgbtime, "%Y-%m-%d %H:%M:%S")\r
- etd = datetime.datetime.strptime(epgetime, "%Y-%m-%d %H:%M:%S")\r
- for dl in dls:\r
- dd1 = datetime.datetime.strptime(dl['epgbtime'], "%Y-%m-%d %H:%M:%S")\r
- dd2 = datetime.datetime.strptime(dl['epgetime'], "%Y-%m-%d %H:%M:%S")\r
- if dd1 < btd:\r
- dd1 = btd\r
- if dd2 > etd:\r
- dd2 = etd\r
- times.append(dd1)\r
- times.append(dd2)\r
- times = list(set(times))\r
- times.sort(cmpare)\r
- times.reverse()\r
- ret=[]\r
- for i in xrange(0, len(times)-2, 1):\r
- bt1 = times[i]\r
- et1 = times[i + 1]\r
- epgbtime1 = bt1.strftime("%Y-%m-%d %H:%M:%S")\r
- epgetime1 = et1.strftime("%Y-%m-%d %H:%M:%S")\r
- ret1 = rec10d.rec10db.search_epgschedule_timeline(epgbtime1, epgetime1)\r
- ret.append(ret1)\r
- ret = list(set(ret))\r
- return ret\r
+#!/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
-#!/usr/bin/python\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import time\r
-import os.path\r
-import ConfigParser\r
-import sys\r
-import commands\r
-import configwriter\r
-import shutil\r
-import traceback\r
-\r
-import recdblist\r
-def printutf8(str):\r
- print str.encode('utf-8')\r
-def install():\r
- version = recdblist.version\r
- recdblist.printutf8(u"rec10の環境インストールを開始します。",verbose_level=100)\r
- time.sleep(1)\r
- recdblist.printutf8(u"環境インストール処理中・・・",verbose_level=100)\r
- path = str(os.path.dirname(os.path.abspath(__file__)))\r
- confp = ConfigParser.SafeConfigParser()\r
- Conf = 'rec10.conf'\r
- confpath=""\r
- if os.path.exists(os.path.join(path,Conf)):\r
- confpath=os.path.join(path,Conf)\r
- elif os.path.exists(os.path.join("/etc","rec10.conf")):\r
- confpath=os.path.join("/etc","rec10.conf")\r
- elif os.path.exists(os.path.join("/etc/rec10","rec10.conf")):\r
- confpath=os.path.join("/etc/rec10","rec10.conf")\r
- if confpath!="":\r
- confp.read(confpath)\r
- else:\r
- recdblist.printutf8(u"rec10.confが見つかりません。",verbose_level=100)\r
- recdblist.printutf8(u"このinstall.pyと同じフォルダに置くか、/etc/rec10.confもしくは/etc/rec10/rec10.confにおいてください。",verbose_level=100)\r
- sys.exit(1)\r
- recdblist.printutf8(u"設定ファイルの読み込みを確認//設定ファイルのパスは"+confpath,verbose_level=100)\r
- if confp.get('path',"recpath")=="/path of /recording":\r
- recdblist.printutf8(u"録画先のフォルダを設定してください(recpath=)",verbose_level=100)\r
- sys.exit(1)\r
- recdblist.printutf8(u"DB処理に入ります",verbose_level=100)\r
- if os.path.exists(os.path.join(path,"rec10d.py")):\r
- try:\r
- update_db_all()\r
- except Exception, inst:\r
- recdblist.printutf8(u"DB処理中にエラーが出ました。configファイルのDB設定を見直してください。",verbose_level=100)\r
- recdblist.printutf8(str(type(inst)),verbose_level=100)\r
- recdblist.printutf8(str(inst)+"\n"+traceback.format_exc(),verbose_level=100)\r
- import rec10d\r
- rec10d.rec10db.change_installed_in_status()\r
- recdblist.printutf8(u"チャンネル設定に入ります",verbose_level=100)\r
- import scan_ch\r
- rec10d.rec10db.new_epg_ch()\r
- recdblist.printutf8(u"チャンネルスキャンの開始",verbose_level=100)\r
- scan_ch.searchCh()\r
- rec10d.rec10db.change_installed_in_status(100)\r
- recdblist.printutf8(u"おめでとうございます 初期設定は完了しました。",verbose_level=100)\r
- recdblist.printutf8(u"rec10を実行するユーザーのcrontabに"+os.path.join(path,"rec10")+u"を追加してください(5分周期が目安)",verbose_level=100)\r
- sys.exit(1)\r
-def getLocalPath(cmd,exit=1):\r
- printutf8(cmd+u"の場所を確認中")\r
- txt=commands.getoutput(u"which "+cmd)\r
- if len(txt.split(" "))>3:\r
- if exit==1:\r
- printutf8(cmd+u"の場所を確認できませんでした。終了します")\r
- sys.exit(1)\r
- else:\r
- return ""\r
- else:\r
- printutf8(cmd+u" : "+txt)\r
- if len(txt.splitlines()):\r
- txt=txt.splitlines()[0]\r
- return txt.strip()\r
-def move():\r
- useB=0\r
- path = str(os.path.dirname(os.path.abspath(__file__)))\r
- printutf8(u"rec10 ver "+recdblist.version_str+" installer.")\r
- printutf8(u"rec10のインストールを開始します。")\r
- maxn=16\r
- configwriter.setTempConfPath(u"wine", getLocalPath(u"wine"))\r
- configwriter.setTempConfPath(u"recpt1", getLocalPath(u"recpt1",exit=0))\r
- #configwriter.setpath(u"x264", getLocalPath(u"x264"))\r
- configwriter.setTempConfPath(u"mp4box", getLocalPath(u"MP4Box",exit=0))\r
- configwriter.setTempConfPath(u"mencoder", getLocalPath(u"mencoder"))\r
- configwriter.setTempConfPath(u"ffmpeg", getLocalPath(u"ffmpeg"))\r
- configwriter.setTempConfPath(u"mkvmerge", getLocalPath(u"mkvmerge",exit=0))\r
- configwriter.setTempConfPath(u"lame", getLocalPath(u"lame",exit=0))\r
- configwriter.setTempConfPath(u"b25", getLocalPath(u"b25"))\r
- configwriter.setTempConfPath(u"tee", getLocalPath(u"tee"))\r
- configwriter.setTempConfPath(u"java", getLocalPath(u"java"))\r
-\r
- try:\r
- configwriter.setTempConfPath(u"lame", getLocalPath(u"lame"))\r
- except:\r
- printutf8(u"lameが見つかりません(NeroAacEncを導入する場合は問題ありません)")\r
- printutf8(u"必須環境の設定が完了しました")\r
- printutf8(u"個人設定に入ります")\r
- if os.path.exists("/etc/rec10.conf"):\r
- printutf8(u"以前の設定ファイルが見つかりました。")\r
- printutf8(u"インポートしますか?")\r
- useB=raw_input("[Y/n]:")\r
- if useB=="N" or useB == "n":\r
- useB=0\r
- else:\r
- useB=1\r
- printutf8(u"設定ファイルのインポートを行います。")\r
- printutf8(u"rec10の録画ファイルが置かれる場所を入力してください(1/"+str(maxn)+")")\r
- printutf8(u"100GB程度は確保されている必要があります")\r
- recpath=getConf(useB,"/etc/rec10.conf","path","recpath","path : ")\r
- configwriter.setTempConfPath(u"recpath",recpath)\r
- printutf8(u"DBの設定に入ります。")\r
- printutf8(u"rec10が使用するMySQLのユーザーを設定してください。(2/"+str(maxn)+")")\r
- mysql_user=getConf(useB,"/etc/rec10.conf","db","mysql_user","mysql_user : ")\r
- configwriter.setTempConfDB("mysql_user", mysql_user)\r
- printutf8(u"パスワードを設定してください(3/"+str(maxn)+")")\r
- mysql_passwd=getConf(useB,"/etc/rec10.conf","db","mysql_passwd","mysql_passwd : ")\r
- configwriter.setTempConfDB("mysql_passwd", mysql_passwd)\r
- printutf8(u"BS/CSの設定に入ります")\r
- printutf8(u"BS/CS(110度CS,スカパーe2)を受信しますか(4/"+str(maxn)+")")\r
- useBSCS=raw_input("[Y/n]:")\r
- if useBSCS=="N" or useBSCS=="n" or useBSCS=="no" or useBSCS=="NO":\r
- useBSCS="0"\r
- else:\r
- useBSCS="1"\r
- printutf8(u"ドライバの設定に入ります")\r
- printutf8(u"DVB版のドライバを使用しますか(earth_pt1など。chardev版を使う場合はNo)(5/"+str(maxn)+")")\r
- useDVB=raw_input("[y/N]:")\r
- if useDVB=="Y" or useDVB=="y" or useDVB=="yes" or useDVB=="YES":\r
- useDVB="1"\r
- else:\r
- useDVB="0"\r
- configwriter.setTempConfDVB("useDVB", useDVB)\r
- if useDVB=="1":\r
- printutf8(u"DVBの設定に入ります")\r
- printutf8(u"DVBAdapterの場所を設定して下さい")\r
- printutf8(u"/dev/dvb/adapterなどdvr0の上のフォルダ(番号の前まで)を指定して下さい。")\r
- getConf(useB,"/etc/rec10.conf","dvb","DVBadapter","/dev/dvb/adapter")\r
- printutf8(u"地デジを受信可能なアダプタ番号を入力して下さい(1,3のように','で区切って下さい)")\r
- getConf(useB,"/etc/rec10.conf","dvb","DVBTE","1,3")\r
- if useBSCS=="1":\r
- printutf8(u"BS/CSを受信可能なアダプタ番号を入力して下さい(0,2のように','で区切って下さい)")\r
- getConf(useB,"/etc/rec10.conf","dvb","DVBBSCS","0,2")\r
- else:\r
- configwriter.setTempConfDVB("DVBBSCS","")\r
- printutf8(u"同時録画可能数の設定に入ります")\r
- printutf8(u"TE(地デジ)録画可能数(PT*だと2 白Friioだと1)(6/"+str(maxn)+")")\r
- te_max=str(int(getConf(useB,"/etc/rec10.conf","env","te_max","te_max : ")))\r
- configwriter.setTempConfEnv("te_max", te_max)\r
- if useBSCS=="1":\r
- printutf8(u"BS/CS110録画可能数(PT*だと2 黒Friioだと1)(7/"+str(maxn)+")")\r
- bscs_max=str(int(getConf(useB,"/etc/rec10.conf","env","bscs_max","bscs_max : ")))\r
- configwriter.setTempConfEnv("bscs_max", bscs_max)\r
- else:\r
- configwriter.setTempConfEnv("bscs_max", "0")\r
- printutf8(u"同時エンコード最大数を設定してください(8/"+str(maxn)+")")\r
- printutf8(u"CPUのコア数が目安です")\r
- enc_max=raw_input("[2]:")\r
- if enc_max=="":\r
- enc_max="2"\r
- else:\r
- enc_max=str(int(enc_max))\r
- configwriter.setTempConfEnv("enc_max", enc_max)\r
- printutf8(u"二カ国語放送/5.1ch放送の音声変換の設定です。\nNeroAACエンコーダーを使用しますか?(NeroAACEncを別途入手してtstoolsに入れてください。))")\r
- printutf8(u"入手先:http://www.nero.com/jpn/technologies-aac-codec.html\n (9/"+str(maxn)+")")\r
- audioenc=raw_input("[y/N]: ")\r
- if audioenc=="y" or audioenc=="Y":\r
- configwriter.setTempConfPath("useNeroAAC", "1")\r
- aacpath=getLocalPath(u"neroAacEnc",exit=0)\r
- if len(aacpath)<2:\r
- printutf8(u"NeroAACEncのパスを指定してください")\r
- aacpath=getConf(useB,"/etc/rec10.conf","path","NeroAAC","[/usr/local/bin/neroAacEnc] : ")\r
- if aacpath.replace(" ","")=="":\r
- aacpath="/usr/local/bin/neroAacEnc"\r
- configwriter.setTempConfPath("NeroAAC",aacpath)\r
- else:\r
- configwriter.setTempConfPath("useNeroAAC", "0")\r
- aacpath="/usr/local/bin/neroAacEnc"\r
- configwriter.setTempConfPath("NeroAAC",aacpath)\r
- printutf8(u"lameを使用します。")\r
- printutf8(u"x264のパスを指定してください(10/"+str(maxn)+")")\r
- x264path=getConf(useB,"/etc/rec10.conf","path","x264","x264 path : ")\r
- if x264path.replace(" ","")=="" or not os.path.isfile(x264path):\r
- x264path=getLocalPath(u"x264")\r
- configwriter.setTempConfPath("x264",x264path)\r
- printutf8(u"保存する画質を教えてください(11/"+str(maxn)+")")\r
- printutf8(u"x264のcrfの値です。標準だと30分で800MBほどになります")\r
- crf=getConf(useB,"/etc/rec10.conf","env","crf","[24] : ")\r
- if crf.replace(" ","")=="":\r
- crf="24"\r
- configwriter.setTempConfEnv("crf", crf)\r
- printutf8(u"アニメーションを保存する画質を教えてください(12/"+str(maxn)+")")\r
- printutf8(u"x264のcrfの値です。標準だと30分で800MBほどになります")\r
- a_crf=getConf(useB,"/etc/rec10.conf","env","animation_crf","[20] : ")\r
- if a_crf.replace(" ","")=="":\r
- a_crf="20"\r
- configwriter.setTempConfEnv("animation_crf", a_crf)\r
- printutf8(u"x264の圧縮率を設定してください(13/"+str(maxn)+")")\r
- printutf8(u"x264のpresetの値です。標準だとmedium、小さければ小さいほど高圧縮になります")\r
- preset=getConf(useB,"/etc/rec10.conf","env","x264_preset","[4] : ")\r
- if preset.replace(" ","")=="":\r
- preset="4"\r
- configwriter.setTempConfEnv("x264_preset", preset)\r
- printutf8(u"保存するコンテナの設定(14/"+str(maxn)+")")\r
- printutf8(u"MP4を標準にしますか(もしくはMKVが使えます)")\r
- useMP4=raw_input("[Y/n]:")\r
- if useMP4=="N" or useMP4 == "n" :\r
- useMP4="0"\r
- else:\r
- useMP4="1"\r
- configwriter.setTempConfEnv("make_mp4", useMP4)\r
- printutf8(u"TSファイルの自動削除(15/"+str(maxn)+")")\r
- printutf8(u"中間体のtsファイルを削除しますか")\r
- printutf8(u"(削除するとやり直しができないため残しておくことを推奨します。)")\r
- removeTS=raw_input("[y/N]:")\r
- if removeTS=="Y" or removeTS == "y" :\r
- removeTS="1"\r
- else:\r
- removeTS="0"\r
- configwriter.setTempConfEnv("remove_ts", removeTS)\r
- printutf8(u"自機識別オプション(16/"+str(maxn)+")")\r
- printutf8(u"本rec10の識別名を入力してください")\r
- printutf8(u"複数台のrec10を運用する場合に効果的です。空白でもかまいません。")\r
- printutf8(u"例 kobe01")\r
- iff=getConf(useB,"/etc/rec10.conf","env","iff","[] : ")\r
- configwriter.setTempConfEnv("iff", iff)\r
- confp = ConfigParser.SafeConfigParser()\r
- confp.read("/etc/rec10.conf")\r
- if useB:\r
- configwriter.setTempConfPath("recorded",confp.get("path","recorded"))\r
- configwriter.setTempConfPath("move_destpath",confp.get("path","move_destpath"))\r
- configwriter.setTempConfPath("tmp",confp.get("path","tmp"))\r
- try:\r
- configwriter.setTempConfEnv("x264_addline",confp.get("env","x264_addline"))\r
- except:\r
- configwriter.setTempConfEnv("x264_addline","")\r
- if confp.get("path","b25_remote")=="":\r
- configwriter.setTempConfPath("b25_remote", "0")\r
- elif confp.get("path","b25_remote")=="1":\r
- configwriter.setTempConfPath("b25_remote", confp.get("path","b25_remote"))\r
- configwriter.setTempConfPath("b25", confp.get("path","b25"))\r
- configwriter.setTempConfPath("b25_env", confp.get("path","b25_env"))\r
- else:\r
- configwriter.setTempConfPath("b25_remote", confp.get("path","b25_remote"))\r
-\r
- configwriter.writeTempConf()\r
- printutf8(u"初期設定が終了しました。")\r
- printutf8(u"makeを実行した後にrootにてmake installを実行するとインストールされます。")\r
-def getConf(useBeforeConf,Confpath,dbsection,key,defaultstr):\r
- tstr=defaultstr\r
- if os.path.exists(Confpath) and useBeforeConf==1:\r
- try:\r
- confp = ConfigParser.SafeConfigParser()\r
- confp.read("/etc/rec10.conf")\r
- tstr=u"["+confp.get(dbsection,key)+u"]:"\r
- except:\r
- tstr=defaultstr\r
- tmpconf=raw_input(tstr)\r
- if tmpconf.replace(" ","")=="" and os.path.exists(Confpath) and useBeforeConf==1 :\r
- confp = ConfigParser.SafeConfigParser()\r
- confp.read("/etc/rec10.conf")\r
- try:\r
- tmpconf=confp.get(dbsection,key)\r
- except:\r
- tmpconf=""\r
- return tmpconf\r
-def update_db_all():\r
- import rec10d\r
- tversion=0\r
- if rec10d.rec10db.select_installed_in_status()==1:\r
- if rec10d.rec10db.select_version_in_status()==0:\r
- tversion=0\r
- recdblist.printutf8(u"既存のDBが見つかりました。0.9.1と仮定してアップデート処理を行います。",verbose_level=100)\r
- update_db(0)\r
- time.sleep(1)\r
- else:\r
- recdblist.printutf8(u"既存のDBが見つかりました。アップデート処理を行います。",verbose_level=100)\r
- tversion=int(rec10d.rec10db.select_version_in_status())\r
- while (recdblist.version>tversion):\r
- update_db(tversion)\r
- tversion=int(rec10d.rec10db.select_version_in_status())\r
- else:\r
- rec10d.rec10db.drop_in_status()\r
- rec10d.rec10db.drop_in_settings()\r
- time.sleep(2)\r
- rec10d.rec10db.new_in_status()\r
- rec10d.rec10db.new_in_settings()\r
- rec10d.rec10db.change_version_in_status(recdblist.version)\r
-def update_db(version):\r
- import rec10d\r
- if version==0:\r
- rec10d.rec10db.update_db_to93()\r
- elif version==93:\r
- rec10d.rec10db.update_db_93to94()\r
- elif version==94:\r
- rec10d.rec10db.update_db_94to95()\r
- elif version==95:\r
- rec10d.rec10db.update_db_95to96()\r
- elif version==96:\r
- rec10d.rec10db.update_db_96to98()\r
- elif version==98:\r
- rec10d.rec10db.update_db_98to100()\r
- elif version==100:\r
- rec10d.rec10db.update_db_100to101()\r
- elif version==101:\r
- rec10d.rec10db.update_db_100to102()\r
-if __name__ == "__main__":\r
- move()\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import os\r
-import os.path\r
-import warnings\r
-warnings.filterwarnings('ignore', "the sets module is deprecated")\r
-import configreader\r
-import dbMySQL\r
-import timerec\r
-path = str(os.path.dirname(os.path.abspath(__file__))) + "/"\r
-tmppath = configreader.getConfPath("tmp")+"/"\r
-if tmppath=="/":\r
- tmppath=path\r
-if not os.path.exists(tmppath):\r
- os.makedirs(tmppath)\r
-global rec10db\r
-def main():\r
- timerec.task()\r
-db = configreader.getConfDB("db")\r
-if db == "MySQL":\r
- dbn = configreader.getConfDB("mysql_dbname")\r
- dbh = configreader.getConfDB("mysql_host")\r
- dbu = configreader.getConfDB("mysql_user")\r
- dbpwd = configreader.getConfDB("mysql_passwd")\r
- dbport = int(configreader.getConfDB("mysql_port"))\r
- rec10db = dbMySQL.DB_MySQL(dbname=dbn, host=dbh, user=dbu, passwd=dbpwd, port=dbport)\r
- rec10db.new_in_status()\r
-else:\r
- rec10db = dbSQLite.DB_SQLite(path + "ch.db")\r
-if __name__ == "__main__":\r
- main()\r
-\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import chdb\r
-import n_gram\r
-import rec10d\r
-import recdblist\r
-\r
-def reserveKeyword(keyword, chtxt, btime, etime, deltatime, opt):\r
- rec10d.rec10db.add_timeline(type=recdblist.REC_KEYWORD, chtxt=chtxt, title=keyword, btime=btime, etime=etime, deltatime=deltatime, opt=opt)\r
-def reserveEverydayKeyword(keyword, chtxt, btime, etime, deltatime, opt, deltaday,count):\r
- tcount=count\r
- if tcount<0:\r
- tcount=-1\r
- 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)\r
-def reserveReckey(type, title, chtxt, btime, etime, opt):\r
- rec10d.rec10db.add_timeline(type=type, chtxt=chtxt, title=title, btime=btime, etime=etime, opt=opt)\r
-def deleteReckey(type, title, chtxt, btime):\r
- rec10d.rec10db.del_timeline(type=type, title=title, chtxt=chtxt, btime=btime)\r
-def reserveAutoKeyword(chtxt,title,btime,etime):\r
- rec10d.rec10db.add_auto_timeline_keyword(chtxt, title, btime, etime)\r
-def addAutoBayesKeyword(chtxt,title,btime,etime,point):\r
- rec10d.rec10db.add_auto_timeline_bayes(chtxt, title, btime, etime,point)\r
-def getProgramsInTheseHours(dhour):\r
- dhour = int(dhour)\r
- dminutes = 60 * dhour\r
- dminutes = str(dminutes)\r
- return rec10d.rec10db.select_bytime_timeline(dminutes)\r
-def getProgramsInTheseMinutes(dminutes):\r
- return rec10d.rec10db.select_bytime_timeline(dminutes)\r
-def countRecNow(dhour):\r
- d = getProgramsInTheseHours(dhour)\r
- ret = 0\r
- for i in d:\r
- t = i['type']\r
- if t == "key" or t == "keyevery" or t == "rec" or t == "res":\r
- ret = ret + 1\r
- return ret\r
-def countRecNow_minutes(dminutes):\r
- d = getProgramsInTheseMinutes(dminutes)\r
- ret = 0\r
- for i in d:\r
- t = i['type']\r
- if t == "key" or t == "keyevery" or t == "rec" or t == "res":\r
- ret = ret + 1\r
- return ret\r
-def countRecNow_minutes_BSCS(dminutes):\r
- d = getProgramsInTheseMinutes(dminutes)\r
- ret = 0\r
- for i in d:\r
- t = i['type']\r
- if t == "key" or t == "keyevery" or t == "rec" or t == "res":\r
- if len(chdb.searchCHFromChtxt(i['chtxt'])['ch']) > 2:\r
- ret = ret + 1\r
- return ret\r
-def countRecNow_minutes_TE(dminutes):\r
- d = getProgramsInTheseMinutes(dminutes)\r
- ret = 0\r
- for i in d:\r
- t = i['type']\r
- if t == "key" or t == "keyevery" or t == "rec" or t == "res":\r
- if len(chdb.searchCHFromChtxt(i['chtxt'])['ch']) < 3:\r
- ret = ret + 1\r
- return ret\r
-def deleteOldProgramBeforeTheseHours(dhour):\r
- """\r
- delete keys except recdblist.REC_MISS_ENCODE and recdblist.REC_KEYWORD_EVERY_SOME_DAYS before dhour hours from now.\r
- """\r
- rec10d.rec10db.delete_old_timeline(dhour)\r
-def delete_old_auto_keyword(dhour):\r
- rec10d.rec10db.delete_old_auto_timeline_keyword(dhour)\r
-def delete_old_auto_bayes(dhour):\r
- rec10d.rec10db.delete_old_auto_timeline_bayes(dhour)\r
-def getAll():\r
- return rec10d.rec10db.select_all_timeline()\r
-def addRecLogProgram(title,chtxt,btime,etime,opt,exp,longexp,category):\r
- rec10d.rec10db.add_in_timeline_log(chtxt,title,btime,etime,opt,exp,longexp,category)\r
-def getAllJbkKeyword():\r
- return rec10d.rec10db.select_all_in_auto_jbk_key()\r
-def checkDuplicated(title,chtxt,epgbtime,epgetime):\r
- tl=rec10d.rec10db.select_byepgtime_all_timeline(epgbtime,epgetime)\r
- nel=rec10d.rec10db.select_bytime_all_timeline(epgbtime, epgetime)\r
- dup=0\r
- for t in tl:\r
- if t["title"]==title and t["chtxt"]==chtxt:\r
- dup=1\r
- elif n_gram.trigram(t["title"],title)> 500 and t["chtxt"]==chtxt:\r
- dup=1\r
- for t in nel:\r
- if t["title"]==title and t["chtxt"]==chtxt:\r
- dup=1\r
- elif n_gram.trigram(t["title"],title)> 500 and t["chtxt"]==chtxt:\r
- dup=1\r
- return dup\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-\r
-"""\r
-task names\r
-"""\r
-import datetime\r
-import os\r
-import os.path\r
-import traceback\r
-\r
-import configreader\r
-\r
-global REC_RESERVE\r
-global REC_FINAL_RESERVE\r
-global REC_ENCODE_GRID\r
-global REC_ENCODE_LOCAL\r
-global REC_ENCODE_QUE\r
-global REC_MISS_ENCODE\r
-global REC_KEYWORD\r
-global REC_KEYWORD_EVERY_SOME_DAYS\r
-global REC_FIN_LOCAL\r
-global REC_MISS_DECODE\r
-global REC_TS_DECODE_QUE\r
-global REC_TS_DECODING\r
-global REC_TS_RECORDING\r
-global REC_AVI_TO_MKV\r
-global REC_AVI_TO_MP4\r
-global REC_MKV_TO_MP4\r
-global REC_CHANGING_CANTAINER\r
-\r
-#ここから処理のちに移動\r
-\r
-global REC_MOVE_END\r
-\r
-#ここから自動で提起される処理。\r
-global REC_AUTO_SUGGEST_REC\r
-global REC_AUTO_SUGGEST_DECODE\r
-global REC_AUTO_SUGGEST_ENCODE\r
-global REC_AUTO_SUGGEST_AVI2MP4\r
-global REC_AUTO_SUGGEST_MKV2MP4\r
-global REC_AUTO_SUGGEST_AVI2FP\r
-global REC_AUTO_SUGGEST_AP2FP\r
-global REC_BAYES_SUGGEST\r
-global REC_AUTO_KEYWORD\r
-REC_RESERVE = "reserve_flexible"\r
-REC_FINAL_RESERVE = "reserve_fixed"\r
-REC_ENCODE_GRID = "convert_ts_mp4_network"\r
-REC_ENCODE_LOCAL = "convert_ts_mp4_running"\r
-REC_ENCODE_QUE = "convert_ts_mp4"\r
-REC_MISS_ENCODE = "convert_avi_mp4_miss"\r
-REC_KEYWORD = "search_today"\r
-REC_KEYWORD_EVERY_SOME_DAYS = "search_everyday"\r
-REC_FIN_LOCAL = "convert_ts_mp4_finished"\r
-REC_MISS_DECODE = "convert_b25_ts_miss"\r
-REC_TS_DECODE_QUE = "convert_b25_ts"\r
-REC_TS_DECODING = "convert_b25_ts_running"\r
-REC_TS_RECORDING = "reserve_running"\r
-REC_CHANGING_CANTAINER = "convert_mkv_mp4_runnings"\r
-REC_AVI_TO_MKV = "convert_avi_mkv"\r
-REC_AVI_TO_MP4 = "convert_avi_mp4"\r
-REC_MKV_TO_MP4 = "convert_mkv_mp4"\r
-\r
-REC_MOVE_END = "move_end"\r
-\r
-REC_AUTO_SUGGEST_REC = "auto_suggest_rec"\r
-REC_AUTO_SUGGEST_DECODE = "auto_suggest_dec"\r
-REC_AUTO_SUGGEST_ENCODE = "auto_suggest_enc"\r
-REC_AUTO_SUGGEST_AVI2FP = "auto_suggest_avi2fp"\r
-REC_AUTO_SUGGEST_AP2FP = "auto_suggest_ap2fp"\r
-REC_AUTO_KEYWORD = "auto_keyword"\r
-REC_BAYES_SUGGEST ="bayes_suggest"\r
-\r
-global BONTSDEMUX_DELAY\r
-BONTSDEMUX_DELAY="0"\r
-\r
-version = 102\r
-version_str="0.9.10"\r
-\r
-global verbose_level_now\r
-global log_level_now\r
-\r
-try:\r
- log_level_now=int(configreader.getConfLog("log_level"))\r
- verbose_level_now=int(configreader.getConfLog("verbose_level"))\r
-except:\r
- log_level_now=900\r
- verbose_level_now=400\r
-\r
-os.environ['LANG'] = "ja_JP.UTF-8"\r
-my_env = os.environ\r
-my_env['LANG'] = "ja_JP.UTF-8"\r
-\r
-def getEnv():\r
- return my_env\r
-def printutf8(unicode,verbose_level=500):\r
- if verbose_level_now > verbose_level:\r
- try:\r
- str=unicode.encode('utf-8')\r
- print str\r
- except Exception, inst:\r
- recdblist.addCommonlogEX("Error", "printutf8(recdblist.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)\r
-def printutf8ex(unicode,verbose_level=500,log_level=500):\r
- str=unicode.encode('utf-8')\r
- if verbose_level_now > verbose_level:\r
- print str\r
- logfname="/var/log/rec10"\r
- mode="a"\r
- if log_level_now > log_level:\r
- if os.path.exists(logfname):\r
- f=open(logfname,mode)\r
- f.write(str+"\n")\r
- f.close()\r
-def printutf8_Important(unicode):\r
- printutf8ex(unicode,100,100)\r
-def printutf8_Normal(unicode):\r
- printutf8ex(unicode,300,300)\r
-def printutf8_Detailed(unicode):\r
- printutf8ex(unicode,600,600)\r
-def addCommonlogEX(type,place,inst,txt,verbose_level=500,log_level=500):\r
- lt=unicode(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))+u":"\r
- if txt=="":\r
- lt=lt+u"["+type+u"] "+place+u" "+inst\r
- else:\r
- try:\r
- lt=lt+u"["+type+u"] "+place+u" "+inst+u"\n"+txt\r
- except:\r
- print [type,place,inst,txt]\r
- lt=lt.encode('utf-8')\r
- logfname="/var/log/rec10"\r
- mode="a"\r
- if verbose_level_now > verbose_level:\r
- print lt\r
- if log_level_now > log_level:\r
- if os.path.exists(logfname):\r
- f=open(logfname,mode)\r
- f.write(lt+"\n")\r
- f.close()\r
-def addCommandLog(tspath,log_title,cmd,cmd_log=""):\r
- addLog(tspath,cmd,log_title+u"ログ-コマンド")\r
- addLog(tspath,cmd_log,log_title+u"ログ-詳細")\r
-def addCommandLogZip(tspath,log_title,log_filename_add,cmd,cmd_log=""):\r
- logtitle=getLogTitle(tspath)\r
- logo=logtitle+"."+log_filename_add+".log"\r
- logzip=logtitle+".log.zip"\r
- addLogAll(tspath,cmd+"\n\n"+cmd_log,log_title,logo)\r
- import zip\r
- zip.addFile2FileZip(logo,logzip)\r
- os.remove(logo)\r
-def addCommandSelfLog(tspath,command):\r
- logpath=getLogTitle(tspath)+".command.log"\r
- f=""\r
- if os.path.exists(logpath):\r
- f=open(logpath,'a')\r
- else:\r
- f=open(logpath,'w')\r
- tc=command+u"\n\n"\r
- tc=unicode(tc)\r
- f.write(tc.encode("utf-8"))\r
- #f.write(tc.encode('utf-8','ignore'))\r
- f.close()\r
-def getLogTitle(tspath):\r
- logo=tspath\r
- logo=logo.replace("_1.wav",".ts")\r
- logo=logo.replace("_2.wav",".ts")\r
- logo=logo.replace("_1.aac",".ts")\r
- logo=logo.replace("_2.aac",".ts")\r
- logo=logo.replace("_1.mp3",".ts")\r
- logo=logo.replace("_2.mp3",".ts")\r
- logo=logo.replace(".ts.tsmix",".ts")\r
- logo=logo.replace(".ts.b25",".ts")\r
- logo=logo.replace(".sa.avi",".ts")\r
- logo=logo.replace(".m2v",".ts")\r
- logo=logo.replace(".avi",".ts")\r
- logo=logo.replace(".mkv",".ts")\r
- logo=logo.replace(".wav",".ts")\r
- logo=logo.replace(".mp4",".ts")\r
- logo=logo.replace(".mp3",".ts")\r
- logo=logo.replace(".aac",".ts")\r
- logo=logo.replace(".srt",".ts")\r
- logo=logo.replace(".264",".ts")\r
- logo=logo.replace(".ts","")\r
- return logo\r
-def addLog(tspath,txt,log_title,maxtextlength=1500):\r
- logo=getLogTitle(tspath)+".log"\r
- f=open(logo,'a')\r
- s=len(txt)\r
- stxt=""\r
- if s>maxtextlength*2 and maxtextlength>0:\r
- stxt=txt[0:maxtextlength]+"\n\n(ry..)\n"\r
- st=txt[s-maxtextlength:].find("\n")\r
- if st>0:\r
- stxt=stxt+txt[s-1500+st:]\r
- else:\r
- stxt=txt\r
- txtw= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")\r
- txtw=txtw+"\n####"+log_title+"####\n"+stxt\r
- f.write(txtw.encode('utf-8'))\r
- f.close()\r
-def addLogAll(tspath,txt,log_title,logpath):\r
- logo=logpath\r
- f=open(logo,'a')\r
- stxt=txt\r
- txtw= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")\r
- txtw=txtw+"\n####"+log_title+"####\n"+stxt\r
- f.write(txtw.encode('utf-8'))\r
- f.close()\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2012 Yukikaze\r
-import datetime\r
-import os\r
-import os.path\r
-import glob\r
-import time\r
-import traceback\r
-\r
-import configreader\r
-import recdblist\r
-import recdb\r
-tmppath = configreader.getConfPath("tmp")+"/"\r
-if not os.path.exists(tmppath):\r
- os.mkdir(tmppath)\r
-def writeRecQue(parentpath,chtxt,title,opts):\r
- outputpath=os.path.join(parentpath,title+".recq")\r
- tmpoppath=os.path.join(tmppath,title+".recq")\r
- f=open(outputpath,"w")\r
- optt=opts\r
- str="99"+","+datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")+","+configreader.getConfEnv("iff")+","+chtxt+","+title+","+optt\r
- f.write(str.encode('utf-8'))\r
- f.close()\r
- if not os.path.exists(outputpath):\r
- if os.path.exists(tmpoppath):\r
- os.remove(tmpoppath)\r
- f2=open(tmpoppath,"w")\r
- f2.write(str.encode('utf-8'))\r
- f2.close()\r
- try:\r
- os.chmod(tmpoppath)\r
- except:\r
- ""\r
- shutil.copy(tmpoppath,outputpath)\r
- os.remove(tmpoppath)\r
-def readRecQue(recquepath):\r
- f=open(recquepath,"r")\r
- line = unicode(f.readline(),'utf-8')\r
- title=""\r
- opts=""\r
- chtxt=""\r
- while line:\r
- linec=line.split(",")\r
- if len(linec)>3:\r
- if linec[0]=="99":\r
- title=linec[4]\r
- opts=linec[5]\r
- chtxt=linec[2]+u"_"+linec[3]\r
- break\r
- line = unicode(f.readline(),'utf-8')\r
- dbkey=""\r
- if opts.find("R")>-1:\r
- dbkey=recdblist.REC_TS_DECODE_QUE\r
- opts=opts.replace("R","")\r
- elif opts.find("D")>-1:\r
- dbkey=recdblist.REC_ENCODE_QUE\r
- opts=opts.replace("D","")\r
- elif opts.find("E")>-1:\r
- dbkey=""\r
- opts=opts.replace("E","")\r
- \r
- bt=datetime.datetime.now()+datetime.timedelta(minutes=5)\r
- et=bt+datetime.timedelta(minutes=30)\r
- btime=bt.strftime("%Y-%m-%d %H:%M:%S")\r
- etime=et.strftime("%Y-%m-%d %H:%M:%S")\r
- if len(dbkey)>2:\r
- recdb.reserveReckey(dbkey, title, chtxt, btime, etime, opts)\r
-def searchRecQue(folderpath):\r
- for file in glob.glob(os.path.join(folderpath,"*.recq")):\r
- dtime = time.time()-os.path.getmtime(file)\r
- dtime = int(dtime)\r
- if dtime > 300:\r
- try:\r
- readRecQue(os.path.join(folderpath, file))\r
- os.remove(os.path.join(folderpath, file))\r
- except Exception, inst:\r
- recdblist.addCommonlogEX("Error", "searchRecQue(recque.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)\r
- \r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import configreader\r
-import os\r
-import rec10d\r
-path = os.path.dirname(os.path.abspath(__file__)) + "/"\r
-def changeEncoding(i):\r
- """\r
- iはint 増減\r
- """\r
- rec10d.rec10db.change_ts2avi_in_status(i)\r
-def changeTERecording(i):\r
- rec10d.rec10db.change_terec_in_status(i)\r
-def changeBSCSRecording(i):\r
- rec10d.rec10db.change_bscsrec_in_status(i)\r
-def changeB25Decoding(i):\r
- rec10d.rec10db.change_b252ts_in_status(i)\r
-def getEncoding():\r
- """\r
- エンコードしている数を帰すint型\r
- """\r
- return int(rec10d.rec10db.select_all_in_status()[0][0])\r
-def getTERecording():\r
- return int(rec10d.rec10db.select_all_in_status()[0][1])\r
-def getBSCSRecording():\r
- return int(rec10d.rec10db.select_all_in_status()[0][2])\r
-def getB25Decoding():\r
- return int(rec10d.rec10db.select_all_in_status()[0][3])\r
-def getSettings_auto_bayes():\r
- return int(rec10d.rec10db.select_all_in_settings()[0][1])\r
-def getSettings_auto_jbk():\r
- return int(rec10d.rec10db.select_all_in_settings()[0][0])\r
-def getSettings_auto_del_tmp():\r
- return int(rec10d.rec10db.select_all_in_settings()[0][2])\r
-def getSettings_auto_opt():\r
- return rec10d.rec10db.select_all_in_settings()[0][3]\r
-\r
-def getRecordingMax():\r
- return [int(configreader.getConfEnv("te_max")),int(configreader.getConfEnv("bscs_max"))]\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-#import sys # モジュール属性 argv を取得するため\r
-import os\r
-import re\r
-import time\r
-import commands\r
-\r
-import chdb\r
-import configreader\r
-import tv2ts\r
-import recdblist\r
-\r
-def writeEpgXML(pout, ch):\r
- """\r
- tsを取得してepgの入ったxmlとして書き出す\r
- """\r
- timet = "90"\r
- if re.search(u'CS', ch):\r
- timet = "180"\r
- elif len(ch)>2:\r
- timet = "240"\r
- writeEpgXMLTime(pout, ch ,timet)\r
-def writeLogoEpgXML(pout, ch):\r
- """\r
- tsを取得してepgの入ったxmlとして書き出す\r
- """\r
- timet = "600"\r
- if re.search(u'CS', ch):\r
- timet = "10"\r
- elif len(ch)>2:\r
- timet = "1200"\r
- writeEpgXMLTime(pout, ch ,timet,islogo=1)\r
-def writeEpgXMLTime(pout, ch ,times,islogo=0):\r
- """\r
- 指定された時間分tsを取得してepgの入ったxmlとして書き出す\r
- """\r
- if islogo==0:\r
- recdblist.addCommonlogEX(u"通常","write_time(ts2epg.py)",u"Ts-EPG XML書き出し処理開始" ,u"CH:"+ch,log_level=500)\r
- elif islogo==1:\r
- recdblist.addCommonlogEX(u"通常","write_time(ts2epg.py)",u"Ts-EPG LOGO : XML書き出し処理開始" ,u"CH:"+ch,log_level=500)\r
- timet = times\r
- if re.search(u'CS', ch):\r
- mode = "/CS"\r
- elif len(ch)>2:\r
- mode = "/BS"\r
- else:\r
- mode = str(chdb.searchCHFromBctype(u'te' + ch)['ch'])\r
- epgdump = configreader.getConfPath("epgdump")\r
- if os.access(pout + ".ts", os.F_OK):\r
- os.remove(pout + ".ts")\r
- time.sleep(10)\r
- tv2ts.tv2b25ts(pout+ ".ts", ch, times,"0")\r
- logoopt=""\r
- if islogo==1:\r
- logoopt="/LOGO "\r
- os.chmod(pout+".ts",0755)\r
- exe = "export LANG=ja_JP.UTF-8 && nice -n 15 " + epgdump + " " +logoopt+ mode + " " + pout + ".ts " + pout\r
- recdblist.printutf8(exe)\r
- recdblist.addCommonlogEX(u"通常", "write_time(ts2epg.py) "+str(ch), exe,"",log_level=500)\r
- unicode(commands.getoutput(exe),'utf-8','ignore')\r
- time.sleep(10)\r
- if os.path.exists(pout+".ts"):\r
- os.remove(pout+ ".ts")\r
-\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import commands\r
-import configreader\r
-import os\r
-import os.path\r
-import sys\r
-import re\r
-import random\r
-import time\r
-import traceback\r
-import zip\r
-\r
-import recdblist\r
-def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"\r
- """\r
- pinで指定されたファイルをpoutにx264でエンコードして書き出す\r
- """\r
- dualpass = 0\r
- is24fps=0\r
- size="HD"\r
- crf=18\r
- quality=4\r
- quality=int(configreader.getConfEnv("x264_preset"))\r
- crf=int(configreader.getConfEnv("crf"))\r
- deinterlace=1\r
- bluray=0\r
- sar=1\r
- if re.search("H", opts):\r
- size = "HD"\r
- if re.search("S", opts):\r
- size = "WVGA"\r
- if re.search("F", opts):\r
- size = "FullHD"\r
- if re.search("W",opts):\r
- size = "WVGA"\r
- if re.search("MW1",opts):\r
- size = "QVGA_BASE"\r
- crf=crf+4\r
- sar=0\r
- if re.search("MW2", opts):\r
- size = "WVGA_BASE"\r
- crf=crf+2\r
- sar=0\r
- if re.search("v", opts):\r
- is24fps=1\r
- crf=int(configreader.getConfEnv("animation_crf"))\r
- if re.search("a", opts):\r
- is24fps=1\r
- crf=int(configreader.getConfEnv("animation_crf"))\r
- if re.search("I", opts):\r
- deinterlace=0\r
- if re.search("B", opts):\r
- bluray=1\r
- sar=0\r
- if re.search("q",opts):\r
- quality=quality-2\r
- if re.search("w",opts):\r
- quality=quality-1\r
- if re.search("e",opts):\r
- quality=quality+1\r
- if re.search("r",opts):\r
- quality=quality+2\r
- if re.search("u",opts):\r
- crf=crf+2\r
- if re.search("i",opts):\r
- crf=crf+1\r
- if re.search("o",opts):\r
- crf=crf-1\r
- if re.search("p",opts):\r
- crf=crf-2\r
- if re.search("d",opts):#二カ国語放送の場合\r
- tm2v=pin.replace(".ts",".m2v")\r
- encodeFfmpegSar(tm2v,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar)\r
- elif re.search("5",opts):#5.1chの場合\r
- encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar)\r
- elif re.search("b",opts):#BonTsDemuxを使いたい場合\r
- tm2v=pin.replace(".ts",".m2v")\r
- encodeFfmpegSar(tm2v,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar)\r
- else:\r
- try:\r
- encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=1,usebluray=bluray,usesar=sar)\r
- if os.path.exists(pout):\r
- if not os.path.getsize(pout)>1*1000:\r
- recdblist.addCommonlogEX("Warning", "Old mencoder option used.","","",log_level=200)\r
- try:\r
- encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=0,usebluray=bluray,usesar=sar)\r
- except Exception, inst:\r
- recdblist.addCommonlogEX("Error", "ts2x264_mencoder_old(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)\r
- else:\r
- recdblist.addCommonlogEX("Warning", "Old mencoder option used.","","",log_level=200)\r
- try:\r
- encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=0,usebluray=bluray,usesar=sar)\r
- except Exception, inst:\r
- recdblist.addCommonlogEX("Error", "ts2x264_mencoder_old(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)\r
- except Exception, inst:\r
- recdblist.addCommonlogEX("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)\r
-def encodeMencoderSar(pin,pout,size,is24fps,quality,crf,deinterlace=1,uselavf=0,usebluray=0,usesar=1):\r
- mencoder=configreader.getConfPath("mencoder")\r
- tee=configreader.getConfPath("tee")\r
- encvf=""\r
- txt=""\r
- encvf="-sws 9 -vf yadif=0,pp=l5"\r
- harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"\r
- ofps="-ofps 30000/1001"\r
- fps="-fps 30000/1001"\r
- x264fps="30000/1001 --keyint 30"\r
- x264streamsize=""\r
- x264preset=""\r
- x264tune=""\r
- x264_bitrate="5000"\r
- x264interlaced=0\r
- x264sar="1:1"\r
- tsar=getMoviePAR2(pin)\r
- if usesar==1:\r
- x264sar=str(tsar[0])+u":"+str(tsar[1])\r
- lavft=""\r
- if is24fps==1:\r
- ofps="-ofps 24000/1001"\r
- fps="-fps 30000/1001"\r
- x264fps="24000/1001 --keyint 24"\r
- x264tune="--tune animation"\r
- encvf="-sws 9 -vf pullup,softskip"\r
- harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"\r
- if size == "HD":\r
- tsize=getParSize(pin,720)\r
- if usesar==1:\r
- encvf = encvf + ",scale=-3:720::0:3"+harddup\r
- x264streamsize=str(tsize[0])+u"x720"\r
- else:\r
- encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup\r
- x264streamsize=u"1280x720"\r
- x264_bitrate="2500"\r
- elif size == "WVGA":\r
- tsize=getParSize(pin,480)\r
- if usesar==1:\r
- encvf = encvf + ",scale=-3:480::0:3"+harddup\r
- x264streamsize=str(tsize[0])+u"x480"\r
- else:\r
- encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup\r
- x264streamsize=u"854x480"\r
- x264_bitrate="1500"\r
- elif size == "FullHD":\r
- tsize=getParSize(pin,1080)\r
- if usesar==1:\r
- encvf = encvf + ",scale=-3:1080::0:3"+harddup\r
- x264streamsize=str(tsize[0])+u"x1080"\r
- else:\r
- encvf = encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup\r
- x264streamsize=u"1920x1080"\r
- x264_bitrate="5000"\r
- elif size == "QVGA_BASE":\r
- tsize=getParSize(pin,240)\r
- if usesar==1:\r
- encvf = encvf + ",scale=-3:240::0:3"+harddup\r
- x264streamsize=str(tsize[0])+u"x240"\r
- else:\r
- encvf = encvf + ",scale=320:-2::0:3,expand=320:240"+harddup\r
- x264streamsize=u"320x240"\r
- x264_bitrate="300"\r
- elif size == "WVGA_BASE":\r
- tsize=getParSize(pin,480)\r
- if usesar==1:\r
- encvf = encvf + ",scale=-3:480::0:3"+harddup\r
- x264streamsize=str(tsize[0])+u"x480"\r
- else:\r
- encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup\r
- x264streamsize=u"854x480"\r
- x264_bitrate="1500"\r
- else:\r
- tsize=getParSize(pin,720)\r
- if usesar==1:\r
- encvf = encvf + ",scale=-3:720::0:3"+harddup\r
- x264streamsize=str(tsize[0])+u"x720"\r
- else:\r
- encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup\r
- x264streamsize=u"1280x720"\r
- x264_bitrate="2500"\r
- if deinterlace==0:\r
- tsize=getMovieBaseSize2(pin)\r
- ofps="-ofps 30000/1001"\r
- #fps="-fps 30000/1001"\r
- fps=""\r
- x264fps="30000/1001 --keyint 30"\r
- x264interlaced=1\r
- encvf="-vf hqdn3d=2:1:2"\r
- harddup=",harddup"\r
- encvf=encvf+harddup\r
- x264streamsize=str(tsize[0])+u"x"+str(tsize[1])\r
- if usebluray==1:\r
- encvf = u"-sws 9 "+encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup\r
- x264streamsize=u"1920x1080"\r
- if tsize[0] <= 0 or tsize[1] <= 0:\r
- encvf="-sws 9 -vf yadif=0,pp=l5"\r
- harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"\r
- ofps="-ofps 30000/1001"\r
- fps="-fps 30000/1001"\r
- x264fps="30000/1001 --keyint 30"\r
- tsize=[1280,720]\r
- encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup\r
- x264streamsize=u"1280x720"\r
- x264_bitrate="2500"\r
- if quality==1:\r
- x264preset=u"ultrafast"\r
- elif quality==2:\r
- x264preset=u"veryfast"\r
- elif quality==3:\r
- x264preset=u"fast"\r
- elif quality==4:\r
- x264preset=u"medium"\r
- elif quality==5:\r
- x264preset=u"slow"\r
- elif quality==6:\r
- x264preset=u"slower"\r
- else:\r
- x264preset=u"medium"\r
- if size == "WVGA_BASE" or size == "QVGA_BASE":\r
- x264profile=" --level 32 --profile baseline "\r
- else:\r
- x264profile=" --level 41 --profile high "\r
- if uselavf==1:\r
- lavft="-demuxer lavf "\r
- x264crf=str(crf)\r
- os.environ['LANG']="ja_JP.UTF-8"\r
- random.seed(pin)\r
- random.jumpahead(10)\r
- temptime=int(time.time())\r
- temptime=temptime % 9697\r
- random.jumpahead(temptime)\r
- streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 99999999)))\r
- unicode(commands.getoutput(u"mkfifo "+streampath),'utf-8','ignore')\r
- logmencoder=recdblist.getLogTitle(pin)+".mencoder.log"\r
- logx264=recdblist.getLogTitle(pin)+".x264.log"\r
- 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+"\" & "\r
- encexe=encexe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout, streampath, x264streamsize, crf=x264crf,interlaced=x264interlaced,bluray=usebluray)\r
- #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\r
- encexe=u"nice -n 19 " +encexe+" 2>&1 | "+tee+" \""+logx264+"\""\r
- try:\r
- recdblist.addCommandSelfLog(pin, encexe)\r
- except Exception, inst:\r
- print type(inst)\r
- print str(inst)\r
- print traceback.print_exc(file=sys.stdout)\r
- recdblist.printutf8(encexe)\r
- txt=""\r
- try:\r
- txt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8','ignore')\r
- except:\r
- ""\r
- os.remove(streampath)\r
- zip.addFile2FileZip(logmencoder, recdblist.getLogTitle(pin)+".log.zip")\r
- zip.addFile2FileZip(logx264, recdblist.getLogTitle(pin)+".log.zip")\r
- os.remove(logmencoder)\r
- os.remove(logx264)\r
- recdblist.addCommandLog(pin, u"Mencoder", encexe, txt)\r
-# recdblist.addCommandLogTar(pin,u"Mencoder","mencoder", encexe,txt)\r
-def encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=1,usebluray=0,usesar=1):\r
- """\r
-\r
- """\r
- ffmpeg=configreader.getConfPath("ffmpeg")\r
- tee=configreader.getConfPath("tee")\r
- fps=u"-r 29.970030 "\r
- x264fps="30000/1001 --keyint 30"\r
- x264streamsize=""\r
- x264preset=""\r
- x264tune=""\r
- x264_bitrate="2500"\r
- x264_thread="auto"\r
- x264interlaced=0\r
- tsar=getMoviePAR2(pin)\r
- filter="-deinterlace"\r
- x264sar=str(tsar[0])+":"+str(tsar[1])\r
- if is24fps==1:\r
- fps=u"-r 23.976023 "\r
- x264fps="24000/1001 --keyint 24"\r
- x264tune="--tune animation"\r
- if size == "HD":\r
- tsize=getParSize(pin,720)\r
- s = "-s "+str(tsize[0])+"x720 "\r
- x264streamsize=str(tsize[0])+u"x720"\r
- x264_bitrate="2500"\r
- elif size == "WVGA":\r
- tsize=getParSize(pin,480)\r
- s = "-s "+str(tsize[0])+"x480 "\r
- x264streamsize=str(tsize[0])+u"x480"\r
- x264_bitrate="1500"\r
- elif size == "FullHD":\r
- tsize=getParSize(pin,1080)\r
- s = "-s "+str(tsize[0])+"x1080 "\r
- x264streamsize=str(tsize[0])+u"x1080"\r
- x264_bitrate="5000"\r
- elif size == "SD":\r
- tsize=getParSize(pin,480)\r
- s = "-s "+str(tsize[0])+"x480 "\r
- x264streamsize=str(tsize[0])+u"x480"\r
- x264_bitrate="1250"\r
- elif size == "QVGA_BASE":\r
- tsize=getParSize(pin,240)\r
- s = "-s "+str(tsize[0])+"x240 "\r
- x264streamsize=str(tsize[0])+u"x240"\r
- x264_bitrate="300"\r
- elif size == "WVGA_BASE":\r
- tsize=getParSize(pin,480)\r
- s = "-s "+str(tsize[0])+"x480 "\r
- x264streamsize=str(tsize[0])+u"x480"\r
- x264_bitrate="1500"\r
- else:\r
- tsize=getParSize(pin,720)\r
- s = "-s "+str(tsize[0])+"x720 "\r
- x264streamsize=str(tsize[0])+u"x720"\r
- x264_bitrate="2500"\r
- if deinterlace==0:\r
- tsize=getMovieBaseSize2(pin)\r
- fps=""\r
- s = "-s "+str(tsize[0])+"x"+str(tsize[1])+" "\r
- x264fps="30000/1001 --keyint 30"\r
- x264interlaced=1\r
- filter=""\r
- x264streamsize=str(tsize[0])+u"x"+str(tsize[1])\r
- if quality==1:\r
- x264preset=u"ultrafast"\r
- elif quality==2:\r
- x264preset=u"veryfast"\r
- elif quality==3:\r
- x264preset=u"fast"\r
- elif quality==4:\r
- x264preset=u"medium"\r
- elif quality==5:\r
- x264preset=u"slow"\r
- elif quality==6:\r
- x264preset=u"slower"\r
- else:\r
- x264preset=u"medium"\r
- if size == "WVGA_BASE" or size == "QVGA_BASE":\r
- x264profile=" --level 32 --profile baseline "\r
- else:\r
- x264profile=" --level 41 --profile high "\r
- x264crf=str(crf)\r
- txt=""\r
- os.environ['LANG']="ja_JP.UTF-8"\r
- log_ffmpeg=recdblist.getLogTitle(pin)+".ffmpeg.log"\r
- log_x264=recdblist.getLogTitle(pin)+".x264.log"\r
- exe=ffmpeg+u" -y -i \""+pin+"\" -vcodec rawvideo -pix_fmt yuv420p "+s+fps+" "+filter+" -an -f rawvideo - 2> \""+log_ffmpeg+"\" | "\r
- exe=exe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout,"-", x264streamsize, crf=x264crf,interlaced=x264interlaced,bluray=usebluray)\r
- exe = "nice -n 19 " + exe+" 2>&1 | "+tee+" \""+log_x264+"\""\r
- txt=""\r
- #recdblist.addCommandSelfLog(log_ffmpeg,recdblist.getLogTitle(pin)+".log.zip")\r
- #recdblist.addCommandSelfLog(log_x264,recdblist.getLogTitle(pin)+".log.zip")\r
- recdblist.printutf8(exe)\r
- recdblist.addCommandSelfLog(pin,exe)\r
- try:\r
- txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')\r
- except:\r
- ""\r
- recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt)\r
- zip.addFile2FileZip(log_ffmpeg, recdblist.getLogTitle(pin+".log.zip"))\r
- zip.addFile2FileZip(log_x264, recdblist.getLogTitle(pin+".log.zip"))\r
- os.remove(log_ffmpeg)\r
- os.remove(log_x264)\r
-def getMovieBaseSize2(pin):##動画開始後すぐに解像度が変更されたときに対処\r
- ffmpeg=configreader.getConfPath("ffmpeg")\r
- os.environ['LANG']="ja_JP.UTF-8"\r
- exe=ffmpeg+u" -ss 5 -fs 1 -t 10 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"\r
- try:\r
- recdblist.addCommandSelfLog(pin, exe)\r
- except Exception, inst:\r
- print type(inst)\r
- print str(inst)\r
- print traceback.print_exc(file=sys.stdout)\r
- txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')\r
- rT=re.compile(u"Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")\r
- rT2=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+SAR\D+(\d+:\d+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z")\r
- sizeMaxX=0\r
- sizeMaxY=0\r
- txtls=txts.split("\n")\r
- for t in txtls:\r
- rM=rT.search(t)\r
- rM2=rT2.search(t)\r
- if rM:\r
- sizetxt=rM.group(1)\r
- partxt=rM.group(2)\r
- tX=int(sizetxt.split("x")[0])\r
- tY=int(sizetxt.split("x")[1])\r
- tEX=int(partxt.split(":")[0])\r
- tEY=int(partxt.split(":")[1])\r
- if sizeMaxX<tX:\r
- sizeMaxX=tX\r
- sizeMaxY=tY\r
- if rM2:\r
- sizetxt=rM2.group(1)\r
- tX=int(sizetxt.split("x")[0])\r
- tY=int(sizetxt.split("x")[1])\r
- if sizeMaxX<tX:\r
- sizeMaxX=tX\r
- sizeMaxY=tY\r
- os.remove(pin+".size.ts")\r
- return [sizeMaxX,sizeMaxY]\r
-def getMoviePAR2(pin):\r
- ffmpeg=configreader.getConfPath("ffmpeg")\r
- os.environ['LANG']="ja_JP.UTF-8"\r
- exe=ffmpeg+u" -ss 5 -fs 1 -t 10 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"\r
- try:\r
- recdblist.addCommandSelfLog(pin, exe)\r
- except Exception, inst:\r
- print type(inst)\r
- print str(inst)\r
- print traceback.print_exc(file=sys.stdout)\r
- txts = unicode(commands.getoutput(exe.encode('utf-8')), 'utf-8', 'ignore')\r
- rT = re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")\r
- rT2 = re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+SAR\D+(\d+:\d+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z")\r
- sizeMaxX = 0\r
- parx = 0\r
- pary = 0\r
- txtls = txts.split("\n")\r
- for t in txtls:\r
- rM = rT.match(t)\r
- rM2 = rT2.match(t)\r
- if rM:\r
- sizetxt = rM.group(1)\r
- dartxt = rM.group(2)\r
- tX = int(sizetxt.split("x")[0])\r
- tY = int(sizetxt.split("x")[1])\r
- tEX = int(dartxt.split(":")[0])\r
- tEY = int(dartxt.split(":")[1])\r
- if sizeMaxX < tX:\r
- sizeMaxX = tX\r
- if tX == 1920 and tY == 1080:\r
- parx = 1\r
- pary = 1\r
- else:\r
- parx = tEX\r
- pary = tEY\r
- rM = rT.match(t)\r
- if rM2:\r
- sizetxt = rM2.group(1)\r
- sartxt = rM2.group(2)\r
- dartxt = rM2.group(3)\r
- tX = int(sizetxt.split("x")[0])\r
- tY = int(sizetxt.split("x")[1])\r
- tEX = int(dartxt.split(":")[0])\r
- tEY = int(dartxt.split(":")[1])##dar=sarxpar\r
- tSX = int(sartxt.split(":")[0])\r
- tSY = int(sartxt.split(":")[1])##par=dar/sar= darx*pary*sary=dary*parx*sarx\r
- if sizeMaxX < tX:\r
- sizeMaxX = tX\r
- if tX == 1920 and tY == 1080:\r
- parx = 1\r
- pary = 1\r
- else:\r
- if tEX * tSY == tEY * tSX:\r
- parx = 1\r
- pary = 1\r
- elif tEX * tSY * 3 == tEY * tSX * 4:\r
- parx = 4\r
- pary = 3\r
- elif tEX * tSY * 4 == tEY * tSX * 3:\r
- parx = 3\r
- pary = 4\r
- elif tEX * tSY * 9 == tEY * tSX * 16:\r
- parx = 16\r
- pary = 9\r
- elif tEX * tSY * 16 == tEY * tSX * 9:\r
- parx = 9\r
- pary = 16\r
- os.remove(pin+".size.ts")\r
- return [parx,pary]\r
-def getParSize(pin,y):\r
- tSize=getMovieBaseSize2(pin)\r
- if tSize[1] != 0 :\r
- tX=tSize[0]*10*y/tSize[1]\r
- tY=y\r
- if tX>int(tX/10)*10:\r
- tX=tX/10+1\r
- else:\r
- tX=tX/10\r
- else:\r
- tX=-1\r
- tY=-1\r
- return [tX,tY]\r
-def getX264CoreVersion():\r
- x264=configreader.getConfPath("x264")\r
- #print x264\r
- t1=commands.getoutput(x264+" --help|grep core")\r
- #print t1\r
- rT=re.compile(u"x264 core:(\d*)[\d]*.*\Z")\r
- rM=rT.match(t1)\r
- v=-1\r
- if rM:\r
- v=int(rM.group(1))\r
- return v\r
-def getX264Commandline(preset,sar,fps,x264profile,x264tune,pout,pin,x264streamsize,crf=-1,bitrate=0,interlaced=0,bluray=0):\r
- x264=configreader.getConfPath("x264")\r
- os.environ['LANG']="ja_JP.UTF-8"\r
- x264_sar="--sar "+sar\r
- x264preset=u"--preset "+preset\r
- x264fps="--fps "+fps\r
- x264interlaced=""\r
- x264bluray=""\r
- x264_addline=configreader.getConfEnv("x264_addline")\r
- if crf==-1:\r
- x264bitrate=u"--bitrate "+str(bitrate)\r
- else:\r
- x264crf=u"--crf "+str(crf)\r
- if interlaced==1:\r
- x264interlaced="--tff --nal-hrd vbr"\r
- if bluray==1:\r
- if getX264CoreVersion()<115:\r
- x264bluray=" --weightp 1 --nal-hrd vbr --bframes 3 --b-pyramid none --open-gop bluray --slices 4 --aud --colorprim bt709 --transfer bt709 "\r
- x264_addline=""\r
- if fps=="24000/1001 --keyint 24" or fps =="24000/1001":\r
- if x264streamsize=="1280x720":\r
- x264bluray=u"--ref 6 "+x264bluray\r
- if x264streamsize=="1920x1080":\r
- x264bluray=u"--ref 4 "+x264bluray\r
- elif fps=="30000/1001 --keyint 30" or fps =="30000/1001":\r
- if x264streamsize=="1280x720":\r
- x264bluray=u"--ref 6 --pulldown double "+x264bluray\r
- if x264streamsize=="1920x1080":\r
- if interlaced==0:\r
- x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray\r
- else:\r
- x264bluray=u"--ref 4 "+x264bluray\r
- elif getX264CoreVersion()>=115:\r
- x264bluray=" --slices 4 --bluray-compat --nal-hrd vbr --bframes 3 --b-pyramid strict --aud --colorprim bt709 --transfer bt709 "\r
- x264_addline=""\r
- if fps=="24000/1001 --keyint 24" or fps =="24000/1001":\r
- if x264streamsize=="1280x720":\r
- x264bluray=u"--ref 6 "+x264bluray\r
- if x264streamsize=="1920x1080":\r
- x264bluray=u"--ref 4 "+x264bluray\r
- elif fps=="30000/1001 --keyint 30" or fps =="30000/1001":\r
- if x264streamsize=="1280x720":\r
- x264bluray=u"--ref 6 --pulldown double "+x264bluray\r
- if x264streamsize=="1920x1080":\r
- if interlaced==0:\r
- x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray\r
- else:\r
- x264bluray=u"--ref 4 "+x264bluray\r
- x264_thread="auto"\r
- try:\r
- xtt=configreader.getConfEnv("x264_thread")\r
- xtt=int(xtt)\r
- if xtt>0:\r
- x264_thread=str(xtt)\r
- except:\r
- x264_thread="auto"\r
- x264_addline=configreader.getConfEnv("x264_addline")\r
- if getX264CoreVersion()>103:\r
- x264res=u"--input-res "+x264streamsize\r
- 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\r
- else:\r
- 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\r
- return exe\r
+#!/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<tX:
+ sizeMaxX=tX
+ sizeMaxY=tY
+ if rM2:
+ sizetxt=rM2.group(1)
+ tX=int(sizetxt.split("x")[0])
+ tY=int(sizetxt.split("x")[1])
+ if sizeMaxX<tX:
+ sizeMaxX=tX
+ sizeMaxY=tY
+ os.remove(pin+".size.ts")
+ return [sizeMaxX,sizeMaxY]
+def getMoviePAR2(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
+ 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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-\r
-import commands\r
-import os\r
-import re\r
-import shutil\r
-import time\r
-import os.path\r
-import subprocess\r
-import signal\r
-\r
-import configreader\r
-import recdblist\r
-\r
-def wav2aac_nero(pin,pout):\r
- os.environ['LANG']="ja_JP.UTF-8"\r
- neroaac=configreader.getConfPath('NeroAAC')\r
- exe=neroaac+" -br 128000 -2pass -if \""+pin+"\" -of \""+pout+"\""\r
- try:\r
- txt=commands.getoutput(exe.encode('utf-8'))\r
- recdblist.addLog(pin, exe, u"Wav2aac_Neroログ-コマンド")\r
- recdblist.addLog(pin, txt, u"Wav2aac_Neroログ-詳細")\r
- except:\r
- if not os.path.exists(pout):\r
- lame="lame"\r
- exe=lame+" -b 128 \""+pin+"\" \""+pout+"\""\r
- txt=commands.getoutput(exe.encode('utf-8'))\r
- recdblist.addLog(pin, exe, u"Wav2aac_Lameログ-コマンド")\r
- recdblist.addLog(pin, txt, u"Wav2aac_Lameログ-詳細")\r
-def wav2mp3_lame(pin,pout):\r
- os.environ['LANG']="ja_JP.UTF-8"\r
- lame=configreader.getConfPath('lame')\r
- exe=lame+" -b 128 \""+pin+"\" \""+pout+"\""\r
- try:\r
- txt=commands.getoutput(exe.encode('utf-8'))\r
- except:\r
- ""\r
- recdblist.addLog(pin, exe, u"Wav2aac_Lameログ-コマンド")\r
- recdblist.addLog(pin, txt, u"Wav2aac_Lameログ-詳細")\r
-def ts2single_audio(pts,opts):\r
- paac=pts.replace(".ts",".aac")\r
- ffmpeg=configreader.getConfPath("ffmpeg")\r
- e0=ffmpeg+" -i \""+pts+"\" -y -vn -acodec copy \""+paac+"\""\r
- p0=subprocess.Popen(e0,shell=True)\r
- os.waitpid(p0.pid, 0)\r
- if p0.poll==None:#実行中\r
- if os.path.exists(paac):\r
- if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了\r
- try:\r
- logt=unicode(p0.communicate()[0], "UTF-8")\r
- recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド")\r
- recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細")\r
- except:\r
- ""\r
- recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200)\r
- os.kill(p0.pid,signal.SIGKILL)\r
- os.remove(paac)\r
- ts2single_mp3_ffmpeg(pts)\r
- if not os.path.exists(pts.replace(".ts",".mp3")):\r
- ts2single_fp_BonTsDemux(pts,opts)\r
- else:\r
- logt=unicode(p0.communicate()[0], "UTF-8")\r
- recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド")\r
- recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細")\r
- else:\r
- try:\r
- logt=unicode(p0.communicate()[0], "UTF-8")\r
- recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド")\r
- recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細")\r
- except:\r
- ""\r
- recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200)\r
- try:\r
- os.kill(p0.pid,signal.SIGKILL)\r
- except:\r
- ""\r
- ts2single_mp3_ffmpeg(pts)\r
- if not os.path.exists(pts.replace(".ts",".mp3")):\r
- ts2single_fp_BonTsDemux(pts,opts)\r
- else:\r
- if os.path.exists(paac):\r
- if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了\r
- try:\r
- logt=unicode(p0.communicate()[0], "UTF-8")\r
- recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド")\r
- recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細")\r
- except:\r
- ""\r
- recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200)\r
- os.remove(paac)\r
- ts2single_mp3_ffmpeg(pts)\r
- if not os.path.exists(pts.replace(".ts",".mp3")):\r
- ts2single_fp_BonTsDemux(pts,opts)\r
- else:\r
- try:\r
- logt=unicode(p0.communicate()[0], "UTF-8")\r
- recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド")\r
- recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細")\r
- except:\r
- ""\r
- else:\r
- try:\r
- logt=unicode(p0.communicate()[0], "UTF-8")\r
- recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド")\r
- recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細")\r
- except:\r
- ""\r
- recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200)\r
- ts2single_mp3_ffmpeg(pts)\r
- if not os.path.exists(pts.replace(".ts",".mp3")):\r
- ts2single_fp_BonTsDemux(pts,opts)\r
-def ts2singlewav(pts,opts):\r
- bontsdemux = configreader.getConfPath('bontsdemux')\r
- bonpin = "Z:\\" + pts[1:]\r
- outf = os.path.splitext(pts)[0]\r
- bonpout = "Z:\\" + outf[1:]\r
- delayt=""\r
- exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" "+delayt+" -nd -sound 0 -o \"" + bonpout + "\""\r
- #recdblist.printutf8(exe)\r
- recdblist.printutf8(exe)\r
- txt=commands.getoutput(exe.encode('utf-8'))\r
- recdblist.addCommandLog(pts, u"BonTsDemux 音声取り出し", exe, txt)\r
-def ts2single_mp3_ffmpeg(pts):\r
- pmp3=pts.replace(".ts",".mp3")\r
- ffmpeg=configreader.getConfPath("ffmpeg")\r
- e0=ffmpeg+" -i \""+pts+"\" -y -vn -ab 128k \""+pmp3+"\""\r
- p0=subprocess.Popen(e0,shell=True)\r
- os.waitpid(p0.pid, 0)\r
- try:\r
- logt=unicode(p0.communicate()[0], "UTF-8")\r
- recdblist.addLog(pts,e0, "FFmpeg_mp3音声取り出しログ-コマンド")\r
- recdblist.addLog(pts,logt, "FFmpeg_mp3音声取り出しログ-詳細")\r
- except:\r
- ""\r
-def ts2single_aac_ffmpeg(pts):\r
- ts2singlewav(pts,opts)\r
- aout=pts.replace(".ts",".aac")\r
- ain=pts.replace(".ts",".wav")\r
- wav2aac_ffmpeg(ain,aout)\r
-def wav2aac_ffmpeg(pin,pout):\r
- paac=pts.replace(".ts",".aac")\r
- ffmpeg=configreader.getConfPath("ffmpeg")\r
- e0=ffmpeg+" -i \""+pin+"\" -y \""+pout+"\""\r
- p0=subprocess.Popen(e0,shell=True)\r
- os.waitpid(p0.pid, 0)\r
- try:\r
- logt=unicode(p0.communicate()[0], "UTF-8")\r
- recdblist.addLog(pts,e0, "FFmpeg_wav2aac音声取り出しログ-コマンド")\r
- recdblist.addLog(pts,logt, "FFmpeg_wav2aac音声取り出しログ-詳細")\r
- except:\r
- ""\r
-def ts2single_fp_BonTsDemux(pts,opts):\r
- useNero=0\r
- try:\r
- if configreader.getConfPath("useNeroAAC")=="1" and os.path.exists(configreader.getConfPath("NeroAAC")):\r
- useNero=1\r
- except:\r
- useNero=0\r
- if useNero==1:\r
- ts2single_aac_BonTsDemux_Nero(pts,opts)\r
- else:\r
- ts2single_aac_ffmpeg(pts)\r
- if not os.path.exists(pts.replace(".ts",".aac")):\r
- ts2single_mp3_BonTsDemux(pts,opts)\r
-def ts2single_aac_BonTsDemux_Nero(pts,opts):\r
- ts2singlewav(pts,opts)\r
- aout=pts.replace(".ts",".aac")\r
- ain=pts.replace(".ts",".wav")\r
- wav2aac_nero(ain,aout)\r
-def ts2single_mp3_BonTsDemux(pts,opts):\r
- ts2singlewav(pts,opts)\r
- aout=pts.replace(".ts",".mp3")\r
- ain=pts.replace(".ts",".wav")\r
- wav2mp3_lame(ain,aout)\r
-def ts2dualaudio_BonTsDemux(pin, delay,opts):\r
- """\r
- delay is string\r
- """\r
- bontsdemux = configreader.getConfPath('bontsdemux')\r
- wine = configreader.getConfPath('wine')\r
- bonpin = "Z:\\" + pin[1:]\r
- outf = os.path.splitext(pin)[0]\r
- bonpout = "Z:\\" + outf[1:]\r
- exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 1 -o \"" + bonpout + "\""\r
- recdblist.printutf8(exe)\r
- txt=commands.getoutput(exe.encode('utf-8'))\r
- try:\r
- recdblist.addCommandLog(pin, u"BonTsDemux 第一音声取り出し", exe, txt)\r
- except:\r
- ""\r
- ffpin = pin.replace(".ts", "")\r
- ffpin1 = pin.replace("ts", "wav")\r
- ffpin2 = pin.replace("ts", "m2v")\r
- ffpout1 = ffpin + "_1.wav"\r
- ffpout2 = ffpin + "_2.wav"\r
- ffpout3 = ffpin + ".m2v"\r
- shutil.move(ffpin1, ffpout1)\r
- exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 2 -encode Demux\(wav\) -o \"" + bonpout + "\""\r
- recdblist.printutf8(exe)\r
- txt=commands.getoutput(exe.encode('utf-8'))\r
- try:\r
- recdblist.addCommandLog(pin, u"BonTsDemux 第二音声取り出し", exe, txt)\r
- except:\r
- ""\r
- #os.system(exe)\r
- shutil.move(ffpin1, ffpout2)\r
- shutil.move(ffpin2, ffpout3)\r
- ffpout21=ffpout1.replace(".wav",".mp3")\r
- ffpout22=ffpout2.replace(".wav",".mp3")\r
- useNero=0\r
- try:\r
- if os.path.exists(configreader.getConfPath("NeroAAC")):\r
- useNero=1\r
- except:\r
- useNero=0\r
- if useNero==1:\r
- ffpout21=ffpout1.replace(".wav",".aac")\r
- ffpout22=ffpout2.replace(".wav",".aac")\r
- wav2aac_nero(ffpout1, ffpout21)\r
- wav2aac_nero(ffpout2, ffpout22)\r
- else:\r
- wav2mp3_lame(ffpout1, ffpout21)\r
- wav2mp3_lame(ffpout2, ffpout22)\r
- time.sleep(3)\r
- os.remove(ffpout1)\r
- os.remove(ffpout2)\r
-def ts2pentaaudio_BonTsDemux(pin, delay,opts):\r
- bontsdemux = configreader.getConfPath('bontsdemux')\r
- wine = configreader.getConfPath('wine')\r
- bonpin = "Z:\\" + pin[1:]\r
- outf = os.path.splitext(pin)[0]\r
- bonpout = "Z:\\" + outf[1:]\r
- exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay "+delay+" -nd -sound 3 -o \"" + bonpout + "\""\r
- recdblist.printutf8(exe)\r
- txt=commands.getoutput(exe.encode('utf-8'))\r
- try:\r
- recdblist.addCommandLog(pin, u"BonTsDemux5.1ch 第一音声取り出し", exe, txt)\r
- except:\r
- ""\r
- ffpin = pin.replace(".ts", "")\r
- ffpin1 = pin.replace("ts", "wav")\r
- ffpin2 = pin.replace("ts", "m2v")\r
- ffpout1 = ffpin + "_1.wav"\r
- ffpout2 = ffpin + "_2.aac"\r
- shutil.move(ffpin1, ffpout1)\r
- exe = "ffmpeg -i '"+pin+"' -vn -f aac -acodec copy '"+ffpout2+"'"\r
- recdblist.printutf8(exe)\r
- txt=commands.getoutput(exe.encode('utf-8'))\r
- try:\r
- recdblist.addCommandLog(pin, u"FFmpeg 5.1ch 第二音声(raw AAC)取り出し", exe, txt)\r
- except:\r
- ""\r
- ffpout21=ffpout1.replace(".wav",".mp3")\r
- useNero=0\r
- try:\r
- if os.path.exists(configreader.getConfPath("NeroAAC")):\r
- useNero=1\r
- except:\r
- useNero=0\r
- if useNero==1:\r
- ffpout21=ffpout1.replace(".wav",".aac")\r
- wav2aac_nero(ffpout1, ffpout21)\r
- else:\r
- wav2mp3_lame(ffpout1, ffpout21)\r
- if not os.path.exists(ffpout21):\r
- exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay "+delay+" -nd -sound 0 -o \"" + bonpout + "\""\r
- recdblist.printutf8(exe)\r
- txt=commands.getoutput(exe.encode('utf-8'))\r
- try:\r
- recdblist.addCommandLog(pin, u"BonTsDemux 修正版第二音声(2chDownmix)取り出し", exe, txt)\r
- except:\r
- ""\r
- shutil.move(ffpin1, ffpout1)\r
- if useNero==1:\r
- ffpout21=ffpout1.replace(".wav",".aac")\r
- wav2aac_nero(ffpout1, ffpout21)\r
- else:\r
- wav2mp3_lame(ffpout1, ffpout21)\r
- time.sleep(3)\r
- ffpout21=ffpout1.replace(".wav",".aac")\r
- if os.path.exists(ffpout21):\r
- if os.path.getsize(ffpout21)>10*1000*1000:\r
- os.remove(ffpout1)\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import commands\r
-import datetime\r
-import os\r
-import re\r
-import shutil\r
-import time\r
-import os.path\r
-import traceback\r
-\r
-import chdb\r
-import configreader\r
-import status\r
-import ts2x264\r
-import tv2ts\r
-import recdblist\r
-import tv2audio\r
-\r
-\r
-global Bitrate_SD\r
-global Bitrate_HD\r
-global Bitrate_FHD\r
-global Bitrate_Short\r
-global Bitrate_LowHD\r
-Bitrate_SD = 1250\r
-Bitrate_HD = 3750\r
-Bitrate_LowHD = 2500\r
-Bitrate_FHD = 5000\r
-Bitrate_Short = 1250\r
-def timetv2b25(pout, chtxt, btime, etime, opt):\r
- """\r
- poutはタイトル\r
- """\r
- bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")\r
- et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")\r
- extt = os.path.splitext(pout)\r
- tsout = extt[0]\r
- tnow = datetime.datetime.now()\r
- wt = bt-tnow\r
- waitt = wt.seconds\r
- if waitt>0:\r
- time.sleep(waitt)\r
- tnow = datetime.datetime.now()\r
- dt = et-tnow\r
- rectime = dt.seconds-5\r
- rectime = str(rectime)\r
- tv2ts.tv2b25ts(tsout + ".ts.b25", chdb.searchCHFromChtxt(chtxt)['ch'], rectime,chdb.searchCHFromChtxt(chtxt)['tsid'])\r
-def b252ts(pout, chtxt, btime, etime, opt):\r
- """\r
- poutはタイトル(自動的にtitle.b25 title.tsと名前がつきます。)\r
- """\r
- #status.setB25Decoding(status.getB25Decoding() + 1)\r
- status.changeB25Decoding(1)\r
- try:\r
- try:\r
- chs=chdb.searchCHFromChtxt(chtxt)\r
- ch=chs['ch']\r
- csch=chs['csch']\r
- #print [ch,csch,chtxt]\r
- except:\r
- ch="0"\r
- csch="0"\r
- tv2ts.b252ts(pout + ".ts", ch, csch)\r
- tsout = pout\r
- aviin = pout + ".ts"\r
- dualaudio = 0\r
- pentaaudio = 0\r
- singleaudiosplit = 0\r
- if re.search("5", opt):\r
- pentaaudio = 1\r
- if re.search("d", opt):\r
- dualaudio = 1\r
- if re.search("b", opt):\r
- singleaudiosplit = 1\r
- if re.search(u"\[二\]", pout):\r
- dualaudio = 1\r
- elif re.search(u'(二)', pout):\r
- dualaudio = 1\r
- elif re.search(u'\(二\)', pout):\r
- dualaudio = 1\r
- if dualaudio == 1:\r
- tv2audio.ts2dualaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt)\r
- if pentaaudio == 1:\r
- tv2audio.ts2pentaaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt)\r
- if singleaudiosplit == 1:\r
- tv2audio.ts2single_fp_BonTsDemux(aviin, opt)\r
- except Exception, inst:\r
- recdblist.addCommonlogEX("Error", "b252ts(tv2avi.py)", str(type(inst))+traceback.format_exc(), str(inst))\r
- status.changeB25Decoding(-1)\r
-def ts2avi(pin, pout, opt):\r
- status.changeEncoding(1)\r
- try:\r
- ts2x264.ts2x264(pin, pout, opt)\r
- except Exception, inst:\r
- recdblist.printutf8("error occures in tv2avi.py ts2avi")\r
- recdblist.printutf8(str(type(inst)))\r
- recdblist.printutf8(str(inst)+traceback.format_exc())\r
- status.changeEncoding(-1)\r
-def ts2raw(pin, pout, opt):\r
- status.changeEncoding(1)\r
- try:\r
- ts2x264.ts2x264(pin, pout, opt)\r
- except Exception, inst:\r
- recdblist.printutf8("error occures in tv2avi.py ts2raw")\r
- recdblist.printutf8(str(type(inst)))\r
- recdblist.printutf8(str(inst)+traceback.format_exc())\r
- status.changeEncoding(-1)\r
-\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import os\r
-import os.path\r
-import tv2mp4\r
-import configreader\r
-import subprocess\r
-import auto_process\r
-def ts2mkv(pin, pout, opt):\r
- tpout=pout.replace(".mkv",".mp4")\r
- tv2mp4.ts2mp4(pin, tpout, opt)\r
- mp42mkv(pout, tpout)\r
- if os.path.exists(pout) and os.path.getsize(pout)>os.path.getsize(tpout)*0.9:\r
- os.remove(tpout)\r
-def mp42mkv(pmkv,pmp4):\r
- exe = configreader.getConfPath("mkvmerge")\r
- e1=exe +" -o \""+pmkv+u"\" \""+pmp4+"\""\r
- p=subprocess.Popen(e1,shell=True)\r
- os.waitpid(p.pid, 0)\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-import commands\r
-import shutil\r
-import auto_process\r
-import os\r
-import re\r
-import os.path\r
-import string\r
-import base64\r
-import time\r
-import subprocess\r
-import traceback\r
-import zip\r
-\r
-import tv2avi\r
-import recdblist\r
-import configreader\r
-import status\r
-import tv2audio\r
-path = str(os.path.dirname(os.path.abspath(__file__))) + "/"\r
-tmppath = configreader.getConfPath("tmp")+"/"\r
-if tmppath=="/":\r
- tmppath=path\r
-if not os.path.exists(tmppath):\r
- os.mkdir(tmppath)\r
-def ts2mp4(pin, pout, opt):\r
- dir=os.path.split(pout)[0]\r
- title=os.path.split(pout)[1]\r
- title=os.path.splitext(title)[0]\r
- tpraw=os.path.join(dir, title+".264")\r
- tpmp4=os.path.join(dir, title+".mp4")\r
- if os.path.isfile(pin) and os.path.getsize(pin)>10*1000:\r
- tv2avi.ts2raw(pin, tpraw, opt)\r
- time.sleep(10)\r
- if os.path.isfile(tpraw) and os.path.getsize(tpraw)>10*1000:\r
- raw2mp4(tpraw, tpmp4, opt)\r
- time.sleep(10)\r
- if os.path.exists(tpraw) and not re.search("B",opt):\r
- os.remove(tpraw)\r
- zip.addFile2FileZip(recdblist.getLogTitle(pin)+".command.log", recdblist.getLogTitle(pin)+".log.zip")\r
- if os.path.exists(recdblist.getLogTitle(pin)+".command.log"):\r
- os.remove(recdblist.getLogTitle(pin)+".command.log")\r
-def raw2mp4(pin,pout,opt):\r
- dir=os.path.split(pout)[0]\r
- title=os.path.split(pout)[1]\r
- title=os.path.splitext(title)[0]\r
- duration="-fps 29.970030 "\r
- if re.search("a",opt):\r
- duration="-fps 23.976023 "\r
- if re.search("I",opt):\r
- duration="-fps 29.970030 "\r
- exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath\r
- txt=""\r
- os.environ['LANG']="ja_JP.UTF-8"\r
- pints=pin.replace(".264",".ts")\r
- e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\""\r
- execmp4box(pin, pout, e1)\r
- addAudio(pints, pout, opt)\r
- addCaption(pints, pout)\r
- if status.getSettings_auto_del_tmp()==1:\r
- if os.path.exists(pout):\r
- if re.search("t",opt):\r
- auto_process.deleteTmpFile(dir, title, ".264")\r
- elif re.search("k",opt):\r
- ""#削除しない\r
- else:\r
- auto_process.deleteTmpFile(dir, title, ".mp4")\r
-def mkv2mp4(pin,pout):\r
- exeb = configreader.getConfPath(u"mkvextract")\r
- exe = configreader.getConfPath(u"mp4Box")\r
- #dtsedit=configreader.getConfPath("DtsEdit")\r
- wineexe=configreader.getConfPath("wine")\r
- dir=os.path.split(pin)[0]\r
- title=os.path.split(pin)[1]\r
- title=os.path.splitext(title)[0]\r
- etitle=base64.b16encode(title.encode('utf-8'))\r
- audiopath=os.path.join(dir,etitle+u"_audio.aac")\r
- videopath=os.path.join(dir,etitle+u"_video.264")\r
- timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt")\r
- tmpmp4=os.path.join(dir,etitle+u".tmp.mp4")\r
- exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"\r
- exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"\r
- exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'"\r
- exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'"\r
- os.environ['LANG']="ja_JP.UTF-8"\r
- txt=""\r
- try:\r
- txt=txt+execcomd(exe0)+"\n"\r
- txt=txt+execcomd(exe1)+"\n"\r
- txt=txt+execcomd(exe2)+"\n"\r
- txt=txt+execcomd(exe3)+"\n"\r
- except:\r
- ""\r
- recdblist.addLog(pin, txt, u"MKV2MP4-log")\r
- txt = "\n####MKV2MP4-log####\n"+txt\r
- time.sleep(10)\r
- if status.getSettings_auto_del_tmp()==1:\r
- if os.path.exists(pout):\r
- auto_process.deleteTmpFile(dir, title, ".mp4")\r
-def addCaption(pts,pmp4):##字幕の追加を試みる。\r
- wineexe=configreader.getConfPath("wine")\r
- pincap=pts.replace(".ts",".srt")\r
- try:\r
- cap2ass=configreader.getConfPath("caption2ass")\r
- except:\r
- cap2ass=""\r
- if os.path.isfile(cap2ass):\r
- e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pts+"\" \"Z:\\"+pincap+"\""\r
- recdblist.printutf8(e0)\r
- p0=subprocess.Popen(e0,shell=True,stdout=subprocess.PIPE)\r
- time.sleep(100)\r
- if p0.poll==None:#実行中\r
- #if os.path.getsize(pincap)<1000:#2mで1kb以下の場合自動で終了\r
- # os.kill(p0.pid,signal.SIGKILL)\r
- #else:\r
- os.waitpid(p0.pid, 0)\r
- logt=unicode(p0.communicate()[0], "UTF-8")\r
- recdblist.addLog(pts,e0, u"Captionログ-コマンド")\r
- recdblist.addLog(pts,logt, u"Captionログ-詳細")\r
- recdblist.addCommandLogZip(pts, "mp4box_caption", "mp4box_caption", e0, logt)\r
- if os.path.exists(pincap):\r
- if os.path.getsize(pincap)>1000:\r
- exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath\r
- e1s=exe +u" -add \""+pincap+"\" \""+pmp4+"\""\r
- addmp4(pincap,pmp4,e1s)\r
-def addAudio(pts,pmp4,opts):#オプションに応じた音声の追加を行う\r
- exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath\r
- if re.search("d",opts) or re.search("5",opts):#二カ国語放送/5.1ch放送の場合\r
- paac1=pts.replace(".ts","_1.aac")\r
- paac2=pts.replace(".ts","_2.aac")\r
- recdblist.printutf8(paac1)\r
- e1a1=exe +u" -add \""+paac1+"\":mpeg4 \""+pmp4+"\""\r
- e1a2=exe +u" -add \""+paac2+"\":mpeg4 \""+pmp4+"\""\r
- if not os.path.exists(paac1):\r
- paac1=pts.replace(".ts","_1.mp3")\r
- e1a1=exe +u" -add \""+paac1+"\" \""+pmp4+"\""\r
- if not os.path.exists(paac2):\r
- paac2=pts.replace(".ts","_2.mp3")\r
- e1a1=exe +u" -add \""+paac2+"\" \""+pmp4+"\""\r
- if os.path.exists(paac1):\r
- addmp4(paac1, pmp4, e1a1)\r
- if os.path.exists(paac2):\r
- addmp4(paac2, pmp4, e1a2)\r
- elif re.search("b",opts):#BonTsDemuxを使って音声をスプリットした場合\r
- paac=pts.replace(".ts",".aac")\r
- e1a=exe +u" -add \""+pinaac+"\":mpeg4 \""+pmp4+"\""\r
- if not os.path.exists(paac):\r
- paac=pts.replace(".ts",".mp3")\r
- e1a1=exe +u" -add \""+paac+"\" \""+pmp4+"\""\r
- if os.path.exists(paac):\r
- addmp4(paac, pmp4, e1a1)\r
- else:\r
- tv2audio.ts2single_audio(pts,opts)\r
- pinaac=pts.replace(".ts",".aac")\r
- e1a=exe +u" -add \""+pinaac+"\":mpeg4 \""+pmp4+"\""\r
- if not os.path.exists(pinaac):\r
- pinaac=pinaac.replace(".aac",".mp3")\r
- e1a=exe +u" -add \""+pinaac+"\" \""+pmp4+"\""\r
- if os.path.exists(pinaac):\r
- addmp4(pinaac, pmp4, e1a)\r
-def execmp4box(pin,pout,cmd):\r
- title=os.path.splitext(os.path.split(pin)[1])[0]\r
- nt=base64.b16encode(title.encode('utf-8'))\r
- if len(nt)>200:\r
- nt=nt[:180]\r
- ptin=os.path.join(os.path.dirname(pin),nt+".264")\r
- recdblist.printutf8(ptin)\r
- shutil.move(pin,ptin)\r
- time.sleep(10)\r
- ptout=os.path.join(os.path.dirname(pout),nt+".mp4")\r
- cmdn=string.replace(cmd,pin,ptin)\r
- cmdn=string.replace(cmdn,pout,ptout)\r
- recdblist.printutf8(cmdn)\r
- recdblist.addCommandSelfLog(pin, cmdn)\r
- txt=""\r
- try:\r
- txt=execcomd(cmdn)\r
- except Exception, inst:\r
- txt= "error occures in execmp4box\n"\r
- txt=txt+ str(type(inst))+"\n"\r
- txt=txt+str(inst)\r
- recdblist.addCommonlogEX("Error", "excecmp4box(tv2mp4.py)", str(type(inst)), str(inst)+traceback.format_exc(),verbose_level=200,log_level=200)\r
- recdblist.addLog(pin, cmdn, u"MP4Boxログ-コマンド")\r
- recdblist.addLog(pin, txt, u"MP4Boxログ-詳細")\r
- recdblist.addCommandLogZip(pin, "MP4Box", "mp4box", cmdn,txt)\r
- time.sleep(5)\r
- shutil.move(ptin,pin)\r
- shutil.move(ptout,pout)\r
- time.sleep(5)\r
-def addmp4(padd,pout,cmd):#without video\r
- title=os.path.splitext(os.path.split(padd)[1])[0]\r
- ext=os.path.splitext(os.path.split(padd)[1])[1]\r
- nt=base64.b16encode(title.encode('utf-8'))\r
- if len(nt)>200:\r
- nt=nt[:180]\r
- ptadd=os.path.join(os.path.dirname(padd),nt+ext)\r
- ptoutb=os.path.join(os.path.dirname(pout),nt+"_b.mp4")\r
- ptout=os.path.join(os.path.dirname(pout),nt+".mp4")\r
- shutil.move(padd,ptadd)\r
- if os.path.isfile(pout):\r
- shutil.move(pout,ptoutb)\r
- time.sleep(5)\r
- cmdn=string.replace(cmd,padd,ptadd)\r
- cmdn=string.replace(cmdn,u"-out \""+pout,u"-add \""+ptoutb+"\" -new \""+ptout)\r
- cmdn=string.replace(cmdn,u"\""+pout,u"-add \""+ptoutb+"\" -new \""+ptout)\r
- cmdn=string.replace(cmdn,pout,ptout)\r
- recdblist.printutf8(cmdn)\r
- txt=""\r
- try:\r
- txt=execcomd(cmdn)\r
- except Exception, inst:\r
- txt= "error occures in addmp4\n"\r
- txt=txt+ str(type(inst))+"\n"\r
- txt=txt+str(inst)\r
- recdblist.addLog(pout, cmdn, u"MP4Box追加ログ-コマンド")\r
- recdblist.addLog(pout, txt, u"MP4Box追加ログ-詳細")\r
- recdblist.addCommandLogZip(pout, "MP4Box_add", "mp4box_add", cmdn, txt)\r
- time.sleep(5)\r
- shutil.move(ptadd,padd)\r
- if os.path.exists(ptout):\r
- shutil.move(ptout,pout)\r
- os.remove(ptoutb)\r
- else:\r
- txtt=padd+u"のインポートエラー"\r
- recdblist.addLog(pout, txtt, u"MP4Box追加ログ-コマンド")\r
- shutil.move(ptoutb,pout)\r
- time.sleep(5)\r
-def execcomd(cmd):\r
- txt=""\r
- try:\r
- txt=u"Cmd : "+cmd+"\n"\r
- txt2=commands.getoutput(cmd.encode('utf-8'))\r
- txt=txt+unicode(txt2,"utf-8")+"\n"\r
- except:\r
- ""\r
- return txt\r
+#!/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\r
-# coding: UTF-8\r
-# Rec10 TS Recording Tools\r
-# Copyright (C) 2009-2011 Yukikaze\r
-\r
-import xml.dom.minidom\r
-import datetime\r
-import re\r
-import traceback\r
-\r
-import zenhan\r
-import chdb\r
-import auto_rec\r
-import recdb\r
-import rec10d\r
-import n_gram\r
-import recdblist\r
-import epgdb\r
-import status\r
-def getText(elm):\r
- nodelist = elm.childNodes\r
- rc = ""\r
- # 全てのノードに対して\r
- for node in nodelist:\r
- # テキストノードなら値を取得\r
- if node.nodeType == node.TEXT_NODE:\r
- rc = rc + node.data\r
- return rc\r
-def getText_item(obj):\r
- rc=""\r
- for o in obj:\r
- rc=rc+getText(o)\r
- return rc\r
-def writeMultiTVDB(bctype,tvlists):\r
- rec10d.rec10db.new_epg_timeline(bctype)\r
- for channel,start,stop,title,desc,longdesc,category in tvlists:\r
- rec10d.rec10db.add_epg_timeline(bctype, channel, start, stop, title, desc, longdesc, category)\r
-def writeMultiCHDB(chlists):\r
- for chtxt,dn in chlists:\r
- rec10d.rec10db.update_chname_by_chtxt_epg_ch(chtxt,dn)\r
- if dn==None:\r
- chdb.changeCHShow(chtxt,"0")\r
- else:\r
- if len(dn)<1:\r
- chdb.changeCHShow(chtxt,"0")\r
-def writeMultiLogoDB(logolists):\r
- #[type,sv,pngdata]\r
- for type,sv,pngdata in logolists:\r
- chtxt=chdb.searchCHFromCsch(sv)['chtxt']\r
- if len(chtxt)>0:\r
- rec10d.rec10db.change_logodata_epg_ch(chtxt,type,pngdata)\r
-def xml2db_dom(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る\r
- dtb=datetime.datetime.now()\r
- dom=xml.dom.minidom.parse(file(xmlpath))\r
- chlist=[]\r
- tvlist=[]\r
- bayes={}\r
- rHisch=re.compile(u"『([^『]+)』(.+)\Z")##History CHのタイトル#01 exp:「#01説明」をタイトルに含める\r
- for ch in dom.getElementsByTagName('channel'):\r
- chtxtt=ch.getAttribute("id")\r
- chname=ch.getElementsByTagName("display-name").item(0).childNodes[0].data\r
- chlist.append([chtxtt,chname])\r
- for tv in dom.getElementsByTagName('programme'):\r
- channel=zenhan.toHankaku_ABC123(tv.getAttribute("channel"))\r
- start=tv.getAttribute("start").replace(" +0900", "")\r
- stop=tv.getAttribute("stop").replace(" +0900", "")\r
- title=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("title"))).replace(",", "_")\r
- desc=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("desc")))\r
- longdesc=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("longdesc")))\r
- category=zenhan.toHankaku_ABC123(getText_item(tv.getElementsByTagName("category")))\r
- title=addTitle_Subtitle(rHisch,1,title,desc)\r
- tch=chdb.searchCHFromChtxt(channel)\r
- if tch!=None:\r
- if tch.get('bctype',"")==bctype and not tch['visible']==0:\r
- bt=bayes.get(tch['chtxt'],["","",0])\r
- bt2=[bt[0]+title+" ",bt[1]+desc+" "+longdesc+" ",bt[2]+1]\r
- bayes[tch['chtxt']]=bt2\r
- tvlist.append([channel,start,stop,title,desc,longdesc,category])\r
- p=auto_rec.calcKey(tch['chtxt'], title,desc+" "+longdesc)\r
- if p>2000:\r
- bttt=datetime.datetime.strptime(start,"%Y%m%d%H%M%S")\r
- bttt=bttt-datetime.timedelta(seconds=1200)\r
- bttime=bttt.strftime("%Y-%m-%d %H:%M:%S")\r
- ettt=datetime.datetime.strptime(stop,"%Y%m%d%H%M%S")\r
- ettt=ettt+datetime.timedelta(seconds=1200)\r
- ettime=ettt.strftime("%Y-%m-%d %H:%M:%S")\r
- chs=rec10d.rec10db.select_bytime_bychtxt_all_timeline(bttime,ettime,tch['chtxt'])\r
- p2=0\r
- if len(chs)>0:\r
- for ch in chs:\r
- p2t=n_gram.trigram(ch['title'],title)\r
- if p2t>p2:\r
- p2=p2t\r
- if p2<350:\r
- if status.getSettings_auto_bayes()==1:\r
- if p2<200:\r
- maxnum=0\r
- if len(ch['ch'])>2:\r
- maxnum=epgdb.count_schedule_timeline(bttime, ettime)[1]\r
- maxnum=int(configreader.getConfEnv("bscs_max"))-maxnum\r
- else:\r
- maxnum=epgdb.count_schedule_timeline(bttime, ettime)[0]\r
- maxnum=int(configreader.getConfEnv("te_max"))-maxnum\r
- if maxnum>0:\r
- topt=status.getSettings_auto_opt()\r
- recdb.reserveReckey(recdblist.REC_RESERVE,title,tch['chtxt'], bttime, ettime,topt)\r
- else:\r
- recdb.addAutoBayesKeyword(tch['chtxt'],title,start,stop,p)\r
- dom.unlink()\r
- if len(chlist) > 0:\r
- writeMultiCHDB(chlist)\r
- chlist = []\r
- if len(tvlist) > 0:\r
- writeMultiTVDB(bctype,tvlist)\r
- tvlist = []\r
- for ct,list in bayes.items():\r
- auto_rec.updateRecall(ct,list[0],list[1],list[2])\r
- auto_rec.updateRecall("ALL",list[0],list[1],list[2])\r
- dtb=datetime.datetime.now()-dtb\r
- recdblist.printutf8(bctype + u" epg取り出し終了")\r
- recdblist.printutf8(str(dtb.days * 24 * 60 * 60 + dtb.seconds)+u"seconds taken for updating bayes-auto DB .")\r
-def xml2db_dom_logo(xmlpath, bctype):#bctypeは放送種別で'TE'(地デジ)BS,CSがある。地デジの場合は te数字 が入る\r
- dtb=datetime.datetime.now()\r
- dom=xml.dom.minidom.parse(file(xmlpath))\r
- logolist=[]\r
- for logo in dom.getElementsByTagName('logo'):\r
- type=int(logo.getAttribute("type"))\r
- sv=logo.getAttribute("sv")\r
- pngdata=logo.childNodes[0].data\r
- logolist.append([type,sv,pngdata])\r
- dom.unlink()\r
- if len(logolist) > 0:\r
- writeMultiLogoDB(logolist)\r
- dtb=datetime.datetime.now()-dtb\r
- recdblist.printutf8(bctype + u" epg取り出し終了")\r
- recdblist.printutf8(str(dtb.days * 24 * 60 * 60 + dtb.seconds)+u"seconds taken for updating logo DB .")\r
-def addTitle_Subtitle(recompiled,num,title,exp):\r
- try:\r
- tST=recompiled.match(exp)\r
- newtitle=u""\r
- if tST:\r
- newtitle=title+u"『"+tST.group(num)+u"』"\r
- else:\r
- newtitle=title\r
- except Exception, inst:\r
- recdblist.addCommonlogEX("Error", "addTitle_Subtitle(xml2db_dob.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)\r
- newtitle=title\r
- return newtitle\r
+#!/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
global h_ascii
global z_number
global h_number
-z_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !”#$%&’()*+,−./:;<=>?@[¥]^_â\80\98ï½\9bï½\9cï½\9dã\80\9cã\80\80ã\80\9c"
+z_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !”#$%&’()*+,−./:;<=>?@[¥]^_â\80\98ï½\9bï½\9cï½\9dã\80\9cã\80\80ã\80\9c"
h_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ -"
z_ascii_sp = unichr(0x2212)+unichr(0xff0e)
h_ascii_sp = unichr(0x002d)+unichr(0x002e)