OSDN Git Service

implement new classify system.
[rec10/rec10-git.git] / rec10 / trunk / src / classify.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
5
6 import os
7 import os.path
8 import optparse
9 import sys
10
11 import configreader
12 import recdblist
13 import auto_move
14 import guess
15 recordedpath=unicode(configreader.getpath("recorded"),'utf-8')
16 recpath=unicode(configreader.getpath("recpath"),'utf-8')
17
18 if __name__ == "__main__":
19     usage="usage: %prog read -h"
20     version="%prog 0.9.4"
21     parser=optparse.OptionParser(usage=usage,version=version)
22     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)")
23     parser.add_option("-A","--Auto",action="store_true",dest="auto",default=False,help="auto classifying mode(not a test)")
24     parser.add_option("-e","--exec",action="store",type="string",dest="etitle",default="",metavar="TITLE",help="exec move(not a test)")
25     parser.add_option("-l","--list",action="store_true",dest="list",default=False,help="File listing mode(test for -A)")
26     parser.add_option("-t","--tssearch",action="store_true",dest="tssearch",default=False,help="Ts move auto search")
27     parser.add_option("-T","--Tsmove",action="store_true",dest="tsmove",default=False,help="Ts auto move.")
28     (opts,args)=parser.parse_args(sys.argv)
29     if opts.ltitle!="":##-sの場合
30         ltitle=unicode(opts.ltitle,'utf-8')
31         sf=guess.searchFolder(ltitle, recordedpath)
32         print "###MKV###"
33         recdblist.printutf8(os.path.join(sf, auto_move.get_move_dest_path(ltitle,recpath,sf,".mkv")+".mkv"))
34         print "\n"
35         print "###MP4###"
36         recdblist.printutf8(os.path.join(sf, auto_move.get_move_dest_path(ltitle,recpath,sf,".mp4")+".mp4"))
37         print "\n"
38     elif opts.auto:##-A の場合
39         sa=auto_move.search_file(recpath, recordedpath, ".mkv")
40         for t in sa:
41             recdblist.printutf8(u"自動推測実行中-MKV")
42             sf=guess.searchFolder(t,recordedpath)
43             if sf!="":
44                 recdblist.printutf8(u"移動先")
45                 recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mkv")+".mkv"))
46                 recdblist.printutf8(u"実行中")
47                 auto_move.execMove(t, recpath, recordedpath,".mkv",1)
48             else:
49                 recdblist.printutf8(t+" can't find matching folder")
50         sa=auto_move.search_file(recpath, recordedpath, ".mp4")
51         for t in sa:
52             recdblist.printutf8(u"自動推測実行中-MP4")
53             sf=guess.searchFolder(t,recordedpath)
54             if sf!="":
55                 recdblist.printutf8(u"移動先")
56                 recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mp4")+".mp4"))
57                 recdblist.printutf8(u"実行中")
58                 auto_move.execMove(t, recpath, recordedpath,".mp4",1)
59             else:
60                 recdblist.printutf8(t+" can't find matching folder")
61     elif opts.list:##-lの場合
62         sa=auto_move.search_file(recpath, recordedpath,".mkv")
63         for t in sa:
64             sf=guess.searchFolder(t,recordedpath)
65             if sf!="":
66                 recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mkv")+".mkv"))
67         sa=auto_move.search_file(recpath, recordedpath,".mp4")
68         for t in sa:
69             sf=guess.searchFolder(t,recordedpath)
70             if sf!="":
71                 recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mp4")+".mp4"))
72     elif opts.etitle!="":
73         if os.path.exists(os.path.join(recpath, etitle+".mkv")):
74             auto_move.execMove(etitle,recpath, recordedpath,".mkv",1)
75         elif os.path.exists(os.path.join(recpath, etitle+".mp4")):
76             auto_move.execMove(etitle,recpath, recordedpath,".mp4",1)
77     elif opts.tssearch:## -tの場合
78         tsmovepath=""
79         try:
80             tsmovepath=unicode(configreader.getpath("ts_movepath"),'utf-8')
81         except:
82             ""
83         if tsmovepath!="":
84             sa=auto_move.search_file(recpath, tsmovepath,".ts")
85             for t in sa:
86                 sf=guess.searchFolder(t,tsmovepath,700)
87                 if sf!="":
88                     recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".ts")+".ts"))
89                     print "\n"
90             sa=auto_move.search_file(recpath, tsmovepath,".ts")
91         else:
92             recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。")
93     elif opts.tsmove:##-Tの場合
94         tsmovepath=""
95         try:
96             tsmovepath=unicode(configreader.getpath("ts_movepath"),'utf-8')
97         except:
98             ""
99         if tsmovepath!="":
100             sa=auto_move.search_file(recpath, tsmovepath,".ts")
101             for t in sa:
102                 sf=guess.searchFolder(t,tsmovepath,700)
103                 if sf!="":
104                     recdblist.printutf8(u"移動先")
105                     recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".ts")+".ts"))
106                     recdblist.printutf8(u"実行中")
107                     auto_move.execMove(t, recpath, tsmovepath,".ts",0)
108             sa=auto_move.search_file(recpath, tsmovepath,".ts")
109         else:
110             recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。")