3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
16 def detName(title,path):
17 tt=detNameType(title, path)
18 if tt['type']=="C"or tt['type']=="D":
19 tt['num']=detNum(tt['title'],tt['folder'])
20 def detNum(title,movepath):
24 files=os.listdir(movepath)
28 recdblist.printutf8(file)
29 file=os.path.join(movepath,file)
30 if os.path.isfile(file):
31 name=os.path.splitext(os.path.split(file)[1])
33 name=zenhan.toHankaku(unicode(name))
34 p1=detNameType(name,movepath)
35 recdblist.printutf8(p1['title']+" "+str(p1['num']))
36 time1=time.localtime(os.path.getmtime(file))
37 time1=datetime.datetime.fromtimestamp(os.path.getmtime(file))
39 ff.append([p1['num'],p1['title'],time1])
40 if maxnum<p1['num']+1:
43 def detMultiDeltaDays(num_with_title_with_dates):
45 for ft in num_with_title_with_dates:
48 ff=num_with_title_with_dates
51 for i in range(0, maxnum, 1):
55 for i in range(maxnum):
56 for j in range(i+1,maxnum,1):
59 for gdd in detSingleDeltaDay(i, ft3[2], j, ft4[2]):
61 if fret.get(gdd[0])!=None:
63 fret[gdd[0]]=fret[gdd[0]]+gdd[1]
69 for i in range(maxnum):
77 def detSingleDeltaDay(num1,date1,num2,date2):
85 dp=dd+datetime.timedelta(hours=6)
87 dm=dd-datetime.timedelta(hours=6)
96 recdblist.printutf8(str(d)+":"+str(dn))
101 ret.append([dn/d,60])
102 ret.append([dm/d,40])
104 ret.append([dn/d,100])
106 def detNameType(title,path):
108 type A ---title#<number>
109 type B ---title#<number>subtitle
110 type C ---title subtitle
111 type D ---title(without number)
112 type Aj ---title第<number>話
113 path --search reflexively
115 recdblist.printutf8(title)
116 #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
117 rA=re.compile("(.+)#(\d*)\s*\Z")
119 rB=re.compile("(.+)#(\d*)\s*(\D*)")
121 rAj=re.compile("(.+)第(\d*)話\s*\Z")
123 ret={'title':"",'type':"",'num':0,'subtitle':"",'folder':""}
125 recdblist.printutf8("typeA")
126 recdblist.printutf8("title="+tA.group(1))
127 recdblist.printutf8("num="+tA.group(2))
129 ret['title']=tA.group(1)
130 ret['num']=int(tA.group(2))
131 ret['folder']=searchFolder(tA.group(1),path)
133 recdblist.printutf8("typeA")
134 recdblist.printutf8("title="+tAj.group(1))
135 recdblist.printutf8("num="+tAj.group(2))
137 ret['title']=tAj.group(1)
138 ret['num']=int(tAj.group(2))
139 ret['folder']=searchFolder(tAj.group(1),path)
141 recdblist.printutf8("typeB")
142 recdblist.printutf8("title="+tB.group(1))
143 recdblist.printutf8("num="+tB.group(2))
144 recdblist.printutf8("subtitle="+tB.group(3))
146 ret['title']=tB.group(1)
147 ret['num']=int(tB.group(2))
148 ret['folder']=searchFolder(tB.group(1),path)
149 ret['subtitle']=tB.group(3)
150 else:#type C or type D
151 #fold=searchFolder(title, path)
157 ft1=searchFolder(tt,path)
158 recdblist.printutf8(tt)
161 #recdblist.printutf8(rt)
162 #recdblist.printutf8(ft1[0]+" : "+str(ft1[1]))
167 #recdblist.printutf8(rt)
168 #recdblist.printutf8("title="+rt[0][1:]+"/")
169 #recdblist.printutf8("subtitle = "+title.replace(rt[0][1:],"")[1:])
170 ret['title']=rt[0][1:]
173 ret['subtitle']=title.replace(rt[0][1:],"")[1:]
174 if ret['subtitle'].replace(" ","")=="":
179 def searchFolder(title,path,threshold=500):
183 folderpath=os.listdir(path)
186 for ft in folderpath:
187 fullpath=os.path.join(path, ft)
188 if os.path.isdir(fullpath):
189 lfpath.append(fullpath)
190 ftt=os.listdir(fullpath)
193 folderpath.append(os.path.join(fullpath, ft2))
195 lfpath.append(fullpath)
199 if os.path.isdir(dirp):
200 cmpp=os.path.dirname(dirp)
203 cmpp=os.path.basename(dirp)
204 appp=os.path.dirname(dirp)
205 ntitle=auto_move.getTitle(title)
206 ncmpp=auto_move.getTitle(cmpp)
207 p=n_gram.trigram(ntitle,ncmpp)
209 ngram.append((p,appp))
210 ngram=list(set(ngram))
214 #recdblist.printutf8(title + ngram[0][1] + " : "+str(ngram[0][0]))
215 if ngram[0][0]>threshold: