movie-renamer 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/lib/movie-renamer.rb +42 -15
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -55,6 +55,10 @@ Please NOTE that multilanguage support REQUIRES an UTF-8 enabled terminal to wor
|
|
55
55
|
Setting this variable you can change the default savepath to save in the same path all the renamed movies.
|
56
56
|
The behavior is the same as with -p option.
|
57
57
|
|
58
|
+
=== Add a pattern to parse movie filenames
|
59
|
+
If option "parsepattern" is set the pattern is used to parse movie filenames
|
60
|
+
trying to detect $director $artist and $year
|
61
|
+
parsepattern: $year - $director - $title
|
58
62
|
|
59
63
|
== Notes on install
|
60
64
|
movie-renamer requires ruby1.9 to work correctly
|
data/lib/movie-renamer.rb
CHANGED
@@ -44,11 +44,11 @@ module Imdb
|
|
44
44
|
end
|
45
45
|
|
46
46
|
class Movie
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
def director
|
48
|
+
document.at("h4[text()='Director:'] ~ a").innerHTML.strip.imdb_unescape_html rescue nil
|
49
|
+
document.search("h4[text()^='Director'] ~ a").map { |link| link.innerHTML.strip.imdb_unescape_html } rescue []
|
50
|
+
end
|
51
|
+
end
|
52
52
|
|
53
53
|
end
|
54
54
|
|
@@ -66,6 +66,10 @@ module MovieRenamer
|
|
66
66
|
if $config['filename']
|
67
67
|
@renamepattern = $config['filename']
|
68
68
|
end
|
69
|
+
|
70
|
+
if $config['parsepattern']
|
71
|
+
@parsepattern = $config['parsepattern']
|
72
|
+
end
|
69
73
|
|
70
74
|
if $config['savepath']
|
71
75
|
@newpath = File.expand_path($config['savepath'])
|
@@ -96,10 +100,10 @@ module MovieRenamer
|
|
96
100
|
end
|
97
101
|
|
98
102
|
end
|
99
|
-
|
103
|
+
|
100
104
|
# setters
|
101
105
|
def MovieRenamer::folderPath=(folderpath)
|
102
|
-
@folderpath = folderpath
|
106
|
+
@folderpath = folderpath
|
103
107
|
end
|
104
108
|
|
105
109
|
def MovieRenamer::newpath=(newpath)
|
@@ -136,14 +140,36 @@ module MovieRenamer
|
|
136
140
|
# returns the movie object
|
137
141
|
def MovieRenamer::readMovie(filename)
|
138
142
|
# TODO insert logic here
|
139
|
-
|
140
|
-
|
141
|
-
|
143
|
+
if @parsepattern
|
144
|
+
MovieRenamer::parseMovie(filename)
|
145
|
+
else
|
146
|
+
filename = File.basename(filename)
|
147
|
+
title =MovieRenamer::titleExtract(File.basename(filename,'.*'))
|
148
|
+
return Movie.new(filename,:title => title)
|
149
|
+
end
|
142
150
|
end
|
143
151
|
|
144
|
-
def MovieRenamer::parseMovie(filename)
|
145
|
-
|
146
|
-
|
152
|
+
def MovieRenamer::parseMovie(filename)
|
153
|
+
filename.gsub!(/(\..+$)/,'')
|
154
|
+
ext = $1
|
155
|
+
#@parsepattern = "$title - $director"
|
156
|
+
p = []
|
157
|
+
p << [:year= , @parsepattern =~ /\$year/] if @parsepattern =~ /\$year/
|
158
|
+
p << [:title=, @parsepattern =~ /\$title/] if @parsepattern =~ /\$title/
|
159
|
+
p << [:director=, @parsepattern =~ /\$director/] if @parsepattern =~ /\$director/
|
160
|
+
p.compact!
|
161
|
+
p.sort! { |a, b| a[1]<=> b[1] }
|
162
|
+
newpattern = @parsepattern.gsub(/\$[a-z]+/,'(.+)')
|
163
|
+
#puts %r{#{newpattern}}.inspect
|
164
|
+
m = Movie.new(filename+ ext) #TODO add extensioooonn that was lost
|
165
|
+
p.each_with_index do |e,i|
|
166
|
+
filename =~ %r{#{newpattern}}
|
167
|
+
m.send e[0], eval("$" +(i+1).to_s)
|
168
|
+
end
|
169
|
+
#m.title = $year
|
170
|
+
#m.director = $director
|
171
|
+
#m.year = $title
|
172
|
+
return m
|
147
173
|
end
|
148
174
|
# attempt to remove the divx part from a filename
|
149
175
|
def MovieRenamer::titleExtract(filename)
|
@@ -151,7 +177,7 @@ module MovieRenamer
|
|
151
177
|
r2 = %r{\s*\[?\(?\s*(x|X)(v|V)(i|I)(d|D)\s?(-|_)?\s?\w+\s*\)?\]?\s*}
|
152
178
|
r3 = %r{\s*\[?\(?\s*(d|D)(v|V)(d|D)(r|R)(i|I)(p|P)\s?(-|_)?\s*\)?\]?\s*}
|
153
179
|
r = /(#{r1}|#{r2}|#{r3})/
|
154
|
-
filename.gsub!(/-.*/,'')
|
180
|
+
filename.gsub!(/-.*/,'') # XXX takes only first part
|
155
181
|
filename.gsub(r,'').gsub(/\s?(-|_)\s?/,' ').gsub(/^\s/,'')
|
156
182
|
end
|
157
183
|
|
@@ -328,7 +354,8 @@ module MovieRenamer
|
|
328
354
|
# makes a query to imdb database
|
329
355
|
def MovieRenamer::suggestMovies(movie)
|
330
356
|
coder = HTMLEntities.new
|
331
|
-
|
357
|
+
name = (movie.title + " ").gsub(/\W/,' ').gsub(/(^\w{,3})|( \w{,3} )/,'').gsub(/\s+/,' ').chomp
|
358
|
+
s = Imdb::Search.new(name)
|
332
359
|
s.movies[0..4].each_with_index do |m,i|
|
333
360
|
m.title = coder.decode(m.title)#.encode("iso-8859-1")
|
334
361
|
out = "#{i}, #{m.year} - #{m.director.to_s.gsub(/(\[")|("\])/,'')} - #{m.title.gsub(/ .*/,'')}"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: movie-renamer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 53
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 21
|
10
|
+
version: 0.0.21
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- ghedamat
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-15 00:00:00 +02:00
|
19
19
|
default_executable: movie-renamer
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|