3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
13 def detName(title,path):
14 tt=detNameType(title, path)
15 if tt['type']=="C"or tt['type']=="D":
16 tt['num']=detNum(tt['title'],tt['folder'])
17 def detNum(title,movepath):
21 files=os.listdir(movepath)
25 if os.path.isfile(file):
26 name=os.path.splitext(os.path.split(file)[1])
27 p1=detNameType(name,movepath)
28 print p1['title']+" "+str(p1['num'])
29 time1=time.localtime(os.path.getmtime(file))
30 ff.append([p1['num'],p1['title'],time1])
31 if maxnum<p1['num']+1:
34 for i in range(0, maxnum, 1):
38 for i in range(maxnum):
39 for j in range(i+1,maxnum,1):
41 def guessDeltaDay(num1,date1,num2,date2):
46 dd=dd+datetime.timedelta(hours=6)
49 def detNameType(title,path):
51 type A ---title#<number>
52 type B ---title#<number>subtitle
53 type C ---title subtitle
54 type D ---title(without number)
55 path --search reflexively
58 #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
59 rA=re.compile("(.+)#(\d*)\s*\Z")
61 rB=re.compile("(.+)#(\d*)\s*(\D*)")
63 ret={'title':"",'type':"",'num':0,'subtitle':"",'folder':""}
66 print "title="+tA.group(1)
67 print "num="+tA.group(2)
69 ret['title']=tA.group(1)
70 ret['num']=int(tA.group(2))
71 ret['folder']=searchFolder(tA.group(1),path)
74 print "title="+tB.group(1)
75 print "num="+tB.group(2)
76 print "subtitle="+tB.group(3)
78 ret['title']=tB.group(1)
79 ret['num']=int(tB.group(2))
80 ret['folder']=searchFolder(tB.group(1),path)
81 ret['subtitle']=tB.group(3)
82 else:#type C or type D
83 #fold=searchFolder(title, path)
89 ft1=searchFolder(tt,path)
94 #print ft1[0]+" : "+str(ft1[1])
100 #print "title="+rt[0][1:]+"/"
101 #print "subtitle = "+title.replace(rt[0][1:],"")[1:]
102 ret['title']=rt[0][1:]
105 ret['subtitle']=title.replace(rt[0][1:],"")[1:]
106 if ret['subtitle'].replace(" ","")=="":
111 def searchFolder(title,path):
115 folderpath=os.listdir(path)
118 for ft in folderpath:
119 fullpath=os.path.join(path, ft)
120 if os.path.isdir(fullpath):
121 lfpath.append(fullpath)
122 ftt=os.listdir(fullpath)
125 folderpath.append(os.path.join(fullpath, ft2))
127 lfpath.append(fullpath)
131 if os.path.isdir(dirp):
132 cmpp=os.path.dirname(dirp)
135 cmpp=os.path.basename(dirp)
136 appp=os.path.dirname(dirp)
137 p=n_gram.trigram(title.decode("utf-8"),cmpp.decode("utf-8"))
139 ngram.append((p,appp))
140 ngram=list(set(ngram))
144 #print title + ngram[0][1] + " : "+str(ngram[0][0])
146 return [ngram[0][1],ngram[0][0]]