3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
15 def detName(title,path):
16 tt=detNameType(title, path)
17 if tt['type']=="C"or tt['type']=="D":
18 tt['num']=detNum(tt['title'],tt['folder'])
19 def detNum(title,movepath):
23 files=os.listdir(movepath)
27 recdblist.printutf8(file)
28 file=os.path.join(movepath,file)
29 if os.path.isfile(file):
30 name=os.path.splitext(os.path.split(file)[1])
32 name=zenhan.toHankaku(unicode(name))
33 p1=detNameType(name,movepath)
34 recdblist.printutf8(p1['title']+" "+str(p1['num']))
35 time1=time.localtime(os.path.getmtime(file))
36 time1=datetime.datetime.fromtimestamp(os.path.getmtime(file))
38 ff.append([p1['num'],p1['title'],time1])
39 if maxnum<p1['num']+1:
42 def detMultiDeltaDays(num_with_title_with_dates):
44 for ft in num_with_title_with_dates:
47 ff=num_with_title_with_dates
50 for i in range(0, maxnum, 1):
54 for i in range(maxnum):
55 for j in range(i+1,maxnum,1):
58 for gdd in detSingleDeltaDay(i, ft3[2], j, ft4[2]):
60 if fret.get(gdd[0])!=None:
62 fret[gdd[0]]=fret[gdd[0]]+gdd[1]
68 for i in range(maxnum):
76 def detSingleDeltaDay(num1,date1,num2,date2):
84 dp=dd+datetime.timedelta(hours=6)
86 dm=dd-datetime.timedelta(hours=6)
95 recdblist.printutf8(str(d)+":"+str(dn))
100 ret.append([dn/d,60])
101 ret.append([dm/d,40])
103 ret.append([dn/d,100])
105 def detNameType(title,path):
107 type A ---title#<number>
108 type B ---title#<number>subtitle
109 type C ---title subtitle
110 type D ---title(without number)
111 type Aj ---title第<number>話
112 path --search reflexively
114 recdblist.printutf8(title)
115 #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
116 rA=re.compile("(.+)#(\d*)\s*\Z")
118 rB=re.compile("(.+)#(\d*)\s*(\D*)")
120 rAj=re.compile("(.+)第(\d*)話\s*\Z")
122 ret={'title':"",'type':"",'num':0,'subtitle':"",'folder':""}
124 recdblist.printutf8("typeA")
125 recdblist.printutf8("title="+tA.group(1))
126 recdblist.printutf8("num="+tA.group(2))
128 ret['title']=tA.group(1)
129 ret['num']=int(tA.group(2))
130 ret['folder']=searchFolder(tA.group(1),path)
132 recdblist.printutf8("typeA")
133 recdblist.printutf8("title="+tAj.group(1))
134 recdblist.printutf8("num="+tAj.group(2))
136 ret['title']=tAj.group(1)
137 ret['num']=int(tAj.group(2))
138 ret['folder']=searchFolder(tAj.group(1),path)
140 recdblist.printutf8("typeB")
141 recdblist.printutf8("title="+tB.group(1))
142 recdblist.printutf8("num="+tB.group(2))
143 recdblist.printutf8("subtitle="+tB.group(3))
145 ret['title']=tB.group(1)
146 ret['num']=int(tB.group(2))
147 ret['folder']=searchFolder(tB.group(1),path)
148 ret['subtitle']=tB.group(3)
149 else:#type C or type D
150 #fold=searchFolder(title, path)
156 ft1=searchFolder(tt,path)
157 recdblist.printutf8(tt)
160 #recdblist.printutf8(rt)
161 #recdblist.printutf8(ft1[0]+" : "+str(ft1[1]))
166 #recdblist.printutf8(rt)
167 #recdblist.printutf8("title="+rt[0][1:]+"/")
168 #recdblist.printutf8("subtitle = "+title.replace(rt[0][1:],"")[1:])
169 ret['title']=rt[0][1:]
172 ret['subtitle']=title.replace(rt[0][1:],"")[1:]
173 if ret['subtitle'].replace(" ","")=="":
178 def searchFolder(title,path):
182 folderpath=os.listdir(path)
185 for ft in folderpath:
186 fullpath=os.path.join(path, ft)
187 if os.path.isdir(fullpath):
188 lfpath.append(fullpath)
189 ftt=os.listdir(fullpath)
192 folderpath.append(os.path.join(fullpath, ft2))
194 lfpath.append(fullpath)
198 if os.path.isdir(dirp):
199 cmpp=os.path.dirname(dirp)
202 cmpp=os.path.basename(dirp)
203 appp=os.path.dirname(dirp)
204 p=n_gram.trigram(title.decode("utf-8"),cmpp.decode("utf-8"))
206 ngram.append((p,appp))
207 ngram=list(set(ngram))
211 #recdblist.printutf8(title + ngram[0][1] + " : "+str(ngram[0][0]))
213 return [ngram[0][1],ngram[0][0]]