3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2011 Yukikaze
17 def detSeriesNum(execpath):
18 files=os.listdir(execpath)
21 ftitle=os.path.splitext(file)
23 fname=zenhan.toHankaku(unicode(fname,"utf-8"))
24 nt=detNameType(fname, execpath)
26 if not ss.has_key(st):
28 ss[st][nt['num']]=ftitle
31 def detDeltaNum(title,movepath):
35 files=os.listdir(movepath)
39 recdblist.printutf8(unicode(file,'utf-8'),verbose_level=800)
40 file=os.path.join(movepath,file)
41 if os.path.isfile(file):
42 name=os.path.splitext(os.path.split(file)[1])
44 name=zenhan.toHankaku(unicode(name,'utf-8'))
45 p1=detNameType(name,movepath)
46 #recdblist.printutf8(p1['title']+" "+str(p1['num']))
47 time1=time.localtime(os.path.getmtime(file))
48 time1=datetime.datetime.fromtimestamp(os.path.getmtime(file))
50 ff.append([p1['num'],p1['title'],time1])
51 if maxnum<p1['num']+1:
53 return detMultiDeltaDays(ff)
54 def detMultiDeltaDays(num_with_title_with_dates):
56 for ft in num_with_title_with_dates:
59 ff=num_with_title_with_dates
62 for i in range(0, maxnum, 1):
66 for i in range(maxnum):
67 for j in range(i+1,maxnum,1):
70 for gdd in detSingleDeltaDay(i, ft3[2], j, ft4[2]):
72 if fret.get(gdd[0])!=None:
74 fret[gdd[0]]=fret[gdd[0]]+gdd[1]
80 for i in range(maxnum):
88 def detSingleDeltaDay(num1,date1,num2,date2):
96 dp=dd+datetime.timedelta(hours=6)
98 dm=dd-datetime.timedelta(hours=6)
107 #recdblist.printutf8(str(d)+":"+str(dn))
109 ret.append([dn/d,60])
110 ret.append([dp/d,40])
112 ret.append([dn/d,60])
113 ret.append([dm/d,40])
115 ret.append([dn/d,100])
117 def detNameType(title,path):
119 type A ---title#<number>
120 type B ---title#<number>subtitle
121 type C ---title subtitle
122 type D ---title(without number)
123 type Aj ---title第<number>話
124 path --search reflexively
127 if re.search(u"[新]",title) or re.search(u" 新",title):
128 title=title.replace(u"[新]","")
129 title=title.replace(u" 新","")
131 recdblist.printutf8(title,verbose_level=800)
132 title=auto_move.getTitle(title)##titleから日時を除く
133 title=title.replace(u"無料≫","")
134 #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
135 rA=re.compile("(.+)#(\d*)\s*\Z")
137 rB=re.compile("(.+)#(\d*)\s*(\D*)")
139 rAj=re.compile("(.+)第(\d*)話\s*\Z")
141 ret={'title':"",'type':"",'num':0,'subtitle':"",'folder':""}
143 #recdblist.printutf8("typeA")
144 #recdblist.printutf8("title="+tA.group(1))
145 #recdblist.printutf8("num="+tA.group(2))
147 ret['title']=tA.group(1).replace(" ","")
148 ret['num']=int(tA.group(2))
149 ret['folder']=searchFolder(tA.group(1),unicode(path,'utf-8'))
151 #recdblist.printutf8("typeA")
152 #recdblist.printutf8("title="+tAj.group(1))
153 #recdblist.printutf8("num="+tAj.group(2))
155 ret['title']=tAj.group(1).replace(" ","")
156 ret['num']=int(tAj.group(2))
157 ret['folder']=searchFolder(tAj.group(1),unicode(path,'utf-8'))
159 #recdblist.printutf8("typeB")
160 #recdblist.printutf8("title="+tB.group(1))
161 #recdblist.printutf8("num="+tB.group(2))
162 #recdblist.printutf8("subtitle="+tB.group(3))
164 ret['title']=tB.group(1).replace(" ","")
165 ret['num']=int(tB.group(2))
166 ret['folder']=searchFolder(tB.group(1),unicode(path,'utf-8'))
167 ret['subtitle']=tB.group(3)
168 else:#type C or type D
169 #fold=searchFolder(title, path)
175 ft1=searchFolder(tt,unicode(path,'utf-8'))
176 #recdblist.printutf8(tt)
179 #recdblist.printutf8(rt)
180 #recdblist.printutf8(ft1[0]+" : "+str(ft1[1]))
185 #recdblist.printutf8(rt)
186 #recdblist.printutf8("title="+rt[0][1:]+"/")
187 #recdblist.printutf8("subtitle = "+title.replace(rt[0][1:],"")[1:])
188 ret['title']=rt[0][1:].replace(" ","")
191 ret['subtitle']=title.replace(rt[0][1:],"")[1:]
192 if ret['subtitle'].replace(" ","")=="":
199 def searchFolder(title,path,threshold=500):
203 folderpath=os.listdir(path)
206 for ft in folderpath:
207 fullpath=os.path.join(path, ft)
208 if os.path.isdir(fullpath):
209 lfpath.append(fullpath)
210 ftt=os.listdir(fullpath)
213 folderpath.append(os.path.join(fullpath, ft2))
215 lfpath.append(fullpath)
219 if os.path.isdir(dirp):
220 cmpp=os.path.dirname(dirp)
223 cmpp=os.path.basename(dirp)
224 appp=os.path.dirname(dirp)
225 ntitle=auto_move.getTitle(title)
226 ncmpp=auto_move.getTitle(cmpp)
227 p=n_gram.trigram(ntitle,ncmpp)
229 ngram.append((p,appp))
230 ngram=list(set(ngram))
234 #recdblist.printutf8(title + ngram[0][1] + " : "+str(ngram[0][0]))
235 if ngram[0][0]>threshold: