OSDN Git Service

stop using trunk directory in rectool
[rec10/rec10-git.git] / rec10 / trunk / src / auto_process.py
index 65d0cf7..fabee05 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # coding: UTF-8
 # Rec10 TS Recording Tools
-# Copyright (C) 2009-2010 Yukikaze
+# Copyright (C) 2009-2011 Yukikaze
 import os
 import glob
 import time
@@ -17,8 +17,9 @@ import recdblist
 import rec10d
 import tv2mp4
 import epgdb
-def Update_to_MP4(path):
+def updateToMP4(path):
     """
+    !現在未使用!
     録画一時フォルダ内mp4ファイルを検索
     """
     avilist = glob.glob(path + "/*.avi")
@@ -55,7 +56,7 @@ def Update_to_MP4(path):
                             if mkvdtime>300:
                                 recdblist.printutf8(mkvpath+":"+mp4path)
                                 tv2mp4.mkv2mp4(mkvpath,mp4path)
-def auto_check(path):
+def autoCheck(path):
     avilist = glob.glob(path + "/*.avi")
     mkvlist = glob.glob(path+"/*.mkv")
     mp4list = glob.glob(path+"/*.mp4")
@@ -71,13 +72,13 @@ def auto_check(path):
                 dir = os.path.split(fn)[0]
                 file = os.path.split(fn)[1]
                 title = os.path.splitext(file)[0]
-                title = unicode(title,'utf-8')
+                title = unicode(title,'utf-8',errors='replace')
                 ext = os.path.splitext(file)[1]
                 if ext == ".b25":
                     title=title.replace(".ts","")
                 dbs=rec10d.rec10db.select_by_name_time_timeline(title,tbtime,tbtime2)
                 if len(dbs)==0:
-                    proc=check_process(dir, title)
+                    proc=checkProcess(dir, title)
                     chtxtt=rec10d.rec10db.select_chtxt_by_title_timeline_log(title)
                     nchtxt=""
                     if chtxtt!=None:
@@ -109,7 +110,7 @@ def auto_check(path):
     mp4making
     mp4
 """
-def check_process(path,title):
+def checkProcess(path,title):
     path1 = os.path.join(path,title+".mkv")
     if os.path.exists(path1):
         if int(time.time()-os.path.getmtime(path1))>300:
@@ -160,9 +161,9 @@ def update_timeline_epg_schedule(btime,etime):
         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.searchtime2(db['title'], db['btime'], db['deltatime'], db['chtxt'])
+            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])
+                rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4],ret[6])
                 if not (db['btime'] == ret[2] and  db['etime']==ret[3]):
                     rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
                 else:
@@ -170,9 +171,9 @@ def update_timeline_epg_schedule(btime,etime):
             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.searchtime2(db['title'], db['btime'],"5", db['chtxt'])
+            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])
+                rec10d.rec10db.update_epg_timeline(db['type'], db['chtxt'], db['title'], db['btime'], ret[2],ret[3],ret[1],ret[4],ret[6])
                 if not (db['btime'] == ret[2] and  db['etime']==ret[3]):
                     rec10d.rec10db.update_status_change_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
                 else:
@@ -183,9 +184,9 @@ 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.count_epgschedule(db['epgbtime'], db['epgetime'])
+            dbn=epgdb.countEpgSchedule(db['epgbtime'], db['epgetime'])
             try:
-                bctypet=chdb.chtxtsearch(db['chtxt'])['bctype']
+                bctypet=chdb.searchCHFromChtxt(db['chtxt'])['bctype']
                 if bctypet.find("cs") > -1 or bctypet.find("bs") > -1 :
                     if dbn[1]>status.getRecordingMax()[1]:
                         rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "1")
@@ -198,45 +199,45 @@ def update_timeline_dup(epgbtime,epgetime):
                         rec10d.rec10db.update_status_dup_timeline(db['type'], db['chtxt'], db['title'], db['btime'], "0")
             except:
                 ""
-def kill_dead_encode(path):
+def killDeadEncode(path):
     rawlist = glob.glob(path + "/*.264")
     for fn in rawlist:
         if int(time.time()-os.path.getmtime(fn))>3000:
-            #print fn
-
-            tspath=unicode(fn.replace(".264",".ts"),'utf-8')
             m2vpath=unicode(fn.replace(".264",".m2v"),'utf-8')
-            x264path=unicode(fn.replace(".264",".264"),'utf-8')
+            x264path=os.path.split(fn)[1]
+            folderpath=unicode(os.path.split(fn)[0],'utf-8')
+            x264path=re.sub("\\[","[",x264path)
+            x264path=re.sub("\[","\\\[",x264path)
+            x264path=re.sub("\\]","]",x264path)
+            x264path=re.sub("]","\\]",x264path)
+            tspath=unicode(x264path.replace(".264",".ts"),'utf-8')
+            m2vpath=unicode(x264path.replace(".264",".m2v"),'utf-8')
+            x264path=unicode(x264path,'utf-8')
             os.environ['LANG']="ja_JP.UTF-8"
-
-            #ktmp=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):
+            ktmp=[]
+            ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+x264path+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep x264 | awk '{print $2}'")
+            ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+tspath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'")
+            ktmp.append(u"ps auxww | grep \""+folderpath+"\" | grep \""+m2vpath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep ffmpeg | awk '{print $2}'")
+            recdblist.printutf8(u"エンコード処理異常終了タスク終了")
+            for istr in ktmp:
+                recdblist.printutf8(istr)
+                ktmt=commands.getoutput(istr.encode('utf-8'))
+                #print ktmt
+                #print len(ktmt)
+                if len(ktmt)>0:
+                    #print ktmt
+                    if len(ktmt[0])>0:
+                        ktmt=ktmt[0]
+                    #print ktmt
+                try:
+                    if int(ktmt)>0:
+                        ktmp=u"kill -9 `"+istr+u"`"
+                        recdblist.printutf8(ktmp)
+                        #print ktmp
+                        os.system(ktmp.encode('utf-8'))
+                except:
+                    ""
+def deleteTmpFile(path,title,ext):
     level= 0##0:b25 1:ts(del tsmix and ts.b25) 5:x264(del 2 and so on) 10:mp4/mkv
     smsize= 0
     if re.search(".ts",ext):
@@ -254,10 +255,12 @@ def deltmpfile(path,title,ext):
     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"))*10>os.path.getsize(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.getenv("remove_ts")=="1":
+        if configreader.getConfEnv("remove_ts")=="1":
             dp.append(os.path.join(path,title+".ts"))
     if level > 9 :
         dp.append(os.path.join(path,title+".avi"))
@@ -279,4 +282,4 @@ def deltmpfile(path,title,ext):
                 try:
                     os.remove(ip)
                 except:
-                    ""
\ No newline at end of file
+                    ""