OSDN Git Service

fix rename miss.
authorgn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Fri, 3 Dec 2010 14:45:44 +0000 (14:45 +0000)
committergn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Fri, 3 Dec 2010 14:45:44 +0000 (14:45 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@780 4e526526-5e11-4fc0-8910-f8fd03428081

24 files changed:
rec10/trunk/src/auto_move.py
rec10/trunk/src/auto_process.py
rec10/trunk/src/auto_test.py
rec10/trunk/src/chdata.py
rec10/trunk/src/chdb.py
rec10/trunk/src/classify.py
rec10/trunk/src/configreader.py
rec10/trunk/src/configwriter.py
rec10/trunk/src/epgdb.py
rec10/trunk/src/install.py
rec10/trunk/src/rec10d.py
rec10/trunk/src/recdb.py
rec10/trunk/src/recdblist.py
rec10/trunk/src/recque.py
rec10/trunk/src/scan_ch.py
rec10/trunk/src/status.py
rec10/trunk/src/timerec.py
rec10/trunk/src/ts2epg.py
rec10/trunk/src/ts2x264.py
rec10/trunk/src/tv2audio.py
rec10/trunk/src/tv2avi.py
rec10/trunk/src/tv2mkv.py
rec10/trunk/src/tv2mp4.py
rec10/trunk/src/xml2db_dom.py

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