movie-renamer 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +21 -3
  2. data/bin/movie-renamer +1 -1
  3. data/lib/movie-renamer.rb +42 -10
  4. metadata +24 -4
data/README.rdoc CHANGED
@@ -31,15 +31,33 @@ in the folder specified with the -p option
31
31
 
32
32
  By default Movies are renamed like this:
33
33
 
34
- $year - $director - $title partXX.file_extension
34
+ $year - $director - $title partXX.file_extension
35
35
 
36
36
  You can set the rename pattern creating a .movie-renamer file in your home
37
37
 
38
- example:
39
- filename: ($year) - $title - $director
38
+ example:
39
+ filename: ($year) - $title - $director
40
40
 
41
+ === Multilanguage support
42
+ Optionally a language for the search can be set in .movie-renamer file
43
+ language: it
41
44
 
45
+ all languages supported by imdb are available, simply set the language option to the website .part
46
+ link www.imdb.it -> it
42
47
 
48
+ In this case search will return the complete title but then just the title in the selected language will be writed in the filename
49
+
50
+ Please NOTE that multilanguage support REQUIRES an UTF-8 enabled terminal to work correctly
51
+
52
+ == Notes on install
53
+ movie-renamer requires ruby1.9 to work correctly
54
+ gem dependencies also includes
55
+
56
+ imdb gem
57
+ htmlentities gem
58
+ highline gem
59
+
60
+ also ensure that you have the gem installation path in your $PATH to use the included executables
43
61
 
44
62
  == Note on Patches/Pull Requests
45
63
  You are encouraged to provide help in developing this simple but useful (I hope) application!
data/bin/movie-renamer CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  require File.join(File.dirname(__FILE__),'..','lib','movie-renamer')
4
4
  require 'optparse'
data/lib/movie-renamer.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'imdb'
4
4
  require 'highline'
5
5
  require 'highline/import'
6
+ require 'htmlentities'
6
7
  require 'yaml'
7
8
 
8
9
  $config = ''
@@ -18,7 +19,6 @@ exit
18
19
  =end
19
20
  end
20
21
 
21
-
22
22
  begin
23
23
  require 'imdb'
24
24
  rescue LoadError
@@ -26,6 +26,25 @@ rescue LoadError
26
26
  exit
27
27
  end
28
28
 
29
+
30
+ if $config['language']
31
+ $language = $config['language']
32
+ else
33
+ $language = 'com'
34
+ end
35
+ # MonkeyPatching is bad..
36
+ module Imdb
37
+
38
+ class Search
39
+ class << self
40
+ def query(query)
41
+ open("http://www.imdb.#{$language}/find?q=#{CGI::escape(query)};s=tt")
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+
29
48
  module MovieRenamer
30
49
 
31
50
  @newpath = 'tmp'
@@ -151,18 +170,24 @@ module MovieRenamer
151
170
  def MovieRenamer::editMovie(filename)
152
171
  movie = MovieRenamer::readMovie(filename)
153
172
  MovieRenamer::printMovieInfo(movie)
154
- ans = askMore "would you like to edit this movie? [ Yes, No, Quit, Info]"# , play] "
173
+ ans = askMore "would you like to edit this movie? [ Yes, Skip movie, Quit, Imdb lookup]"# , play] "
155
174
  if ans
156
175
  if ans == :info
157
- MovieRenamer::suggestMovies(movie)
176
+ ret = MovieRenamer::suggestMovies(movie)
177
+ if ret.class == nil
178
+ return true
179
+ end
158
180
  elsif ans == :play
159
181
  MovieRenamer::playMovie(movie)
160
182
  end
183
+
184
+
161
185
  #if ask "play movie with mplayer?"
162
186
  # MovieRenamer::playMovie(movie)
163
187
  #end
164
188
 
165
189
  # TODO insert imdb suggestions here?
190
+
166
191
 
167
192
  if movie.year == ''
168
193
  @output.puts "Enter a year"
@@ -227,11 +252,11 @@ module MovieRenamer
227
252
  case response
228
253
  when /^y(es)?$/i
229
254
  true
230
- when /^no?$/i
255
+ when /^s(kip)?$/i
231
256
  false
232
257
  when /^q(uit)?$/i
233
258
  exit 0
234
- when /^i(nfo)?$/i
259
+ when /^i(mdb)?$/i
235
260
  return :info
236
261
  when /^p(lay)?$/i
237
262
  return :play
@@ -276,27 +301,34 @@ module MovieRenamer
276
301
 
277
302
  def MovieRenamer::imdbLookup(name)
278
303
  s = Imdb::Search.new(name)
304
+ coder = HTMLEntities.new
279
305
  s.movies[0..4].each_with_index do |m,i|
306
+ m.title = coder.decode(m.title)#.encode("iso-8859-1")
280
307
  @output.puts "#{i}, #{m.year} - #{m.director.to_s.gsub(/(\[")|("\])/,'')} - #{m.title.gsub(/ .*/,'')}"
281
308
  end
282
309
  end
283
310
  # makes a query to imdb database
284
311
  def MovieRenamer::suggestMovies(movie)
312
+ coder = HTMLEntities.new
285
313
  s = Imdb::Search.new(movie.title)
286
314
  s.movies[0..4].each_with_index do |m,i|
315
+ m.title = coder.decode(m.title)#.encode("iso-8859-1")
287
316
  @output.puts "#{i}, #{m.year} - #{m.director.to_s.gsub(/(\[")|("\])/,'')} - #{m.title.gsub(/ .*/,'')}"
288
317
  end
289
- cmd = ask("pick a choice [0..4], Manual search, Edit Manually", %w{0 1 2 3 4 m e}) do |q|
290
- q.readline = true
291
- end
292
- if %w{0 1 2 3 4}.include?(cmd)
318
+ mt = s.movies[0..4]
319
+ cmd = ask("pick a choice [0..#{(mt.length) -1 }], Manual search, Edit manually, Skip Movie, Quit", ((0...mt.length).to_a.map{ |e| e.to_s} << %w{m e s q}).flatten)
320
+ if (0..mt.length).to_a.map{|e| e.to_s}.include?(cmd)
293
321
  m = s.movies[cmd.to_i]
294
- movie.title = m.title.gsub(/ .*/,'').gsub(/\s*\([0-9]+\)/,'').gsub(/\saka\s.*/,'') # aka removes other lang from title
322
+ movie.title = m.title.gsub(/ .*/,'').gsub(/\s*\([0-9]+\).*/,'')#.gsub(/\saka\s.*/,'') # aka removes other lang from title
295
323
  movie.year = m.year
296
324
  movie.director = m.director.to_s.gsub(/(\[")|("\])/,'')
297
325
  elsif cmd == "m"
298
326
  movie.title = ask("enter title")
299
327
  MovieRenamer::suggestMovies(movie )
328
+ elsif cmd == "q"
329
+ exit(0)
330
+ elsif cmd == "s"
331
+ return nil
300
332
  end
301
333
  return movie
302
334
  end
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.16
4
+ version: 0.0.17
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-09-04 00:00:00 +02:00
12
+ date: 2010-09-08 00:00:00 +02:00
13
13
  default_executable: movie-renamer
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -23,7 +23,17 @@ dependencies:
23
23
  version: "0"
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: highlight
26
+ name: highline
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: htmlentities
27
37
  type: :runtime
28
38
  version_requirement:
29
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +53,17 @@ dependencies:
43
53
  version: "0"
44
54
  version:
45
55
  - !ruby/object:Gem::Dependency
46
- name: highlight
56
+ name: highline
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: htmlentities
47
67
  type: :runtime
48
68
  version_requirement:
49
69
  version_requirements: !ruby/object:Gem::Requirement