lib/movie-renamer.rb in movie-renamer-0.0.6 vs lib/movie-renamer.rb in movie-renamer-0.0.7
- old
+ new
@@ -74,14 +74,20 @@
# reads move filename and tries to initialize a movie object?
# returns the movie object
def MovieRenamer::readMovie(filename)
# TODO insert logic here
filename = File.basename(filename)
- title = File.basename(filename,'.*')
+ title =MovieRenamer::titleExtract(File.basename(filename,'.*'))
return Movie.new(filename,:title => title)
end
+ # attempt to remove the divx part from a filename
+ def MovieRenamer::titleExtract(filename)
+ r = %r{\s*\[?\(?\s*(d|D)(i|I)(v|V)(x|X)\s?(-|_)?\s?\w+\s*\)?\]?\s*}
+ filename.gsub(r,'')
+ end
+
# rename a movie according to movie data
# and moves it to the new path in filesystem
def MovieRenamer::renameMovie(movie,newpath = NEWPATH)
filename = MovieRenamer::newName(movie)
path = File.join(@folderpath,newpath)
@@ -159,11 +165,11 @@
MovieRenamer::findMovies(folder).each do |file|
MovieRenamer::editMovie(file)
end
end
-
+ # yes or no questioner
def MovieRenamer::ask(question)
@output.puts question
response = @input.gets.chomp
case response
when /^y(es)?$/i
@@ -174,10 +180,11 @@
puts "I don't understand. Please retry"
ask(question)
end
end
+ # yes no quit info play questioner
def MovieRenamer::askMore(question)
@output.puts question
response = @input.gets.chomp
case response
when /^y(es)?$/i
@@ -217,14 +224,16 @@
end
s += File.extname(movie.filename)
return s
end
-
+
+ # LIMITS the set of chars that can be used in movie names
+ # just 'cause we love shell and we know how painful those chars can be :P
def MovieRenamer::sanitizeInput(input)
# XXX naive sanitize
# simply removing all non standard characters
- input.gsub(/[^A-Za-z0-9\_\-\s]/,'').chomp.sub(/ +$/,'')
+ input.gsub(/[^A-Za-z0-9\_\-\s']/,'').gsub(/\s+/,' ').chomp.sub(/ +$/,'')
end
# makes a query to imdb database
def MovieRenamer::suggestMovies(name)
s = Imdb::Search.new(name)