OSDN Git Service

fix encode for mobile function.(option 8,9,0)
[rec10/rec10-git.git] / rec10 / trunk / src / auto_move.py
index 63cd020..f04e422 100644 (file)
@@ -1,4 +1,3 @@
-import shutil
 #!/usr/bin/python
 # coding: UTF-8
 # Rec10 TS Recording Tools
@@ -9,9 +8,10 @@ import os
 import os.path
 import re
 import time
+import shutil
 
-import n_gram
 import recdblist
+import guess
 def getTitle(title):
     rT=re.compile("(.+)_(\d+)\Z")
     tT=rT.match(title)
@@ -35,31 +35,9 @@ def getTitle(title):
     elif tT5:
         ntitle=tT5.group(1)
     return ntitle
-def detNameType(title):
-    """
-    type A ---title#<number>
-    type B ---title#<number>subtitle
-    type C ---title subtitle
-    type D ---title(without number)
-    """
-    recdblist.printutf8(title)
-    #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
-    rA=re.compile("(.+)#(\d*)\s*\Z")
-    tA=rA.match(title)
-    rB=re.compile("(.+)#(\d*)\s*(\D*)")
-    tB=rB.match(title)
-    if tA:
-        recdblist.printutf8("typeA")
-        recdblist.printutf8("title="+tA.group(1))
-        recdblist.printutf8("num="+tA.group(2))
-    elif tB:
-        recdblist.printutf8("typeB")
-        recdblist.printutf8("title="+tB.group(1))
-        recdblist.printutf8("num="+tB.group(2))
-        recdblist.printutf8("subtitle="+tB.group(3))
 def search_file(temppath,recpath,ext):
     """
-    録画一時フォルダ内mkvファイルを検索
+    録画一時フォルダ内ファイルを検索
     """
     avilist = glob.glob(temppath + "/*"+ext)
     ret=[]
@@ -118,63 +96,11 @@ def veryfySize(path):
     if os.path.getsize(path)>270*1024*1024:
         ret=1
     return ret
-def searchFolder(title,path,threshold=500):
-    """
-    titleにマッチするフォルダを探し出す。
-    """
-    folderpath=os.listdir(path)
-    lfpath=[]
-    ngram=[]
-    for ft in folderpath:
-        fullpath=os.path.join(path.encode('utf-8'), ft)
-        if os.path.isdir(fullpath):
-            lfpath.append(fullpath)
-            ftt=os.listdir(fullpath)
-            if len(ftt)>0:
-                for ft2 in ftt:
-                    try:
-                        folderpath.append(os.path.join(fullpath, ft2))
-                    except Exception, inst:
-                        #print type(inst)
-                        #print inst
-                        ""
-        else:
-            lfpath.append(fullpath)
-    for dirp in lfpath:
-        cmpp=""
-        appp=""
-        ntitle=title
-        if os.path.isdir(dirp):
-            cmpp=os.path.dirname(dirp)
-            appp=dirp
-        else:
-            cmpp=os.path.basename(dirp)
-            appp=os.path.dirname(dirp)
-        ntitle=getTitle(title)
-        #recdblist.printutf8(cmpp)
-        cmpp=getTitle(os.path.splitext(cmpp)[0])
-        #recdblist.printutf8(cmpp+"\n")
-        p=n_gram.trigram(ntitle,cmpp)
-        if p>0:
-            ngram.append((p,appp))
-    ngram=list(set(ngram))
-    ngram.sort()
-    ngram.reverse()
-    if len(ngram)>0:
-        #recdblist.printutf8(title + ngram[0][1] + " : "+str(ngram[0][0]))
-        if ngram[0][0]>threshold:
-            return ngram[0][1]
-        else:
-            return ""
-    else:
-        return ""
 def execMove(title,temppath,recpath,ext,autodel):
     srcpath=os.path.join(temppath,title+ext)
-    #desttitle=destName(title, temppath, recpath)
-
-    sf=searchFolder(title, recpath)
+    sf=guess.searchFolder(title, recpath)
     if sf!="":
-        destpath=os.path.join(sf,destNameMKV(title, temppath, sf)+ext)
+        destpath=os.path.join(sf,get_move_dest_path(title, temppath, sf, ext)+ext)
         recdblist.printutf8("moving now..")
         recdblist.printutf8(srcpath+" : "+destpath)
         print srcpath