OSDN Git Service

add dist
[rec10/rec10-git.git] / dist / trunk / rec10 / classify.py
1 #!/usr/bin/python\r
2 # coding: UTF-8\r
3 # Rec10 TS Recording Tools\r
4 # Copyright (C) 2009-2011 Yukikaze\r
5 \r
6 import os\r
7 import os.path\r
8 import optparse\r
9 import sys\r
10 \r
11 import configreader\r
12 import recdblist\r
13 import auto_move\r
14 import guess\r
15 recordedpath=unicode(configreader.getConfPath("recorded"),'utf-8')\r
16 recpath=unicode(configreader.getConfPath("recpath"),'utf-8')\r
17 \r
18 if __name__ == "__main__":\r
19     usage="usage: %prog read -h"\r
20     version="%prog 0.9.4"\r
21     parser=optparse.OptionParser(usage=usage,version=version)\r
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)")\r
23     parser.add_option("-A","--Auto",action="store_true",dest="auto",default=False,help="auto classifying mode(not a test)")\r
24     parser.add_option("-D","--Delete",action="store_true",dest="delete",default=False,help="auto delete tempfile mode(not a test)")\r
25     parser.add_option("-e","--exec",action="store",type="string",dest="etitle",default="",metavar="TITLE",help="exec move(not a test)")\r
26     parser.add_option("-l","--list",action="store_true",dest="list",default=False,help="File listing mode(test for -A)")\r
27     parser.add_option("-t","--tssearch",action="store_true",dest="tssearch",default=False,help="Ts move auto search")\r
28     parser.add_option("-T","--Tsmove",action="store_true",dest="tsmove",default=False,help="Ts auto move.")\r
29     parser.add_option("-S","--SeriesNum",action="store",type="string",dest="seriespath",default="",metavar="TITLE",help="Search Series Number in the path.")\r
30     #parser.add_option("-f","--filenumlist",action="store_true",dest="filenumlist",default=False,help="Guess Program Number.")\r
31 \r
32     (opts,args)=parser.parse_args(sys.argv)\r
33     if opts.ltitle!="":##-sの場合\r
34         ltitle=unicode(opts.ltitle,'utf-8')\r
35         sf=guess.searchFolder(ltitle, recordedpath)\r
36         print "###MKV###"\r
37         recdblist.printutf8(os.path.join(sf, auto_move.getMoveDestpath(ltitle,recpath,sf,".mkv")+".mkv"),verbose_level=100)\r
38         print "\n"\r
39         print "###MP4###"\r
40         recdblist.printutf8(os.path.join(sf, auto_move.getMoveDestpath(ltitle,recpath,sf,".mp4")+".mp4"),verbose_level=100)\r
41         print "\n"\r
42     elif opts.auto:##-A の場合\r
43         sa=auto_move.searchFile(recpath, recordedpath, ".mkv")\r
44         for t in sa:\r
45             recdblist.printutf8(u"自動推測実行中-MKV",verbose_level=100)\r
46             sf=guess.searchFolder(t,recordedpath)\r
47             if sf!="":\r
48                 recdblist.printutf8(u"移動先",verbose_level=100)\r
49                 recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mkv")+".mkv"),verbose_level=100)\r
50                 recdblist.printutf8(u"実行中",verbose_level=100)\r
51                 auto_move.execMove(t, recpath, recordedpath,".mkv",1)\r
52             else:\r
53                 recdblist.printutf8(t+" can't find matching folder",verbose_level=100)\r
54         sa=auto_move.searchFile(recpath, recordedpath, ".mp4")\r
55         for t in sa:\r
56             recdblist.printutf8(u"自動推測実行中-MP4",verbose_level=100)\r
57             sf=guess.searchFolder(t,recordedpath)\r
58             if sf!="":\r
59                 recdblist.printutf8(u"移動先",verbose_level=100)\r
60                 recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mp4")+".mp4"),verbose_level=100)\r
61                 recdblist.printutf8(u"実行中",verbose_level=100)\r
62                 auto_move.execMove(t, recpath, recordedpath,".mp4",1)\r
63             else:\r
64                 recdblist.printutf8(t+" can't find matching folder",verbose_level=100)\r
65     elif opts.delete:##-Dの場合\r
66         sa=auto_move.searchFile(recpath, recordedpath,".mkv")\r
67         for t in sa:\r
68             auto_move.execDelete(t, recpath)\r
69         sa=auto_move.searchFile(recpath, recordedpath,".mp4")\r
70         for t in sa:\r
71             auto_move.execDelete(t, recpath)\r
72     elif opts.list:##-lの場合\r
73         sa=auto_move.searchFile(recpath, recordedpath,".mkv")\r
74         for t in sa:\r
75             sf=guess.searchFolder(t,recordedpath)\r
76             if sf!="":\r
77                 recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mkv")+".mkv"),verbose_level=100)\r
78         sa=auto_move.searchFile(recpath, recordedpath,".mp4")\r
79         for t in sa:\r
80             sf=guess.searchFolder(t,recordedpath)\r
81             if sf!="":\r
82                 recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".mp4")+".mp4"),verbose_level=100)\r
83     elif opts.etitle!="":\r
84         if os.path.exists(os.path.join(recpath, etitle+".mkv")):\r
85             auto_move.execMove(etitle,recpath, recordedpath,".mkv",1)\r
86         elif os.path.exists(os.path.join(recpath, etitle+".mp4")):\r
87             auto_move.execMove(etitle,recpath, recordedpath,".mp4",1)\r
88     elif opts.tssearch:## -tの場合\r
89         tsmovepath=""\r
90         try:\r
91             tsmovepath=unicode(configreader.getConfPath("ts_movepath"),'utf-8')\r
92         except:\r
93             ""\r
94         if tsmovepath!="":\r
95             sa=auto_move.searchFile(recpath, tsmovepath,".ts")\r
96             for t in sa:\r
97                 sf=guess.searchFolder(t,tsmovepath,700)\r
98                 if sf!="":\r
99                     recdblist.printutf8(t+u" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".ts")+".ts"))\r
100                     print "\n"\r
101             sa=auto_move.searchFile(recpath, tsmovepath,".ts")\r
102         else:\r
103             recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。",verbose_level=100)\r
104     elif opts.tsmove:##-Tの場合\r
105         tsmovepath=""\r
106         try:\r
107             tsmovepath=unicode(configreader.getConfPath("ts_movepath"),'utf-8')\r
108         except:\r
109             ""\r
110         if tsmovepath!="":\r
111             sa=auto_move.searchFile(recpath, tsmovepath,".ts")\r
112             for t in sa:\r
113                 sf=guess.searchFolder(t,tsmovepath,700)\r
114                 if sf!="":\r
115                     recdblist.printutf8(u"移動先",verbose_level=100)\r
116                     recdblist.printutf8(t+" : "+os.path.join(sf, auto_move.getMoveDestpath(t, recpath,sf,".ts")+".ts"),verbose_level=100)\r
117                     recdblist.printutf8(u"実行中",verbose_level=100)\r
118                     auto_move.execMove(t, recpath, tsmovepath,".ts",0)\r
119             sa=auto_move.searchFile(recpath, tsmovepath,".ts")\r
120         else:\r
121             recdblist.printutf8(u"ts_movepathが設定されていません。/etc/rec10.confを設定してください。",verbose_level=100)\r
122     elif opts.seriespath!="":##-Sの場合##与えられたパスにシリーズがそろっているかを調べる。\r
123         ss=guess.detSeriesNum(opts.seriespath)\r
124         for sstitle, ssv in ss.iteritems():\r
125             if len(ssv)>0:\r
126                 maxt=0\r
127                 bt=0\r
128                 alr=[]\r
129                 for ssi,ssiv in ssv.iteritems():\r
130                     alr.append(ssi)\r
131                     if maxt<ssi:\r
132                         maxt=ssi\r
133                 alr=list(set(alr))\r
134                 alr.sort()\r
135                 alr.reverse()\r
136                 nuke=""\r
137                 for i in xrange(1,maxt+1,1):\r
138                     if alr.count(i)==0:\r
139                         nuke=nuke+str(i)+","\r
140                 if len(nuke)==0:\r
141                     recdblist.printutf8(sstitle+" "+str(maxt))\r
142                 else:\r
143                     recdblist.printutf8(u"**"+sstitle+" |"+str(maxt)+"| "+nuke)\r