myimdb 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -14,9 +14,8 @@ begin
14
14
  gem.rubyforge_project = 'myimdb'
15
15
  gem.files = FileList["**/*"]
16
16
  end
17
- Jeweler::RubyforgeTasks.new do |rubyforge|
18
- rubyforge.doc_task = "rdoc"
19
- end
17
+
18
+ Jeweler::GemcutterTasks.new
20
19
  rescue LoadError
21
20
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
21
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/bin/myimdb CHANGED
@@ -1,34 +1,20 @@
1
- #!/usr/bin/env ruby
2
-
3
- # point this file to a folder and all the folder inside it will be renamed
4
- require 'myimdb.rb'
5
-
6
- unless ARGV[0]
7
- p "Source directory required - exiting"
8
- exit(0)
9
- end
10
-
11
- file_paths = Dir["#{ARGV[0]}/*"]
12
- search_scope = "imdb.com"
13
-
14
- file_paths.each do |path|
15
- next if !File.directory?(path)
16
- p "============================================"
17
- name = File.basename(path)
18
- if name.scan(/\[.*?\]/).size == 3
19
- p "Skipping: #{name}"
20
- else
21
- p "Fetching details for: #{name}"
22
- begin
23
- search_result = Myimdb::Search::Google.search_text(name, search_scope)[0]
24
- imdb = Myimdb::Scraper::Imdb.new(search_result["url"])
25
- new_name = name.gsub(/\[\S+\]/, "").strip
26
- new_name << " [#{imdb.year}] [#{imdb.rating},#{imdb.votes}] [#{imdb.directors.join(',')}]"
27
- p "Renaming: #{name} to: #{new_name}"
28
- new_path = File.join(File.dirname(path), new_name)
29
- File.rename(path, new_path)
30
- rescue
31
- p "Unable to fetch details for: #{name}"
32
- end
33
- end
34
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'myimdb.rb'
4
+
5
+ name = ARGV.join(' ')
6
+
7
+ if name.blank?
8
+ p "Movie name required - exiting"
9
+ exit(0)
10
+ end
11
+
12
+ search_scope = "imdb.com"
13
+
14
+ begin
15
+ search_result = Myimdb::Search::Google.search_text(name, search_scope)[0]
16
+ imdb = Myimdb::Scraper::Imdb.new(search_result["url"])
17
+ p imdb
18
+ rescue
19
+ p "Unable to fetch details for: #{name}"
20
+ end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # point this file to a folder and all the folder inside it will be renamed
4
+ require 'myimdb.rb'
5
+
6
+ unless ARGV[0]
7
+ p "Source directory required - exiting"
8
+ exit(0)
9
+ end
10
+
11
+ file_paths = Dir["#{ARGV[0]}/*"]
12
+ search_scope = "imdb.com"
13
+
14
+ file_paths.each do |path|
15
+ next if !File.directory?(path)
16
+ p "============================================"
17
+ name = File.basename(path)
18
+ if name.scan(/\[.*?\]/).size == 3
19
+ p "Skipping: #{name}"
20
+ else
21
+ p "Fetching details for: #{name}"
22
+ begin
23
+ search_result = Myimdb::Search::Google.search_text(name, search_scope)[0]
24
+ imdb = Myimdb::Scraper::Imdb.new(search_result["url"])
25
+ new_name = name.gsub(/\[\S+\]/, "").strip
26
+ new_name << " [#{imdb.year}] [#{imdb.rating},#{imdb.votes}] [#{imdb.directors.join(',')}]"
27
+ p "Renaming: #{name} to: #{new_name}"
28
+ new_path = File.join(File.dirname(path), new_name)
29
+ File.rename(path, new_path)
30
+ rescue
31
+ p "Unable to fetch details for: #{name}"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1 @@
1
+ @"ruby.exe" "%~dpn0" %*
data/bin/myimdb.bat CHANGED
@@ -1 +0,0 @@
1
- @"ruby.exe" "%~dpn0" %*
@@ -29,17 +29,41 @@ module Myimdb
29
29
  module Scraper
30
30
  class Base
31
31
  include HandleExceptions
32
- def year
32
+ def directors
33
33
  end
34
-
34
+
35
+ def writers
36
+ end
37
+
38
+ def rating
39
+ end
40
+
41
+ def votes
42
+ end
43
+
44
+ def genres
45
+ end
46
+
35
47
  def tagline
36
48
  end
37
-
38
- def directors
49
+
50
+ def plot
39
51
  end
40
-
41
- def writers
52
+
53
+ def year
54
+ end
55
+
56
+ def release_date
42
57
  end
58
+
59
+ def summary
60
+ [:directors, :writers, :rating, :votes, :genres, :tagline, :plot, :year, :release_date].collect do |meth|
61
+ data = send(meth)
62
+ data = data.join(", ") if Array === data
63
+ sprintf("%-15s : %s", meth.to_s.titleize, data)
64
+ end.join("\n")
65
+ end
66
+
43
67
  end
44
68
  end
45
69
  end
@@ -14,11 +14,11 @@ module Myimdb
14
14
  end
15
15
 
16
16
  def rating
17
- document.css(".general.rating b").inner_text.strip.split('/').first.to_f
17
+ document.css(".starbar-meta b").inner_text.strip.split('/').first.to_f
18
18
  end
19
19
 
20
20
  def votes
21
- document.css(".general.rating a").inner_text.strip.sub(',', '').to_i
21
+ document.css(".starbar-meta a").inner_text.strip.split(' ').first.sub(',', '').to_i
22
22
  end
23
23
 
24
24
  def genres
@@ -26,7 +26,7 @@ module Myimdb
26
26
  end
27
27
 
28
28
  def tagline
29
- document.css('.info h5:contains("Tagline:") + .info-content').children[0].text.strip
29
+ document.css('.info h5:contains("Tagline:") + .info-content').children[0].text.strip rescue nil
30
30
  end
31
31
 
32
32
  def plot
@@ -36,7 +36,11 @@ module Myimdb
36
36
  def year
37
37
  document.css("div#tn15title a:first")[0].text.to_i
38
38
  end
39
-
39
+
40
+ def release_date
41
+ Date.parse(document.css('.info h5:contains("Release Date:") + .info-content').inner_text)
42
+ end
43
+
40
44
  private
41
45
  def document
42
46
  @document ||= Nokogiri::HTML(open(@url))
@@ -15,6 +15,14 @@ module Myimdb
15
15
  def strip_useless_chars
16
16
  gsub(/[^a-zA-z0-9\|\-_\(\)@$\/\\]/, '')
17
17
  end
18
+
19
+ def titleize
20
+ humanize.gsub(/\b('?[a-z])/) { $1.capitalize }
21
+ end
22
+
23
+ def humanize
24
+ gsub(/_/, " ").capitalize
25
+ end
18
26
  end
19
27
  end
20
28
  end
@@ -6,12 +6,25 @@ module Myimdb
6
6
  format :json
7
7
  headers 'Content-Type' => 'application/json'
8
8
  base_uri 'ajax.googleapis.com'
9
-
10
- def self.search_text( text, restrict_to=nil )
11
- text = "site:#{restrict_to} #{text}" if restrict_to
9
+
10
+ def self.search_text( text, options={} )
11
+ text = text + " site:#{options[:restrict_to]}" if !options[:restrict_to].blank?
12
12
  response = get( '/ajax/services/search/web', :query=> {:v=> '1.0', :q=> text} )
13
13
  response['responseData'] and response['responseData']['results']
14
14
  end
15
+
16
+ def self.search_images( text, options={} )
17
+ sizes = {
18
+ 'large' => 'l',
19
+ 'medium' => 'm',
20
+ 'small' => 'i'
21
+ }
22
+ search_options = { :v=> '1.0', :q=> text }
23
+ search_options.merge!(:imgsz=> sizes[options[:size].to_s]) if !options[:size].blank?
24
+ text = text + " site:#{options[:restrict_to]}" if !options[:restrict_to].blank?
25
+ response = get( '/ajax/services/search/images', :query=> search_options )
26
+ response['responseData'] and response['responseData']['results']
27
+ end
15
28
  end
16
29
  end
17
30
  end
data/myimdb.gemspec CHANGED
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{myimdb}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
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{2009-12-28}
12
+ s.date = %q{2010-01-19}
13
13
  s.email = %q{gaurav@vinsol.com}
14
- s.executables = ["myimdb", "myimdb.bat"]
14
+ s.executables = ["myimdb", "myimdb-catalogue", "myimdb-catalogue.bat", "myimdb.bat"]
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
@@ -22,6 +22,8 @@ Gem::Specification.new do |s|
22
22
  "Rakefile",
23
23
  "VERSION",
24
24
  "bin/myimdb",
25
+ "bin/myimdb-catalogue",
26
+ "bin/myimdb-catalogue.bat",
25
27
  "bin/myimdb.bat",
26
28
  "lib/myimdb.rb",
27
29
  "lib/myimdb/scraper.rb",
@@ -33,10 +35,6 @@ Gem::Specification.new do |s|
33
35
  "lib/myimdb/search.rb",
34
36
  "lib/myimdb/search/google.rb",
35
37
  "myimdb.gemspec",
36
- "pkg/myimdb-0.0.0.gem",
37
- "pkg/myimdb-0.1.0.gem",
38
- "pkg/myimdb-0.2.0.gem",
39
- "pkg/myimdb-0.3.0.gem",
40
38
  "test/helper.rb",
41
39
  "test/test_myimdb.rb"
42
40
  ]
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.0
4
+ version: 0.3.1
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: 2009-12-28 00:00:00 +05:30
12
+ date: 2010-01-19 00:00:00 +05:30
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -36,6 +36,8 @@ description:
36
36
  email: gaurav@vinsol.com
37
37
  executables:
38
38
  - myimdb
39
+ - myimdb-catalogue
40
+ - myimdb-catalogue.bat
39
41
  - myimdb.bat
40
42
  extensions: []
41
43
 
@@ -48,6 +50,8 @@ files:
48
50
  - Rakefile
49
51
  - VERSION
50
52
  - bin/myimdb
53
+ - bin/myimdb-catalogue
54
+ - bin/myimdb-catalogue.bat
51
55
  - bin/myimdb.bat
52
56
  - lib/myimdb.rb
53
57
  - lib/myimdb/scraper.rb
@@ -59,10 +63,6 @@ files:
59
63
  - lib/myimdb/search.rb
60
64
  - lib/myimdb/search/google.rb
61
65
  - myimdb.gemspec
62
- - pkg/myimdb-0.0.0.gem
63
- - pkg/myimdb-0.1.0.gem
64
- - pkg/myimdb-0.2.0.gem
65
- - pkg/myimdb-0.3.0.gem
66
66
  - test/helper.rb
67
67
  - test/test_myimdb.rb
68
68
  has_rdoc: true
data/pkg/myimdb-0.0.0.gem DELETED
Binary file
data/pkg/myimdb-0.1.0.gem DELETED
Binary file
data/pkg/myimdb-0.2.0.gem DELETED
Binary file
data/pkg/myimdb-0.3.0.gem DELETED
Binary file