OSDN Git Service

fix mkv option of classify.py.
authorgn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Wed, 7 Oct 2009 14:10:52 +0000 (14:10 +0000)
committergn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Wed, 7 Oct 2009 14:10:52 +0000 (14:10 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@175 4e526526-5e11-4fc0-8910-f8fd03428081

rec10/trunk/src/classify.py

index 8d2671f..2708ee6 100644 (file)
@@ -29,6 +29,7 @@ def search_b25(path):
         title = os.path.split(b25f)[1]
         title = title.replace(".ts.b25", "")
         avipath = os.path.join(dir, title + ".avi")
+        mkvpath = os.path.join(dir, title + ".mkv")
         tspath = os.path.join(dir, title + ".ts")
         b25f = b25f.replace(".ts.b25", ".avi")
         mode = "ts"
@@ -42,8 +43,8 @@ def search_b25(path):
                     mode = "tsmiss"
             else:
                 mode = "ts"
-        if os.path.isfile(avipath):##tsファイルが存在している
-            dtime = time.time()-os.path.getmtime(avipath)
+        if os.path.isfile(mkvpath):##tsファイルが存在している
+            dtime = time.time()-os.path.getmtime(mkvpath)
             dtime = int(dtime)
             if dtime > 120:
                 if os.path.getsize(avipath) > 1 * 1000 * 1000:##最終更新から22分以上経過かつ1MB以上
@@ -71,10 +72,30 @@ def search_avi(temppath,recpath):
             if veryfySize(avipath):
                 ret.append(title)
     return ret
+def search_mkv(temppath,recpath):
+    """
+    録画一時フォルダ内mkvファイルを検索
+    """
+    avilist = glob.glob(temppath + "/*.mkv")
+    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(".mkv", "")
+        avipath = os.path.join(dir, title + ".mkv")
+        dtime = time.time()-os.path.getmtime(avipath)
+        dtime = int(dtime)
+        if dtime > 300:
+            if veryfySize(avipath):
+                ret.append(title)
+    return ret
+
 def veryfySize(path):
-    vsize=[297,497,596,1196]#SD 30m 1h 1.5h 2h
-    vsize=vsize+[458,916]#HD 30m 1h
-    vsize=vsize+[381,895,447]
+    #vsize=[297,497,596,1196]#SD 30m 1h 1.5h 2h
+    vsize=[295,591]
+    #vsize=vsize+[458,916]#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:
@@ -120,12 +141,15 @@ def searchFolder(title,path):
     else:
         return ""
 def execMove(title,temppath,recpath):
-    srcpath=os.path.join(temppath,title+".avi")
+    srcpath=os.path.join(temppath,title+".mkv")
     desttitle=destName(title, temppath, recpath)
     sf=searchFolder(title, recpath)
     if sf!="":
-        destpath=os.path.join(sf,desttitle+".avi")
+        destpath=os.path.join(sf,desttitle+".mkv")
+        #print srcpath
+        #print destpath
         shutil.move(srcpath, destpath)
+        #shutil.copy(srcpath, destpath)
         delpath=[os.path.join(temppath,title+".ts")]
         delpath.append(os.path.join(temppath,title+".ts.b25"))
         delpath.append(os.path.join(temppath,title+".ts.tsmix"))
@@ -135,6 +159,7 @@ def execMove(title,temppath,recpath):
         for dp in delpath:
             try:
                 os.remove(dp)
+                ""
             except:
                 ""
 def destName(title,temppath,recpath):
@@ -148,9 +173,24 @@ def destName(title,temppath,recpath):
         times=time.strftime("%y%m%d",gmtime)
         title=title+"_"+times
     return title
+def destNameMKV(title,temppath,recpath):
+    """
+    titleから移動先に作るべきファイル名を作り出す。
+    """
+    dstpath=os.path.join(recpath,title+".mkv")
+    srcpath=os.path.join(temppath,title+".mkv")
+    if os.path.exists(dstpath):
+        gmtime=time.gmtime(os.path.getmtime(srcpath))
+        times=time.strftime("%y%m%d",gmtime)
+        title=title+"_"+times
+    return title
+
+def detName(path,title):
+    ""
+    
 if __name__ == "__main__":
     usage="usage: %prog read -h"
-    version="%prog 0.7.0alpha"
+    version="%prog 0.7.0beta1"
     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)")
@@ -159,24 +199,25 @@ if __name__ == "__main__":
     (opts,args)=parser.parse_args(sys.argv)
     if opts.ltitle!="":
         sf=searchFolder(opts.ltitle, recordedpath)
-        print os.path.join(sf, destName(opts.ltitle,recpath,sf)+".avi")
+        print os.path.join(sf, destNameMKV(opts.ltitle,recpath,sf)+".mkv")
     elif opts.auto:
-        sa=search_avi(recpath, recordedpath)
+        sa=search_mkv(recpath, recordedpath)
         for t in sa:
             print "自動推測実行中"
             sf=searchFolder(t,recordedpath)
             if sf!="":
                 print "移動先"
-                print t+" : "+os.path.join(sf, destName(t, recpath,sf)+".avi")
+                print t+" : "+os.path.join(sf, destNameMKV(t, recpath,sf)+".mkv")
                 print "実行中"
                 execMove(t, recpath, recordedpath)
             else:
                 print t+" can't find matching folder."
     elif opts.list:
-        sa=search_avi(recpath, recordedpath)
+        sa=search_mkv(recpath, recordedpath)
         for t in sa:
             sf=searchFolder(t,recordedpath)
             if sf!="":
-                print t+" : "+os.path.join(sf, destName(t, recpath,sf)+".avi")
+                print t+" : "+os.path.join(sf, destNameMKV(t, recpath,sf)+".mkv")
     elif opts.etitle!="":
-        execMove(opts.etitle,recpath, recordedpath)
\ No newline at end of file
+        execMove(opts.etitle,recpath, recordedpath)
+