3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
14 def detName(title,path):
15 tt=detNameType(title, path)
16 if tt['type']=="C"or tt['type']=="D":
17 tt['num']=detNum(tt['title'],tt['folder'])
18 def detNum(title,movepath):
22 files=os.listdir(movepath)
27 file=os.path.join(movepath,file)
28 if os.path.isfile(file):
29 name=os.path.splitext(os.path.split(file)[1])
31 name=zenhan.toHankaku(unicode(name))
32 p1=detNameType(name,movepath)
33 print p1['title']+" "+str(p1['num'])
34 time1=time.localtime(os.path.getmtime(file))
35 time1=datetime.datetime.fromtimestamp(os.path.getmtime(file))
37 ff.append([p1['num'],p1['title'],time1])
38 if maxnum<p1['num']+1:
41 def detMultiDeltaDays(num_with_title_with_dates):
43 for ft in num_with_title_with_dates:
46 ff=num_with_title_with_dates
49 for i in range(0, maxnum, 1):
53 for i in range(maxnum):
54 for j in range(i+1,maxnum,1):
57 for gdd in detSingleDeltaDay(i, ft3[2], j, ft4[2]):
59 if fret.get(gdd[0])!=None:
61 fret[gdd[0]]=fret[gdd[0]]+gdd[1]
67 for i in range(maxnum):
75 def detSingleDeltaDay(num1,date1,num2,date2):
83 dp=dd+datetime.timedelta(hours=6)
85 dm=dd-datetime.timedelta(hours=6)
94 print str(d)+":"+str(dn)
100 ret.append([dm/d,40])
102 ret.append([dn/d,100])
104 def detNameType(title,path):
106 type A ---title#<number>
107 type B ---title#<number>subtitle
108 type C ---title subtitle
109 type D ---title(without number)
110 type Aj ---title第<number>話
111 path --search reflexively
114 #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
115 rA=re.compile("(.+)#(\d*)\s*\Z")
117 rB=re.compile("(.+)#(\d*)\s*(\D*)")
119 rAj=re.compile("(.+)第(\d*)話\s*\Z")
121 ret={'title':"",'type':"",'num':0,'subtitle':"",'folder':""}
124 print "title="+tA.group(1)
125 print "num="+tA.group(2)
127 ret['title']=tA.group(1)
128 ret['num']=int(tA.group(2))
129 ret['folder']=searchFolder(tA.group(1),path)
132 print "title="+tAj.group(1)
133 print "num="+tAj.group(2)
135 ret['title']=tAj.group(1)
136 ret['num']=int(tAj.group(2))
137 ret['folder']=searchFolder(tAj.group(1),path)
140 print "title="+tB.group(1)
141 print "num="+tB.group(2)
142 print "subtitle="+tB.group(3)
144 ret['title']=tB.group(1)
145 ret['num']=int(tB.group(2))
146 ret['folder']=searchFolder(tB.group(1),path)
147 ret['subtitle']=tB.group(3)
148 else:#type C or type D
149 #fold=searchFolder(title, path)
155 ft1=searchFolder(tt,path)
160 #print ft1[0]+" : "+str(ft1[1])
166 #print "title="+rt[0][1:]+"/"
167 #print "subtitle = "+title.replace(rt[0][1:],"")[1:]
168 ret['title']=rt[0][1:]
171 ret['subtitle']=title.replace(rt[0][1:],"")[1:]
172 if ret['subtitle'].replace(" ","")=="":
177 def searchFolder(title,path):
181 folderpath=os.listdir(path)
184 for ft in folderpath:
185 fullpath=os.path.join(path, ft)
186 if os.path.isdir(fullpath):
187 lfpath.append(fullpath)
188 ftt=os.listdir(fullpath)
191 folderpath.append(os.path.join(fullpath, ft2))
193 lfpath.append(fullpath)
197 if os.path.isdir(dirp):
198 cmpp=os.path.dirname(dirp)
201 cmpp=os.path.basename(dirp)
202 appp=os.path.dirname(dirp)
203 p=n_gram.trigram(title.decode("utf-8"),cmpp.decode("utf-8"))
205 ngram.append((p,appp))
206 ngram=list(set(ngram))
210 #print title + ngram[0][1] + " : "+str(ngram[0][0])
212 return [ngram[0][1],ngram[0][0]]