OSDN Git Service

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