public
Description: Simple to use TVDB (thetvdb.com) API in Python, and automatic TV episode namer
Homepage: http://dbr.lighthouseapp.com/projects/13342-tvdb_api/tickets
Clone URL: git://github.com/dbr/tvdb_api.git
Search Repo:
Improved --help output, vaious fixes to --always and --interactive 
handling
dbr (author)
Fri May 09 18:35:25 -0700 2008
commit  9581e2c85e19bbe141882413d4b050affab498c4
tree    7ec3e1cf31ae92113e08827e2496d8f4c2e9b49b
parent  db9c02a00722dc1aa70880ef0c2a3803b22ea283
...
126
127
128
129
 
130
131
132
133
134
 
 
 
 
 
 
 
 
 
 
135
136
137
138
139
140
141
142
143
144
...
145
146
147
148
 
 
 
 
149
150
151
152
 
 
 
 
153
 
 
154
 
 
155
156
157
158
159
 
160
161
 
 
162
163
164
165
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
168
169
170
 
 
171
172
173
...
126
127
128
 
129
130
 
 
 
 
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
...
151
152
153
 
154
155
156
157
158
 
 
 
159
160
161
162
163
164
165
166
167
168
169
170
171
172
 
173
174
 
175
176
177
178
 
 
 
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
 
196
197
198
199
200
0
@@ -126,12 +126,18 @@
0
     
0
 
0
 def main():
0
- parser = OptionParser()
0
+ parser = OptionParser(usage="%prog [options] <file or directories>")
0
 
0
- parser.add_option("-d","--debug",action="store_true",default=False,dest="debug", help="Show debugging info")
0
- parser.add_option("-b","--batch",action="store_false",dest="interactive",help="Selects first search result, requires no human intervention once launched",default=False)
0
- parser.add_option("-i","--interactive",action="store_true",dest="interactive",help="Interactivly prompt for show",default=True)
0
- parser.add_option("-f","--force",action="store_true",default=False,dest="force",help="Skips checking if new filename already exists before renaming")
0
+ parser.add_option( "-d","--debug",action="store_true",default=False,dest="debug",
0
+ help="show debugging info")
0
+ parser.add_option( "-b","--batch",action="store_false",dest="interactive",
0
+ help="selects first search result, requires no human intervention once launched",default=False)
0
+ parser.add_option( "-i","--interactive",action="store_true",dest="interactive",default=True,
0
+ help="interactivly select correct show from search results [default]")
0
+ parser.add_option( "-a","--always",action="store_true",default=False,dest="always",
0
+ help="always renames files (but still lets user select correct show). Can be changed during runtime with the 'a' prompt-option")
0
+ parser.add_option( "-f","--force",action="store_true",default=False,dest="force",
0
+ help="forces file to be renamed, even if it will overwrite an existing file")
0
     
0
     opts,args = parser.parse_args()
0
     if len(args) == 0:
0
0
0
0
0
0
0
0
@@ -145,29 +151,50 @@
0
         sys.stderr.write("No valid files found\n")
0
         sys.exit(1)
0
     
0
- print "Starting tvdb"
0
+ print "#"*20
0
+ print "# Starting tvnamer"
0
+ print "# Processing %d files" % ( len(validFiles) )
0
+
0
     t = tvdb(debug = opts.debug, interactive = opts.interactive)
0
- print "Done"
0
- print "Starting processing files"
0
- always=False
0
+
0
+ print "# ..got tvdb mirrors"
0
+ print "# Starting to process files"
0
+
0
     for cfile in validFiles:
0
+
0
+ # Ask for episode name from tvdb_api
0
         epname = t[ cfile['showname'] ][ cfile['seasno'] ][ cfile['epno'] ]['name']
0
+
0
+ # Either use the found episode name, warn if not found
0
         if epname:
0
             cfile['epname'] = epname
0
         else:
0
             cfile['epname'] = None
0
- sys.stderr.write("Episode name not found for %s" % ( cfile['fullpath']) )
0
+ sys.stderr.write("! Episode name not found for %s\n" % ( cfile ) )
0
         #end if epname
0
-
0
+
0
+ # Format new filename, strip unwanted characters
0
         newname = formatName( cfile )
0
         newname = cleanName(newname)
0
- oldfile = os.path.join( cfile['filepath'],cfile['filename'] + cfile['ext'] )
0
- newfile = os.path.join( cfile['filepath'],newname )
0
- print "*"*20
0
+
0
+ # Append new filename (with extension) to path
0
+ oldfile = os.path.join(
0
+ cfile['filepath'],
0
+ cfile['filename'] + cfile['ext']
0
+ )
0
+ # Join path to new file name
0
+ newfile = os.path.join(
0
+ cfile['filepath'],
0
+ newname
0
+ )
0
+
0
+ # Show new/old filename
0
+ print "#"*20
0
         print "Old name: %s" % ( cfile['filename'] + cfile['ext'] )
0
         print "New name: %s" % ( newname )
0
         
0
- if always:
0
+ # Either always rename, or prompt user
0
+ if opts.always or not opts.interactive:
0
             rename_result = renameFile(oldfile,newname,force=opts.force)
0
             if rename_result:
0
                 print "..auto-renaming"

Comments

    No one has commented yet.