3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
17 def detName(title,path):
18 tt=detNameType(title, path)
19 if tt['type']=="C"or tt['type']=="D":
20 tt['num']=detNum(tt['title'],tt['folder'])
21 def detSeriesNum(execpath):
22 files=os.listdir(execpath)
25 ftitle=os.path.splitext(file)
27 fname=zenhan.toHankaku(unicode(name))
28 st=detNameType(fname, execpath)['title']
31 ss[detNum(fname,execpath)]=ftitle
33 def detNum(title,movepath):
37 files=os.listdir(movepath)
41 recdblist.printutf8(file)
42 file=os.path.join(movepath,file)
43 if os.path.isfile(file):
44 name=os.path.splitext(os.path.split(file)[1])
46 name=zenhan.toHankaku(unicode(name))
47 p1=detNameType(name,movepath)
48 recdblist.printutf8(p1['title']+" "+str(p1['num']))
49 time1=time.localtime(os.path.getmtime(file))
50 time1=datetime.datetime.fromtimestamp(os.path.getmtime(file))
52 ff.append([p1['num'],p1['title'],time1])
53 if maxnum<p1['num']+1:
55 return detMultiDeltaDays(ff)
56 def detMultiDeltaDays(num_with_title_with_dates):
58 for ft in num_with_title_with_dates:
61 ff=num_with_title_with_dates
64 for i in range(0, maxnum, 1):
68 for i in range(maxnum):
69 for j in range(i+1,maxnum,1):
72 for gdd in detSingleDeltaDay(i, ft3[2], j, ft4[2]):
74 if fret.get(gdd[0])!=None:
76 fret[gdd[0]]=fret[gdd[0]]+gdd[1]
82 for i in range(maxnum):
90 def detSingleDeltaDay(num1,date1,num2,date2):
98 dp=dd+datetime.timedelta(hours=6)
100 dm=dd-datetime.timedelta(hours=6)
109 recdblist.printutf8(str(d)+":"+str(dn))
111 ret.append([dn/d,60])
112 ret.append([dp/d,40])
114 ret.append([dn/d,60])
115 ret.append([dm/d,40])
117 ret.append([dn/d,100])
119 def detNameType(title,path):
121 type A ---title#<number>
122 type B ---title#<number>subtitle
123 type C ---title subtitle
124 type D ---title(without number)
125 type Aj ---title第<number>話
126 path --search reflexively
128 recdblist.printutf8(title)
129 title=auto_move.getTitle(title)##titleから日時を除く
130 #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
131 rA=re.compile("(.+)#(\d*)\s*\Z")
133 rB=re.compile("(.+)#(\d*)\s*(\D*)")
135 rAj=re.compile("(.+)第(\d*)話\s*\Z")
137 ret={'title':"",'type':"",'num':0,'subtitle':"",'folder':""}
139 recdblist.printutf8("typeA")
140 recdblist.printutf8("title="+tA.group(1))
141 recdblist.printutf8("num="+tA.group(2))
143 ret['title']=tA.group(1)
144 ret['num']=int(tA.group(2))
145 ret['folder']=searchFolder(tA.group(1),path)
147 recdblist.printutf8("typeA")
148 recdblist.printutf8("title="+tAj.group(1))
149 recdblist.printutf8("num="+tAj.group(2))
151 ret['title']=tAj.group(1)
152 ret['num']=int(tAj.group(2))
153 ret['folder']=searchFolder(tAj.group(1),path)
155 recdblist.printutf8("typeB")
156 recdblist.printutf8("title="+tB.group(1))
157 recdblist.printutf8("num="+tB.group(2))
158 recdblist.printutf8("subtitle="+tB.group(3))
160 ret['title']=tB.group(1)
161 ret['num']=int(tB.group(2))
162 ret['folder']=searchFolder(tB.group(1),path)
163 ret['subtitle']=tB.group(3)
164 else:#type C or type D
165 #fold=searchFolder(title, path)
171 ft1=searchFolder(tt,path)
172 recdblist.printutf8(tt)
175 #recdblist.printutf8(rt)
176 #recdblist.printutf8(ft1[0]+" : "+str(ft1[1]))
181 #recdblist.printutf8(rt)
182 #recdblist.printutf8("title="+rt[0][1:]+"/")
183 #recdblist.printutf8("subtitle = "+title.replace(rt[0][1:],"")[1:])
184 ret['title']=rt[0][1:]
187 ret['subtitle']=title.replace(rt[0][1:],"")[1:]
188 if ret['subtitle'].replace(" ","")=="":
193 def searchFolder(title,path,threshold=500):
197 folderpath=os.listdir(path)
200 for ft in folderpath:
201 fullpath=os.path.join(path, ft)
202 if os.path.isdir(fullpath):
203 lfpath.append(fullpath)
204 ftt=os.listdir(fullpath)
207 folderpath.append(os.path.join(fullpath, ft2))
209 lfpath.append(fullpath)
213 if os.path.isdir(dirp):
214 cmpp=os.path.dirname(dirp)
217 cmpp=os.path.basename(dirp)
218 appp=os.path.dirname(dirp)
219 ntitle=auto_move.getTitle(title)
220 ncmpp=auto_move.getTitle(cmpp)
221 p=n_gram.trigram(ntitle,ncmpp)
223 ngram.append((p,appp))
224 ngram=list(set(ngram))
228 #recdblist.printutf8(title + ngram[0][1] + " : "+str(ngram[0][0]))
229 if ngram[0][0]>threshold: