--- /dev/null
+#!/usr/bin/python
+# coding: UTF-8
+# Rec10 TS Recording Tools
+# Copyright (C) 2009-2010 Yukikaze
+
+import os
+import os.path
+import re
+import time
+
+import n_gram
+import recdblist
+def getTitle(title):
+ rT=re.compile("(.+)_(\d+)\Z")
+ tT=rT.match(title)
+ rT2=re.compile("(.+)_(.+)_(\d*)\Z")#_(aichi)_2010-02-06T01:59:00.mkv
+ tT2=rT2.match(title)
+ rT3=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+:\d+:\d+\Z")#_(aichi)_2010-02-06T01:59:00.mkv
+ tT3=rT3.match(title)
+ rT4=re.compile("(.+)_(.+)_\d+-\d+-\d+T\d+-\d+-\d+\Z")#_(aichi)_2010-02-06T01-59-00.mkv
+ tT4=rT4.match(title)
+ rT5=re.compile("(.+)_(.+)_(.+)\Z")#_(aichi)_2010-02-06T01-59-00.mkv
+ tT5=rT5.match(title)
+ ntitle=title
+ if tT :
+ ntitle=tT.group(1)
+ elif tT2:
+ ntitle=tT2.group(1)
+ elif tT3:
+ ntitle=tT3.group(1)
+ elif tT4:
+ ntitle=tT4.group(1)
+ elif tT5:
+ ntitle=tT5.group(1)
+ return ntitle
+def detNameType(title):
+ """
+ type A ---title#<number>
+ type B ---title#<number>subtitle
+ type C ---title subtitle
+ type D ---title(without number)
+ """
+ recdblist.printutf8(title)
+ #rA=re.compile(".+(?P<title>)#\d(?P<num>)\s[0,10]\z")
+ rA=re.compile("(.+)#(\d*)\s*\Z")
+ tA=rA.match(title)
+ rB=re.compile("(.+)#(\d*)\s*(\D*)")
+ tB=rB.match(title)
+ if tA:
+ recdblist.printutf8("typeA")
+ recdblist.printutf8("title="+tA.group(1))
+ recdblist.printutf8("num="+tA.group(2))
+ elif tB:
+ recdblist.printutf8("typeB")
+ recdblist.printutf8("title="+tB.group(1))
+ recdblist.printutf8("num="+tB.group(2))
+ recdblist.printutf8("subtitle="+tB.group(3))
+def search_file(temppath,recpath,ext):
+ """
+ 録画一時フォルダ内mkvファイルを検索
+ """
+ avilist = glob.glob(temppath + "/*"+ext)
+ ret=[]
+ for avif in avilist:
+ ##b25f is title.ts.b25 avi is title.avi
+ dir = os.path.split(avif)[0]
+ title = os.path.split(avif)[1]
+ title = title.replace(ext, "")
+ avipath = os.path.join(dir, title + ext)
+ dtime = time.time()-os.path.getmtime(avipath)
+ dtime = int(dtime)
+ if dtime > 300:
+ if veryfySize(avipath):
+ ret.append(title)
+ return ret
+def get_move_dest_path(title,temppath,recpath,ext):
+ dstpath=os.path.join(recpath,title+ext)
+ srcpath=os.path.join(temppath,title+ext)
+ if os.path.exists(dstpath):
+ gmtime=time.gmtime(os.path.getmtime(srcpath))
+ times=time.strftime("%y%m%d",gmtime)
+ title=title+"_"+times
+ return title
+def get_delpath(temppath,title):
+ delpath=[os.path.join(temppath,title+".ts")]
+ delpath.append(os.path.join(temppath,title+".avi"))
+ delpath.append(os.path.join(temppath,title+".120.avi"))
+ delpath.append(os.path.join(temppath,title+".timecode.txt"))
+ delpath.append(os.path.join(temppath,title+".aac"))
+ delpath.append(os.path.join(temppath,title+".ts.b25"))
+ delpath.append(os.path.join(temppath,title+".ts.tsmix"))
+ delpath.append(os.path.join(temppath,title+".ts.log"))
+ delpath.append(os.path.join(temppath,title+".sa.avi"))
+ delpath.append(os.path.join(temppath,title+".sa.avi.log"))
+ delpath.append(os.path.join(temppath,title+".log"))
+ return delpath
+def searchFolder(title,path,threshold=500):
+ """
+ titleにマッチするフォルダを探し出す。
+ """
+ folderpath=os.listdir(path)
+ lfpath=[]
+ ngram=[]
+ for ft in folderpath:
+ fullpath=os.path.join(path.encode('utf-8'), ft)
+ if os.path.isdir(fullpath):
+ lfpath.append(fullpath)
+ ftt=os.listdir(fullpath)
+ if len(ftt)>0:
+ for ft2 in ftt:
+ try:
+ folderpath.append(os.path.join(fullpath, ft2))
+ except Exception, inst:
+ #print type(inst)
+ #print inst
+ ""
+ else:
+ lfpath.append(fullpath)
+ for dirp in lfpath:
+ cmpp=""
+ appp=""
+ ntitle=title
+ if os.path.isdir(dirp):
+ cmpp=os.path.dirname(dirp)
+ appp=dirp
+ else:
+ cmpp=os.path.basename(dirp)
+ appp=os.path.dirname(dirp)
+ ntitle=getTitle(title)
+ #recdblist.printutf8(cmpp)
+ cmpp=getTitle(os.path.splitext(cmpp)[0])
+ #recdblist.printutf8(cmpp+"\n")
+ p=n_gram.trigram(ntitle,cmpp)
+ if p>0:
+ ngram.append((p,appp))
+ ngram=list(set(ngram))
+ ngram.sort()
+ ngram.reverse()
+ if len(ngram)>0:
+ #recdblist.printutf8(title + ngram[0][1] + " : "+str(ngram[0][0]))
+ if ngram[0][0]>threshold:
+ return ngram[0][1]
+ else:
+ return ""
+ else:
+ return ""
+def execMove(title,temppath,recpath,ext,autodel):
+ srcpath=os.path.join(temppath,title+ext)
+ #desttitle=destName(title, temppath, recpath)
+
+ sf=searchFolder(title, recpath)
+ if sf!="":
+ destpath=os.path.join(sf,destNameMKV(title, temppath, sf)+ext)
+ recdblist.printutf8("moving now..")
+ recdblist.printutf8(srcpath+" : "+destpath)
+ print srcpath
+ shutil.move(srcpath, destpath)
+ #shutil.copy(srcpath, destpath)
+ if autodel==1:
+ delpath=get_delpath(temppath, title)
+ for dp in delpath:
+ try:
+ os.remove(dp)
+ ""
+ except:
+ ""
\ No newline at end of file
+import auto_move
#!/usr/bin/python
# coding: UTF-8
# Rec10 TS Recording Tools
recdblist.printutf8("subtitle="+tB.group(3))
if __name__ == "__main__":
usage="usage: %prog read -h"
- version="%prog 0.9.3"
+ version="%prog 0.9.4"
parser=optparse.OptionParser(usage=usage,version=version)
parser.add_option("-s","--search",action="store",type="string",dest="ltitle",default="",metavar="TITLE",help="test to search where the title should be contained(test for -e)")
parser.add_option("-A","--Auto",action="store_true",dest="auto",default=False,help="auto classifying mode(not a test)")
parser.add_option("-e","--exec",action="store",type="string",dest="etitle",default="",metavar="TITLE",help="exec move(not a test)")
- parser.add_option("-l","--list",action="store_true",dest="list",default=False,help="File listing mode(test for -a)")
+ parser.add_option("-l","--list",action="store_true",dest="list",default=False,help="File listing mode(test for -A)")
+ parser.add_option("-t","--tssearch",action="store_true",dest="tssearch",default=False,help="Ts move auto search")
+ parser.add_option("-T","--Tsmove",action="store_true",dest="tsmove",default=False,help="Ts auto move.")
(opts,args)=parser.parse_args(sys.argv)
if opts.ltitle!="":
- #print opts.ltitle
ltitle=unicode(opts.ltitle,'utf-8')
sf=searchFolder(ltitle, recordedpath)
- print "###MKV List###"
- recdblist.printutf8(os.path.join(sf, destNameMKV(ltitle,recpath,sf)+".mkv"))
- print "###MP4 List###"
- recdblist.printutf8(os.path.join(sf, destNameMP4(ltitle,recpath,sf)+".mp4"))
- #print os.path.join(sf, destNameMP4(ltitle,recpath,sf)+".mp4")
+ print "###MKV###"
+ recdblist.printutf8(os.path.join(sf, auto_move.get_move_dest_path(ltitle,recpath,sf,".mkv")+".mkv"))
+ print "###MP4###"
+ recdblist.printutf8(os.path.join(sf, auto_move.get_move_dest_path(ltitle,recpath,sf,".mp4")+".mp4"))
elif opts.auto:
- sa=search_mkv(recpath, recordedpath)
+ sa=auto_move.search_file(recpath, recordedpath, ".mkv")
for t in sa:
- recdblist.printutf8(u"自動推測実行中")
+ recdblist.printutf8(u"自動推測実行中-MKV")
sf=searchFolder(t,recordedpath)
if sf!="":
recdblist.printutf8(u"移動先")
- recdblist.printutf8(t+" : "+os.path.join(sf, destNameMKV(t, recpath,sf)+".mkv"))
+ recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mkv")+".mkv"))
recdblist.printutf8(u"実行中")
- execMove_MKV(t, recpath, recordedpath)
+ auto_move.execMove(t, recpath, recordedpath,".mkv",1)
else:
recdblist.printutf8(t+" can't find matching folder")
- sa=search_mp4(recpath, recordedpath)
+ sa=auto_move.search_file(recpath, recordedpath, ".mp4")
for t in sa:
- recdblist.printutf8(u"自動推測実行中")
+ recdblist.printutf8(u"自動推測実行中-MP4")
sf=searchFolder(t,recordedpath)
if sf!="":
recdblist.printutf8(u"移動先")
- recdblist.printutf8(t+" : "+os.path.join(sf, destNameMP4(t, recpath,sf)+".mp4"))
+ recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mp4")+".mp4"))
recdblist.printutf8(u"実行中")
- execMove_MP4(t, recpath, recordedpath)
+ auto_move.execMove(t, recpath, recordedpath,".mp4",1)
else:
- recdblist.printutf8(t+" can't find matching folder.")
+ recdblist.printutf8(t+" can't find matching folder")
elif opts.list:
- sa=search_mkv(recpath, recordedpath)
+ sa=auto_move.search_file(recpath, recordedpath,".mkv")
for t in sa:
sf=searchFolder(t,recordedpath)
if sf!="":
- recdblist.printutf8(t+u" : "+os.path.join(sf, destNameMKV(t, recpath,sf)+".mkv"))
- sa=search_mp4(recpath, recordedpath)
+ recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mkv")+".mkv"))
+ sa=auto_move.search_file(recpath, recordedpath,".mp4")
for t in sa:
sf=searchFolder(t,recordedpath)
if sf!="":
- recdblist.printutf8(t+u" : "+os.path.join(sf, destNameMP4(t, recpath,sf)+".mp4"))
+ recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mp4")+".mp4"))
elif opts.etitle!="":
+ if os.path.exists(os.path.join(recpath, etitle+".mkv")):
+ auto_move.execMove(etitle,recpath, recordedpath,".mkv",1)
+ elif os.path.exists(os.path.join(recpath, etitle+".mp4")):
+ auto_move.execMove(etitle,recpath, recordedpath,".mp4",1)
+ srcpath=os.path.join(temppath,title+".mkv")
etitle=unicode(opts.etitle,'utf-8')
try:
execMove_MKV(etitle,recpath, recordedpath)
except:
- execMove_MP4(etitle,recpath, recordedpath)
\ No newline at end of file
+ execMove_MP4(etitle,recpath, recordedpath)
+ elif opts.tssearch:
+ tsmovepath=""
+ try:
+ tsmovepath=unicode(configreader.getpath("ts_movepath"),'utf-8',700)
+ except:
+ ""
+ if tsmovepath!="":
+ sa=auto_move.search_file(recpath, recordedpath,".ts")
+ for t in sa:
+ sf=searchFolder(t,recordedpath)
+ if sf!="":
+ recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".ts")+".ts"))
+ sa=auto_move.search_file(recpath, recordedpath,".ts")
+ else:
+ recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。")
+ elif opts.tsmove:
+ tsmovepath=""
+ try:
+ tsmovepath=unicode(configreader.getpath("ts_movepath"),'utf-8',700)
+ except:
+ ""
+ if tsmovepath!="":
+ sa=auto_move.search_file(recpath, recordedpath,".ts")
+ for t in sa:
+ sf=searchFolder(t,recordedpath)
+ if sf!="":
+ recdblist.printutf8(u"移動先")
+ recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".ts")+".ts"))
+ recdblist.printutf8(u"実行中")
+ auto_move.execMove(t, recpath, recordedpath,".ts",0)
+ sa=auto_move.search_file(recpath, recordedpath,".ts")
+ else:
+ recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。")
\ No newline at end of file