OSDN Git Service

test auto guess program_number function.
[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     #parser.add_option("-f","--filenumlist",action="store_true",dest="filenumlist",default=False,help="Guess Program Number.")
29
30     (opts,args)=parser.parse_args(sys.argv)
31     if opts.ltitle!="":##-sの場合
32         ltitle=unicode(opts.ltitle,'utf-8')
33         sf=guess.searchFolder(ltitle, recordedpath)
34         print "###MKV###"
35         recdblist.printutf8(os.path.join(sf, auto_move.get_move_dest_path(ltitle,recpath,sf,".mkv")+".mkv"))
36         print "\n"
37         print "###MP4###"
38         recdblist.printutf8(os.path.join(sf, auto_move.get_move_dest_path(ltitle,recpath,sf,".mp4")+".mp4"))
39         print "\n"
40     elif opts.auto:##-A の場合
41         sa=auto_move.search_file(recpath, recordedpath, ".mkv")
42         for t in sa:
43             recdblist.printutf8(u"自動推測実行中-MKV")
44             sf=guess.searchFolder(t,recordedpath)
45             if sf!="":
46                 recdblist.printutf8(u"移動先")
47                 recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mkv")+".mkv"))
48                 recdblist.printutf8(u"実行中")
49                 auto_move.execMove(t, recpath, recordedpath,".mkv",1)
50             else:
51                 recdblist.printutf8(t+" can't find matching folder")
52         sa=auto_move.search_file(recpath, recordedpath, ".mp4")
53         for t in sa:
54             recdblist.printutf8(u"自動推測実行中-MP4")
55             sf=guess.searchFolder(t,recordedpath)
56             if sf!="":
57                 recdblist.printutf8(u"移動先")
58                 recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mp4")+".mp4"))
59                 recdblist.printutf8(u"実行中")
60                 auto_move.execMove(t, recpath, recordedpath,".mp4",1)
61             else:
62                 recdblist.printutf8(t+" can't find matching folder")
63     elif opts.list:##-lの場合
64         sa=auto_move.search_file(recpath, recordedpath,".mkv")
65         for t in sa:
66             sf=guess.searchFolder(t,recordedpath)
67             if sf!="":
68                 recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mkv")+".mkv"))
69         sa=auto_move.search_file(recpath, recordedpath,".mp4")
70         for t in sa:
71             sf=guess.searchFolder(t,recordedpath)
72             if sf!="":
73                 recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".mp4")+".mp4"))
74     elif opts.etitle!="":
75         if os.path.exists(os.path.join(recpath, etitle+".mkv")):
76             auto_move.execMove(etitle,recpath, recordedpath,".mkv",1)
77         elif os.path.exists(os.path.join(recpath, etitle+".mp4")):
78             auto_move.execMove(etitle,recpath, recordedpath,".mp4",1)
79     elif opts.tssearch:## -tの場合
80         tsmovepath=""
81         try:
82             tsmovepath=unicode(configreader.getpath("ts_movepath"),'utf-8')
83         except:
84             ""
85         if tsmovepath!="":
86             sa=auto_move.search_file(recpath, tsmovepath,".ts")
87             for t in sa:
88                 sf=guess.searchFolder(t,tsmovepath,700)
89                 if sf!="":
90                     recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".ts")+".ts"))
91                     print "\n"
92             sa=auto_move.search_file(recpath, tsmovepath,".ts")
93         else:
94             recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。")
95     elif opts.tsmove:##-Tの場合
96         tsmovepath=""
97         try:
98             tsmovepath=unicode(configreader.getpath("ts_movepath"),'utf-8')
99         except:
100             ""
101         if tsmovepath!="":
102             sa=auto_move.search_file(recpath, tsmovepath,".ts")
103             for t in sa:
104                 sf=guess.searchFolder(t,tsmovepath,700)
105                 if sf!="":
106                     recdblist.printutf8(u"移動先")
107                     recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.get_move_dest_path(t, recpath,sf,".ts")+".ts"))
108                     recdblist.printutf8(u"実行中")
109                     auto_move.execMove(t, recpath, tsmovepath,".ts",0)
110             sa=auto_move.search_file(recpath, tsmovepath,".ts")
111         else:
112             recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。")