OSDN Git Service

implement seriesnum determinant system.
[rec10/rec10-git.git] / rec10 / trunk / src / guess.py
index 83188c1..5e1f6ca 100644 (file)
@@ -1,3 +1,4 @@
+import os.path
 #!/usr/bin/python
 # coding: UTF-8
 # Rec10 TS Recording Tools
@@ -11,14 +12,27 @@ import datetime
 import n_gram
 import recdblist
 import zenhan
+import auto_move
 
 def detName(title,path):
     tt=detNameType(title, path)
     if tt['type']=="C"or tt['type']=="D":
         tt['num']=detNum(tt['title'],tt['folder'])
+def detSeriesNum(execpath):
+    files=os.listdir(execpath)
+    ss={}
+    for file in files:
+        ftitle=os.path.splitext(file)
+        fname=ftitle[0]
+        fname=zenhan.toHankaku(unicode(name))
+        st=detNameType(fname, execpath)['title']
+        if not len(ss[st])>0:
+            ss[st]=[]
+        ss[detNum(fname,execpath)]=ftitle
+    return ss
 def detNum(title,movepath):
     """
-        #
+        #番組の話数を推測する。
     """
     files=os.listdir(movepath)
     ff=[]
@@ -38,7 +52,7 @@ def detNum(title,movepath):
                 ff.append([p1['num'],p1['title'],time1])
                 if maxnum<p1['num']+1:
                     maxnum=p1['num']+1
-    detMultiDeltaDays(ff)
+    return detMultiDeltaDays(ff)
 def detMultiDeltaDays(num_with_title_with_dates):
     maxnum=0
     for ft in num_with_title_with_dates:
@@ -56,13 +70,13 @@ def detMultiDeltaDays(num_with_title_with_dates):
             for ft3 in f3[i]:
                 for ft4 in f3[j]:
                     for gdd in detSingleDeltaDay(i, ft3[2], j, ft4[2]):
-                        print gdd
+                        #print gdd
                         if fret.get(gdd[0])!=None:
-                            print fret
+                            #print fret
                             fret[gdd[0]]=fret[gdd[0]]+gdd[1]
                         else:
                             fret[gdd[0]]=gdd[1]
-    print fret
+    #print fret
     maxk=0
     maxp=0
     for i in range(maxnum):
@@ -70,8 +84,8 @@ def detMultiDeltaDays(num_with_title_with_dates):
             if maxp<fret[i]:
                 maxk=i
                 maxp=fret[i]
-    print maxk
-    print maxp
+    #print maxk
+    #print maxp
     return maxk
 def detSingleDeltaDay(num1,date1,num2,date2):
     dd=date1-date2
@@ -112,6 +126,7 @@ def detNameType(title,path):
     path --search reflexively
     """
     recdblist.printutf8(title)
+    title=auto_move.getTitle(title)##titleから日時を除く
     #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
     rA=re.compile("(.+)#(\d*)\s*\Z")
     tA=rA.match(title)
@@ -155,7 +170,7 @@ def detNameType(title,path):
             tt=tt+" "+t
             ft1=searchFolder(tt,path)
             recdblist.printutf8(tt)
-            print ft1
+            #print ft1
             if ft1!="":
                 #recdblist.printutf8(rt)
                 #recdblist.printutf8(ft1[0]+" : "+str(ft1[1]))
@@ -175,7 +190,7 @@ def detNameType(title,path):
         else:
             ret['type']="C"
     return ret
-def searchFolder(title,path,threshold=300):
+def searchFolder(title,path,threshold=500):
     """
     titleからフォルダーを探す
     """
@@ -201,7 +216,9 @@ def searchFolder(title,path,threshold=300):
         else:
             cmpp=os.path.basename(dirp)
             appp=os.path.dirname(dirp)
-        p=n_gram.trigram(title.decode("utf-8"),cmpp.decode("utf-8"))
+        ntitle=auto_move.getTitle(title)
+        ncmpp=auto_move.getTitle(cmpp)
+        p=n_gram.trigram(ntitle,ncmpp)
         if p>0:
             ngram.append((p,appp))
     ngram=list(set(ngram))
@@ -210,7 +227,7 @@ def searchFolder(title,path,threshold=300):
     if len(ngram)>0:
         #recdblist.printutf8(title + ngram[0][1] + " : "+str(ngram[0][0]))
         if ngram[0][0]>threshold:
-            return [ngram[0][1],ngram[0][0]]
+            return ngram[0][1]
         else:
             return ""
     else: