myimdb 0.3.11 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,54 @@
2
2
 
3
3
  Utility gem for fetching movie details.
4
4
 
5
+ == Usage
6
+
7
+ === Command line
8
+
9
+ ==== Command line info for a movie
10
+
11
+ ~> myimdb the dark knight
12
+ ====================================================
13
+ Imdb details for: the dark knight
14
+ ====================================================
15
+ Directors : Christopher Nolan
16
+ Writers : Jonathan Nolan, Christopher Nolan
17
+ Rating : 8.9
18
+ Votes : 420667
19
+ Genres : Action, Crime, Drama, Thriller
20
+ Tagline : Why So Serious?
21
+ Plot : Batman, Gordon and Harvey Dent are forced to deal with the chaos unleashed by an anarchist mastermind known only as the Joker, as it drives each of them to their limits.
22
+ Year : 2008
23
+ Release Date : 2008-07-18
24
+
25
+
26
+ ==== Catalogue a movie directory
27
+
28
+ ~/m> ls
29
+ the dark knight
30
+ ~/m> myimdb-catalogue the\ dark\ knight/
31
+ "Fetching metadata for: the dark knight"
32
+ "Renaming: the dark knight to: the dark knight [2008] [8.9,420667] [Christopher Nolan]"
33
+ ~/m> ls
34
+ the dark knight [2008] [8.9,420667] [Christopher Nolan]
35
+
36
+
37
+ ==== As a library
38
+
39
+ >> require 'myimdb'
40
+ => true
41
+ >> search_result = Myimdb::Search::Google.search_text('the dark knight', :restrict_to=> 'imdb.com')[0]
42
+ => {"GsearchResultClass"=>"GwebSearch", "title"=>"<b>The Dark Knight</b> (2008)", "url"=>"http://www.imdb.com/title/tt0468569/", "cacheUrl"=>"http://www.google.com/search?q=cache:6zAp1ivBuzEJ:www.imdb.com", "content"=>"Directed by Christopher Nolan. With Christian Bale, Heath Ledger, Aaron Eckhart. Batman, Gordon and Harvey Dent are forced to deal with the chaos unleashed <b>...</b>", "visibleUrl"=>"www.imdb.com", "unescapedUrl"=>"http://www.imdb.com/title/tt0468569/", "titleNoFormatting"=>"The Dark Knight (2008)"}
43
+ >> site = Myimdb::Scraper::Imdb.new(search_result['url'])
44
+ => #<Myimdb::Scraper::Imdb:0x1023a2e80 @url="http://www.imdb.com/title/tt0468569/">
45
+ >> site.rating
46
+ => 8.9
47
+ >> site.votes
48
+ => 420667
49
+ >> site.release_date.to_s
50
+ => "2008-07-18"
51
+
52
+
5
53
  == Note on Patches/Pull Requests
6
54
 
7
55
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.11
1
+ 0.3.12
data/bin/myimdb CHANGED
@@ -53,7 +53,7 @@ def details(klass_name, name)
53
53
  print "#{klass_name} details for: #{name}\n"
54
54
  print "====================================================\n"
55
55
  print "#{site.summary}\n"
56
- rescue
56
+ rescue Exception=> ex
57
57
  p "Unable to fetch #{klass_name} details for: #{name}"
58
58
  end
59
59
 
@@ -22,6 +22,11 @@ end
22
22
 
23
23
  options = {}
24
24
 
25
+ def puts(data)
26
+ print("#{data}\n")
27
+ STDOUT.flush
28
+ end
29
+
25
30
  OptionParser.new do |opts|
26
31
  opts.banner = "Usage: #{File.basename($0)} [movie name]"
27
32
 
@@ -63,18 +68,19 @@ OptionParser.new do |opts|
63
68
  puts opts
64
69
  exit 1
65
70
  end
71
+
72
+ # need a movie name
73
+ if ARGV.empty?
74
+ puts opts
75
+ exit(0)
76
+ end
66
77
  end
67
78
 
68
79
  # add imdb as default
69
80
  options.merge!(:metadata=> true) if options.empty?
70
81
 
71
- # need a movie name
72
- if ARGV.empty?
73
- abort "Source directory required - exiting"
74
- end
75
-
76
- file_paths = options[:recursive] ? Dir["#{ARGV[0]}/*"] : [ARGV[0]]
77
-
82
+ source_dir = Platform.windows? ? ARGV[0].gsub(/\\+/, "/") : ARGV[0]
83
+ file_paths = options[:recursive] ? Dir["#{source_dir}/*"] : [source_dir]
78
84
 
79
85
  # helper methods
80
86
  def conf_file_name
@@ -145,7 +151,7 @@ def generate_metadata(path, name)
145
151
  imdb = Myimdb::Scraper::Imdb.new(search_result["url"])
146
152
  new_name = name.gsub(/\[\S+\]/, "").strip
147
153
  new_name << " [#{imdb.year}] [#{imdb.rating},#{imdb.votes}] [#{imdb.directors.join(',')}]"
148
- p "Renaming: #{name} to: #{new_name}"
154
+ puts "Renaming: #{name} to: #{new_name}"
149
155
  new_path = File.join(File.dirname(path), new_name)
150
156
  File.rename(path, new_path)
151
157
  new_path
@@ -165,20 +171,30 @@ file_paths.each do |path|
165
171
  metadata_present = (name.scan(/\[.*?\]/).size == 3)
166
172
  # metadata exists and -f isn't supplied
167
173
  if metadata_present and !options[:force] and options[:metadata]
168
- p "Skipping: Metadata already exists for: #{name}"
174
+ puts "Skipping: Metadata already exists for: #{name}"
169
175
  elsif options[:metadata]
170
- p "Fetching metadata for: #{name}"
176
+ puts "Fetching metadata for: #{name}"
171
177
  path = generate_metadata(path, filtered_movie_name(name))
172
178
  metadata_present = true
173
179
  end
174
180
 
181
+ if options[:'apply-icon']
182
+ source_file = Dir.entries(path).find{ |file| file =~ /\.jpg|\.png/ }
183
+ if source_file
184
+ puts "Applying icon for: #{name}"
185
+ convert_to_icon(File.join(path, source_file), File.join(path, icon_file_name))
186
+ else
187
+ puts "Source image file not found for: #{name}"
188
+ end
189
+ end
190
+
175
191
  # movie icon exists and -f isn't supplied
176
192
  if !metadata_present and options[:images]
177
- p "Skipping: Metadata not present: #{name}"
193
+ puts "Skipping: Metadata not present: #{name}"
178
194
  elsif File.exists?(File.join(path, 'movie.ico')) and !options[:force] and options[:images]
179
- p "Skipping: Image already exists for: #{name}"
195
+ puts "Skipping: Image already exists for: #{name}"
180
196
  elsif options[:images]
181
- p "Fetching image for: #{name}"
197
+ puts "Fetching image for: #{name}"
182
198
  begin
183
199
  save_image(path, "#{filtered_movie_name(name)} #{filtered_movie_year(name)}", retry_count)
184
200
  rescue
@@ -187,21 +203,11 @@ file_paths.each do |path|
187
203
  end
188
204
  end
189
205
 
190
- if options[:'apply-icon']
191
- source_file = Dir.entries(path).find{ |file| file =~ /\.jpg|\.png/ }
192
- if source_file
193
- p "Applying icon for: #{name}"
194
- convert_to_icon(File.join(path, source_file), File.join(path, icon_file_name))
195
- else
196
- p "Source image file not found for: #{name}"
197
- end
198
- end
199
-
200
206
  if options[:'rebuild-permissions'] or options[:'apply-icon'] or (options[:images] and metadata_present)
201
- p "Repairing permissions for: #{name}"
207
+ puts "Repairing permissions for: #{name}"
202
208
  repair_permissions_for(path)
203
209
  end
204
- rescue
205
- p "Unable to fetch details for: #{name}"
210
+ rescue Exception=> ex
211
+ puts "Unable to fetch details for: #{name}"
206
212
  end
207
213
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{myimdb}
8
- s.version = "0.3.11"
8
+ s.version = "0.3.12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gaurav"]
12
- s.date = %q{2010-01-29}
12
+ s.date = %q{2010-02-01}
13
13
  s.email = %q{gaurav@vinsol.com}
14
14
  s.executables = ["myimdb", "myimdb-catalogue"]
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myimdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gaurav
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-29 00:00:00 +05:30
12
+ date: 2010-02-01 00:00:00 +05:30
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency