movie-renamer 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +11 -1
- data/lib/movie-renamer.rb +13 -4
- data/test/test_movie-renamer.rb +12 -3
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
A simple command line interface to rename movies in a folder
|
4
4
|
|
5
|
+
|
6
|
+
Uses imdb gem to query imdb about current movie trying to obtain useful infos
|
7
|
+
|
8
|
+
play function is going to be added...
|
9
|
+
|
10
|
+
to see the usage type
|
11
|
+
|
12
|
+
$movie-renamer -h
|
13
|
+
|
14
|
+
|
5
15
|
wait for a deeper description
|
6
16
|
|
7
17
|
== Note on Patches/Pull Requests
|
@@ -20,7 +30,7 @@ Copyright (c) 2010 ghedamat. See LICENSE for details.
|
|
20
30
|
|
21
31
|
Feel free to send me suggestions :)
|
22
32
|
|
23
|
-
|
33
|
+
Please drop me a line if you find this useful
|
24
34
|
|
25
35
|
Mail me at: thamayor [at] gmail [dot] com
|
26
36
|
|
data/lib/movie-renamer.rb
CHANGED
@@ -76,10 +76,16 @@ module MovieRenamer
|
|
76
76
|
def MovieRenamer::readMovie(filename)
|
77
77
|
# TODO insert logic here
|
78
78
|
filename = File.basename(filename)
|
79
|
-
title =
|
79
|
+
title =MovieRenamer::titleExtract(File.basename(filename,'.*'))
|
80
80
|
return Movie.new(filename,:title => title)
|
81
81
|
end
|
82
82
|
|
83
|
+
# attempt to remove the divx part from a filename
|
84
|
+
def MovieRenamer::titleExtract(filename)
|
85
|
+
r = %r{\s*\[?\(?\s*(d|D)(i|I)(v|V)(x|X)\s?(-|_)?\s?\w+\s*\)?\]?\s*}
|
86
|
+
filename.gsub(r,'')
|
87
|
+
end
|
88
|
+
|
83
89
|
# rename a movie according to movie data
|
84
90
|
# and moves it to the new path in filesystem
|
85
91
|
def MovieRenamer::renameMovie(movie,newpath = NEWPATH)
|
@@ -161,7 +167,7 @@ module MovieRenamer
|
|
161
167
|
end
|
162
168
|
end
|
163
169
|
|
164
|
-
|
170
|
+
# yes or no questioner
|
165
171
|
def MovieRenamer::ask(question)
|
166
172
|
@output.puts question
|
167
173
|
response = @input.gets.chomp
|
@@ -176,6 +182,7 @@ module MovieRenamer
|
|
176
182
|
end
|
177
183
|
end
|
178
184
|
|
185
|
+
# yes no quit info play questioner
|
179
186
|
def MovieRenamer::askMore(question)
|
180
187
|
@output.puts question
|
181
188
|
response = @input.gets.chomp
|
@@ -219,11 +226,13 @@ module MovieRenamer
|
|
219
226
|
return s
|
220
227
|
end
|
221
228
|
|
222
|
-
|
229
|
+
|
230
|
+
# LIMITS the set of chars that can be used in movie names
|
231
|
+
# just 'cause we love shell and we know how painful those chars can be :P
|
223
232
|
def MovieRenamer::sanitizeInput(input)
|
224
233
|
# XXX naive sanitize
|
225
234
|
# simply removing all non standard characters
|
226
|
-
input.gsub(/[^A-Za-z0-9\_\-\s]/,'').chomp.sub(/ +$/,'')
|
235
|
+
input.gsub(/[^A-Za-z0-9\_\-\s']/,'').gsub(/\s+/,' ').chomp.sub(/ +$/,'')
|
227
236
|
end
|
228
237
|
|
229
238
|
# makes a query to imdb database
|
data/test/test_movie-renamer.rb
CHANGED
@@ -25,7 +25,16 @@ class TestMovieRenamer < Test::Unit::TestCase
|
|
25
25
|
must "create a movie object" do
|
26
26
|
assert_equal MovieRenamer::Movie.new('movie1.avi',title: 'movie1'),MovieRenamer::readMovie(@movies.first)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
|
+
# test title extraction
|
30
|
+
must "extract a title correctly with bad words in filename" do
|
31
|
+
['DIvX-ITa Kill Bill Vol. 2','(Divx-Ita )Kill Bill Vol. 2',
|
32
|
+
'Divx- ita Kill Bill Vol. 2',
|
33
|
+
'[Divx-Ita ]Kill Bill Vol. 2','Kill Bill Vol. 2 [divx - Ita ]'].each do |name|
|
34
|
+
assert_equal "Kill Bill Vol. 2", MovieRenamer::titleExtract(name)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
29
38
|
# simple checks that rename is done
|
30
39
|
must "rename a file (and moves it) correctly" do
|
31
40
|
assert ! MovieRenamer::renameMovie(MovieRenamer::readMovie(@movies.first)), "file not renamed?"
|
@@ -70,8 +79,8 @@ class TestMovieRenamer < Test::Unit::TestCase
|
|
70
79
|
|
71
80
|
# test input sanitize
|
72
81
|
must "sanitize input correctly" do
|
73
|
-
input = "very bad movie{}\@# son "
|
74
|
-
assert_equal "very bad movie son", MovieRenamer::sanitizeInput(input)
|
82
|
+
input = "ain't a very bad movie{}\@# son "
|
83
|
+
assert_equal "ain't a very bad movie son", MovieRenamer::sanitizeInput(input)
|
75
84
|
end
|
76
85
|
|
77
86
|
# test edit movie
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: movie-renamer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ghedamat
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-06-
|
12
|
+
date: 2010-06-21 00:00:00 +02:00
|
13
13
|
default_executable: movie-renamer
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|