OSDN Git Service

implement auto_delete temp file.
[rec10/rec10-git.git] / rec10 / trunk / src / auto_process.py
index c3ef5d9..65d0cf7 100644 (file)
@@ -6,12 +6,15 @@ 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 os.path
 import tv2mp4
 import epgdb
 def Update_to_MP4(path):
@@ -63,30 +66,31 @@ def auto_check(path):
     tbtime=datetime.datetime.now()+datetime.timedelta(seconds=60)
     tbtime2=datetime.datetime.now()+datetime.timedelta(seconds=1200)
     for fn in filelist:
-        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 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:
@@ -158,7 +162,7 @@ def update_timeline_epg_schedule(btime,etime):
         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'])
             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])
+                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:
@@ -168,7 +172,7 @@ def update_timeline_epg_schedule(btime,etime):
         elif db['type']==recdblist.REC_RESERVE or db['type']==recdblist.REC_FINAL_RESERVE :
             ret=epgdb.searchtime2(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])
+                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:
@@ -198,12 +202,81 @@ 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"kill -9 `ps auxw | grep \""+tspath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'`"
-            kmmp=u"kill -9 `ps auxw | grep \""+m2vpath+u"\" | egrep -v grep | egrep -v \"sh -c\" | grep mencoder | awk '{print $2}'`"
+
+            #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)
-            #recdblist.printutf8(kmmp)
-            os.system(ktmp.encode('utf-8'))
-            os.system(kmmp.encode('utf-8'))
+            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"))*10>os.path.getsize(os.path.join(path,title+".ts.b25")):
+                dp.append(os.path.join(path,title+".ts.b25"))
+    if level > 4 :
+        if configreader.getenv("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